GFramework/GFramework.Game/coroutine/CoroutineContext.cs
GeWuYou ef2e718efe feat(coroutine): 完善协程系统接口设计与实现
- 实现ICoroutineContext和ICoroutineHandle接口,提供协程上下文和句柄的标准定义
- 重构CoroutineContext实现ICoroutineContext接口,统一协程上下文访问方式
- 修改CoroutineHandle实现ICoroutineHandle接口,标准化协程控制方法
- 扩展ICoroutineScheduler和ICoroutineScope接口,增加ActiveCount属性和Launch方法
- 优化CoroutineScheduler线程安全性,添加线程ID检查防止跨线程调用
- 为WaitForSeconds、WaitUntil、WaitWhile添加Reset方法支持状态重置
- 重构CoroutineScopeExtensions移除类型转换,使用接口方法替代具体类型
- 改进GlobalCoroutineScope添加TryGetScope方法,使用TryGet模式替代异常控制
- 优化CoroutineHandle取消逻辑,确保取消时正确触发OnComplete事件
- 统一各协程组件的XML文档注释,完善参数和返回值说明
- [skip ci]
2026-01-21 00:06:01 +08:00

28 lines
937 B
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using GFramework.Game.Abstractions.coroutine;
namespace GFramework.Game.coroutine;
/// <summary>
/// 协程上下文类,用于封装协程执行所需的环境信息
/// </summary>
/// <param name="scope">协程作用域,定义协程的执行范围</param>
/// <param name="scheduler">协程调度器,负责协程的调度和执行管理</param>
/// <param name="owner">协程的所有者对象可为空默认为null</param>
public class CoroutineContext(ICoroutineScope scope, CoroutineScheduler scheduler, object? owner = null)
: ICoroutineContext
{
/// <summary>
/// 获取协程作用域
/// </summary>
public ICoroutineScope Scope { get; } = scope;
/// <summary>
/// 获取协程调度器
/// </summary>
public ICoroutineScheduler Scheduler { get; } = scheduler;
/// <summary>
/// 获取协程所有者对象
/// </summary>
public object? Owner { get; } = owner;
}