using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
/// <summary>
/// 协程运行类,所有需要组件或物体禁用时都要保持运行的协程都应通过此类调用
/// </summary>
class CoroutineManager : MonoBehaviour
{
private static CoroutineManager Instance { get; set; }
private void Awake()
{
if (Instance != null) { throw new Exception("已有实例化对象"); }
Instance = this;
}
/// <summary>
/// 开始协程
/// </summary>
/// <param name="routine">协程</param>
/// <returns>返回协程实例</returns>
public static Coroutine Start(IEnumerator routine)
{
return Instance.StartCoroutine(routine);
}
/// <summary>
/// 开始协程
/// </summary>
/// <param name="methodName">协程名</param>
/// <param name="value">协程对象</param>
/// <returns></returns>
public static Coroutine Start(string methodName, object value)
{
return Instance.StartCoroutine(methodName, value);
}
/// <summary>
/// 停止协程
/// </summary>
/// <param name="routine">协程</param>
public static void Stop(IEnumerator routine)
{
Instance.StopCoroutine(routine);
}
/// <summary>
/// 停止协程
/// </summary>
/// <param name="routine">协程</param>
public static void Stop(Coroutine routine)
{
Instance.StopCoroutine(routine);
}
}
Unity游戏开发——协程管理类
最新推荐文章于 2024-08-25 22:39:22 发布