2024-12-01 15:24:10 +08:00
|
|
|
using System;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using UnityEngine;
|
|
|
|
using UnityEngine.Video;
|
|
|
|
|
|
|
|
[RequireComponent(typeof(VideoPlayer))]
|
|
|
|
public class AudioPlayControl : MonoBehaviour
|
|
|
|
{
|
|
|
|
public VideoClip startAudio;
|
|
|
|
public VideoClip endAudio;
|
|
|
|
|
|
|
|
private VideoPlayer player;
|
|
|
|
private void Awake()
|
|
|
|
{
|
|
|
|
player = GetComponent<VideoPlayer>();
|
|
|
|
player.playOnAwake = false;
|
|
|
|
}
|
|
|
|
public async Task PlayStartVideo()
|
|
|
|
{
|
|
|
|
this.gameObject.SetActive(true);
|
|
|
|
player.clip = startAudio;
|
|
|
|
player.Play();
|
|
|
|
await Task.Delay((int)(1000 * player.clip.length));
|
2024-12-01 15:48:43 +08:00
|
|
|
if (this == null || this.gameObject == null)
|
|
|
|
return;
|
2024-12-01 15:24:10 +08:00
|
|
|
player.Stop();
|
|
|
|
this.gameObject.SetActive(false);
|
|
|
|
}
|
|
|
|
public async void PlayEndVideo()
|
|
|
|
{
|
|
|
|
player.clip = endAudio;
|
|
|
|
player.Play();
|
|
|
|
await Task.Delay((int)(1000 * player.clip.length));
|
|
|
|
player.Stop();
|
|
|
|
this.gameObject.SetActive(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void StopPlay()
|
|
|
|
{
|
|
|
|
player.Stop();
|
|
|
|
this.gameObject.SetActive(false);
|
|
|
|
}
|
|
|
|
}
|