mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-03-22 19:03:29 +08:00
- 添加协程上下文、句柄、调度器和作用域管理类 - 实现协程等待指令包括 WaitForSeconds、WaitUntil 和 WaitWhile - 创建协程系统和全局协程作用域管理器 - 定义协程相关抽象接口 ICoroutineScheduler、ICoroutineScope 等 - 升级 Meziantou.Analyzer 依赖版本至 2.0.283 - 升级 Meziantou.Polyfill 依赖版本至 1.0.100
31 lines
1.1 KiB
C#
31 lines
1.1 KiB
C#
using System.Collections;
|
|
|
|
namespace GFramework.Game.coroutine;
|
|
|
|
/// <summary>
|
|
/// 全局协程作用域管理器,提供全局唯一的协程执行环境
|
|
/// </summary>
|
|
public static class GlobalCoroutineScope
|
|
{
|
|
private static CoroutineScope? _instance;
|
|
|
|
/// <summary>
|
|
/// 获取全局协程作用域实例,如果未初始化则抛出异常
|
|
/// </summary>
|
|
private static CoroutineScope Instance =>
|
|
_instance ?? throw new InvalidOperationException("GlobalScope not initialized");
|
|
|
|
/// <summary>
|
|
/// 初始化全局协程作用域
|
|
/// </summary>
|
|
/// <param name="scheduler">协程调度器实例</param>
|
|
public static void Initialize(CoroutineScheduler scheduler) =>
|
|
_instance = new CoroutineScope(scheduler, "GlobalScope");
|
|
|
|
/// <summary>
|
|
/// 在全局作用域中启动一个协程
|
|
/// </summary>
|
|
/// <param name="routine">要执行的协程枚举器</param>
|
|
/// <returns>协程句柄,用于控制和管理协程生命周期</returns>
|
|
public static CoroutineHandle Launch(IEnumerator routine) => Instance.Launch(routine);
|
|
} |