备份CatanBuilding瘦身独立工程
This commit is contained in:
90
Assets/Scripts/Sound/OutPlaySound.cs
Normal file
90
Assets/Scripts/Sound/OutPlaySound.cs
Normal file
@@ -0,0 +1,90 @@
|
||||
using asap.core;
|
||||
using Game;
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AddressableAssets;
|
||||
|
||||
/// <summary>
|
||||
/// 播放当前主场景的BGM 钓场、建造、无尽建造
|
||||
/// </summary>
|
||||
public struct EventMainBGM
|
||||
{
|
||||
|
||||
}
|
||||
public class OutPlaySound : MonoBehaviour
|
||||
{
|
||||
public enum PlayerType
|
||||
{
|
||||
None,
|
||||
OnEnable,
|
||||
OnAwake,
|
||||
OnDisable,
|
||||
}
|
||||
public PlayerType playerType = PlayerType.OnEnable;
|
||||
public SoundMainType mainType = SoundMainType.UI;
|
||||
public bool isOutDisable = false;
|
||||
public AssetReferenceT<AudioClip> assetReference;
|
||||
public float delay = 0f;
|
||||
public float startTimer = 0f;
|
||||
AssetReferenceAudioClip assetReferenceAudioClip;
|
||||
void Awake()
|
||||
{
|
||||
if (playerType == PlayerType.OnAwake)
|
||||
{
|
||||
PlaySound();
|
||||
}
|
||||
}
|
||||
private void OnEnable()
|
||||
{
|
||||
if (playerType == PlayerType.OnEnable)
|
||||
{
|
||||
PlaySound();
|
||||
}
|
||||
}
|
||||
private void OnDisable()
|
||||
{
|
||||
if (playerType == PlayerType.OnDisable)
|
||||
{
|
||||
PlaySound();
|
||||
}
|
||||
if (isOutDisable)
|
||||
{
|
||||
if (mainType != SoundMainType.BGM)
|
||||
{
|
||||
GContext.Publish(new FadeOutEvent(assetReferenceAudioClip.Sound));
|
||||
assetReferenceAudioClip.mainType = SoundMainType.None;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
GContext.Publish(new EventMainBGM());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator DelayPlaySound()
|
||||
{
|
||||
yield return new WaitForSeconds(delay);
|
||||
Play();
|
||||
}
|
||||
void Play()
|
||||
{
|
||||
// Debug.Log($"<color=#57965c>[Audio] {assetReference} Played on {gameObject}.</color>");
|
||||
assetReferenceAudioClip = new AssetReferenceAudioClip(assetReference, isOutDisable, mainType, startTimer);
|
||||
GContext.Publish(assetReferenceAudioClip);
|
||||
}
|
||||
public void PlaySound()
|
||||
{
|
||||
if (assetReference != null && assetReference.RuntimeKeyIsValid())
|
||||
{
|
||||
if (delay > 0.001f)
|
||||
{
|
||||
StartCoroutine(DelayPlaySound());
|
||||
}
|
||||
else
|
||||
{
|
||||
Play();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user