2025-04-22 13:50:46 +08:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections;
|
2025-03-06 17:24:31 +08:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
using UnityEngine.Internal;
|
|
|
|
|
|
|
2025-03-31 11:49:53 +08:00
|
|
|
|
namespace Stary.Evo.AudioCore
|
2025-03-26 09:34:52 +08:00
|
|
|
|
{
|
2025-12-19 11:55:13 +08:00
|
|
|
|
// 音频协程启动器
|
|
|
|
|
|
public class CoroutineHelper : IDisposable
|
2025-03-06 17:24:31 +08:00
|
|
|
|
{
|
2025-12-19 11:55:13 +08:00
|
|
|
|
private static CoroutineHelper _instance = new CoroutineHelper();
|
|
|
|
|
|
public static CoroutineHelper Instance => _instance;
|
|
|
|
|
|
private CoroutineRunner _coroutineRunner;
|
|
|
|
|
|
|
|
|
|
|
|
private CoroutineHelper()
|
2025-03-26 09:34:52 +08:00
|
|
|
|
{
|
|
|
|
|
|
GameObject runnerObject = new GameObject("CoroutineRunner");
|
2025-12-19 11:55:13 +08:00
|
|
|
|
_coroutineRunner= runnerObject.AddComponent<CoroutineRunner>();
|
2025-03-26 09:34:52 +08:00
|
|
|
|
}
|
2025-12-19 11:55:13 +08:00
|
|
|
|
public Coroutine StartCoroutine(IEnumerator coroutine)
|
2025-03-26 09:34:52 +08:00
|
|
|
|
{
|
2025-12-19 11:55:13 +08:00
|
|
|
|
Coroutine myCoroutine = _coroutineRunner.StartIEnumerator(coroutine);
|
2025-03-26 09:34:52 +08:00
|
|
|
|
return myCoroutine;
|
|
|
|
|
|
}
|
2025-12-19 11:55:13 +08:00
|
|
|
|
public void StopCoroutine(Coroutine myCoroutine)
|
2025-03-26 09:34:52 +08:00
|
|
|
|
{
|
2025-12-19 11:55:13 +08:00
|
|
|
|
_coroutineRunner.StopIEnumerator(myCoroutine);
|
2025-03-26 09:34:52 +08:00
|
|
|
|
}
|
2025-12-19 11:55:13 +08:00
|
|
|
|
public void Dispose()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (_coroutineRunner != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
GameObject.Destroy(_coroutineRunner.gameObject);
|
|
|
|
|
|
_coroutineRunner = null;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (CoroutineHelper.Instance != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
CoroutineHelper._instance = null;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-04-24 13:40:09 +08:00
|
|
|
|
public class CoroutineRunner : MonoBehaviour
|
2025-04-22 13:50:46 +08:00
|
|
|
|
{
|
2025-12-19 11:55:13 +08:00
|
|
|
|
public Coroutine StartIEnumerator(IEnumerator coroutine)
|
2025-04-22 13:50:46 +08:00
|
|
|
|
{
|
2025-12-19 11:55:13 +08:00
|
|
|
|
Coroutine myCoroutine = StartCoroutine(coroutine);
|
|
|
|
|
|
return myCoroutine;
|
|
|
|
|
|
}
|
|
|
|
|
|
public void StopIEnumerator(Coroutine myCoroutine)
|
|
|
|
|
|
{
|
|
|
|
|
|
StopCoroutine(myCoroutine);
|
2025-04-22 13:50:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-03-26 09:34:52 +08:00
|
|
|
|
}
|
2025-03-06 17:24:31 +08:00
|
|
|
|
}
|
2025-12-19 11:55:13 +08:00
|
|
|
|
|