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
|
|
|
|
{
|
|
|
|
|
|
public static class CoroutineHelper
|
2025-03-06 17:24:31 +08:00
|
|
|
|
{
|
2025-04-24 13:40:09 +08:00
|
|
|
|
public static CoroutineRunner coroutineRunner;
|
2025-03-06 17:24:31 +08:00
|
|
|
|
|
2025-03-26 09:34:52 +08:00
|
|
|
|
public static void SetRunner()
|
|
|
|
|
|
{
|
|
|
|
|
|
GameObject runnerObject = new GameObject("CoroutineRunner");
|
|
|
|
|
|
coroutineRunner = runnerObject.AddComponent<CoroutineRunner>();
|
|
|
|
|
|
}
|
|
|
|
|
|
public static Coroutine StartCoroutine(IEnumerator coroutine)
|
|
|
|
|
|
{
|
|
|
|
|
|
Coroutine myCoroutine = coroutineRunner.StartCoroutine(coroutine);
|
|
|
|
|
|
return myCoroutine;
|
|
|
|
|
|
}
|
|
|
|
|
|
public static void StopCoroutine(Coroutine myCoroutine)
|
|
|
|
|
|
{
|
|
|
|
|
|
coroutineRunner.StopCoroutine(myCoroutine);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-04-24 13:40:09 +08:00
|
|
|
|
public class CoroutineRunner : MonoBehaviour
|
2025-04-22 13:50:46 +08:00
|
|
|
|
{
|
|
|
|
|
|
private void OnDestroy()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (coroutineRunner != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
coroutineRunner.StopAllCoroutines();
|
|
|
|
|
|
coroutineRunner = null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-03-26 09:34:52 +08:00
|
|
|
|
}
|
2025-03-06 17:24:31 +08:00
|
|
|
|
}
|