LaboratoryProtection/Assets/UnityTest/ZXL/Scripts/UI/Help/AutoPlayAudio.cs

93 lines
2.1 KiB
C#

using System;
using System.Collections;
using Script;
using Sirenix.OdinInspector;
using UnityEngine;
namespace UnityTest.ZXL.Help
{
public class AutoPlayAudio : MonoBehaviour
{
[SerializeField] private AudioType _audioType = AudioType.Main;
[SerializeField] private AudioClipType _audioClipType;
private string str = "6_4/";
private bool isFinish;
private void OnEnable()
{
isFinish = false;
StartCoroutine(StartPlayAudio());
}
private void OnDisable()
{
if (isFinish)
{
return;
}
StopCoroutine(StartPlayAudio());
}
IEnumerator StartPlayAudio()
{
var s = _audioClipType.ToString();
var substring = s.Substring(1, s.Length - 1);
var replace = substring.Replace("_", "-");
var path = str + replace;
float time = 0;
switch (_audioType)
{
case AudioType.Bgm:
time = AudioManager.Instance.PlayBgmSound(true, path);
break;
case AudioType.Main:
time = AudioManager.Instance.PlayMainSounds(path);
break;
case AudioType.Other:
time = AudioManager.Instance.PlayOtherSound(true, path);
break;
default:
throw new ArgumentOutOfRangeException();
}
yield return new WaitForSeconds(time);
isFinish = true;
}
}
public enum AudioType
{
Bgm,
Main,
Other,
}
public enum AudioClipType
{
_1_2_1,
_1_2_2,
_1_3_1,
_1_3_2,
_1_3_3,
_2_1_1,
_2_1_2,
_2_1_3,
_2_1_4,
_2_2_1,
_2_2_2,
_2_2_3,
_2_2_4,
_2_3_1,
_2_3_2,
_2_3_3,
_2_3_4,
_2_4_1,
_2_4_2,
_2_4_3,
_2_4_4,
_3_3,
_119,
}
}