mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-03-22 10:34:30 +08:00
refactor(architecture): 移除架构运行时并使用命令查询总线
- 移除了 IArchitectureRuntime 接口和 ArchitectureRuntime 类 - 在 ArchitectureContext 中添加了对 ICommandBus 和 IQueryBus 的依赖注入 - 修改 Architecture 类以使用 CommandBus 和 QueryBus 替代 Runtime - 更新 ArchitectureServices 以提供 CommandBus 和 QueryBus 服务 - 将组件初始化逻辑从 if-else 改为 switch 语句 - 更新 ContextAwareBase 以使用新的 GetFirstArchitectureContext 方法 - 添加了 CommandBus 和 QueryBus 的实现类 - 修复了 Godot 模块中系统获取的重复代码问题
This commit is contained in:
parent
f88f90f394
commit
0c9063a5fd
@ -15,11 +15,6 @@ public interface IArchitecture : IAsyncInitializable
|
||||
/// </summary>
|
||||
IArchitectureContext Context { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取架构运行时实例
|
||||
/// </summary>
|
||||
IArchitectureRuntime Runtime { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 初始化方法,用于执行对象的初始化操作
|
||||
/// </summary>
|
||||
|
||||
@ -1,64 +0,0 @@
|
||||
using System;
|
||||
using GFramework.Core.Abstractions.command;
|
||||
using GFramework.Core.Abstractions.events;
|
||||
using GFramework.Core.Abstractions.query;
|
||||
|
||||
namespace GFramework.Core.Abstractions.architecture;
|
||||
|
||||
/// <summary>
|
||||
/// 架构运行时接口,提供统一的命令、查询、事件操作入口
|
||||
/// 负责委托 ArchitectureContext 的能力执行具体操作
|
||||
/// </summary>
|
||||
public interface IArchitectureRuntime
|
||||
{
|
||||
/// <summary>
|
||||
/// 发送并执行指定的命令
|
||||
/// </summary>
|
||||
/// <typeparam name="T">命令类型,必须实现ICommand接口</typeparam>
|
||||
/// <param name="command">要执行的命令实例</param>
|
||||
void SendCommand<T>(T command) where T : ICommand;
|
||||
|
||||
/// <summary>
|
||||
/// 发送并执行带有返回值的命令
|
||||
/// </summary>
|
||||
/// <typeparam name="TResult">命令执行结果的类型</typeparam>
|
||||
/// <param name="command">要执行的命令实例</param>
|
||||
/// <returns>命令执行的结果</returns>
|
||||
TResult SendCommand<TResult>(ICommand<TResult> command);
|
||||
|
||||
/// <summary>
|
||||
/// 发送并执行查询操作
|
||||
/// </summary>
|
||||
/// <typeparam name="TResult">查询结果的类型</typeparam>
|
||||
/// <param name="query">要执行的查询实例</param>
|
||||
/// <returns>查询的结果</returns>
|
||||
TResult SendQuery<TResult>(IQuery<TResult> query);
|
||||
|
||||
/// <summary>
|
||||
/// 发送无参事件
|
||||
/// </summary>
|
||||
/// <typeparam name="TEvent">事件类型,必须具有无参构造函数</typeparam>
|
||||
void SendEvent<TEvent>() where TEvent : new();
|
||||
|
||||
/// <summary>
|
||||
/// 发送指定的事件实例
|
||||
/// </summary>
|
||||
/// <typeparam name="TEvent">事件类型</typeparam>
|
||||
/// <param name="e">要发送的事件实例</param>
|
||||
void SendEvent<TEvent>(TEvent e) where TEvent : class;
|
||||
|
||||
/// <summary>
|
||||
/// 注册事件监听器
|
||||
/// </summary>
|
||||
/// <typeparam name="TEvent">事件类型</typeparam>
|
||||
/// <param name="onEvent">事件触发时的回调方法</param>
|
||||
/// <returns>用于取消注册的句柄</returns>
|
||||
IUnRegister RegisterEvent<TEvent>(Action<TEvent> onEvent);
|
||||
|
||||
/// <summary>
|
||||
/// 取消注册事件监听器
|
||||
/// </summary>
|
||||
/// <typeparam name="TEvent">事件类型</typeparam>
|
||||
/// <param name="onEvent">要取消注册的事件回调方法</param>
|
||||
void UnRegisterEvent<TEvent>(Action<TEvent> onEvent);
|
||||
}
|
||||
@ -1,5 +1,7 @@
|
||||
using GFramework.Core.Abstractions.events;
|
||||
using GFramework.Core.Abstractions.command;
|
||||
using GFramework.Core.Abstractions.events;
|
||||
using GFramework.Core.Abstractions.ioc;
|
||||
using GFramework.Core.Abstractions.query;
|
||||
using GFramework.Core.Abstractions.rule;
|
||||
|
||||
namespace GFramework.Core.Abstractions.architecture;
|
||||
@ -20,4 +22,14 @@ public interface IArchitectureServices : IContextAware
|
||||
/// </summary>
|
||||
/// <returns>ITypeEventSystem类型的事件系统实例</returns>
|
||||
ITypeEventSystem TypeEventSystem { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取命令总线
|
||||
/// </summary>
|
||||
public ICommandBus CommandBus { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取查询总线
|
||||
/// </summary>
|
||||
public IQueryBus QueryBus { get; }
|
||||
}
|
||||
21
GFramework.Core.Abstractions/command/ICommandBus.cs
Normal file
21
GFramework.Core.Abstractions/command/ICommandBus.cs
Normal file
@ -0,0 +1,21 @@
|
||||
namespace GFramework.Core.Abstractions.command;
|
||||
|
||||
/// <summary>
|
||||
/// 定义命令总线接口,用于执行各种命令
|
||||
/// </summary>
|
||||
public interface ICommandBus
|
||||
{
|
||||
/// <summary>
|
||||
/// 发送并执行一个命令
|
||||
/// </summary>
|
||||
/// <param name="command">要执行的命令对象</param>
|
||||
public void Send(ICommand command);
|
||||
|
||||
/// <summary>
|
||||
/// 发送并执行一个带返回值的命令
|
||||
/// </summary>
|
||||
/// <typeparam name="TResult">命令执行结果的类型</typeparam>
|
||||
/// <param name="command">要执行的带返回值的命令对象</param>
|
||||
/// <returns>命令执行的结果</returns>
|
||||
public TResult Send<TResult>(ICommand<TResult> command);
|
||||
}
|
||||
15
GFramework.Core.Abstractions/query/IQueryBus.cs
Normal file
15
GFramework.Core.Abstractions/query/IQueryBus.cs
Normal file
@ -0,0 +1,15 @@
|
||||
namespace GFramework.Core.Abstractions.query;
|
||||
|
||||
/// <summary>
|
||||
/// 查询总线接口,用于发送和处理查询请求
|
||||
/// </summary>
|
||||
public interface IQueryBus
|
||||
{
|
||||
/// <summary>
|
||||
/// 发送查询请求并返回结果
|
||||
/// </summary>
|
||||
/// <typeparam name="TResult">查询结果的类型</typeparam>
|
||||
/// <param name="query">要发送的查询对象</param>
|
||||
/// <returns>查询结果</returns>
|
||||
public TResult Send<TResult>(IQuery<TResult> query);
|
||||
}
|
||||
@ -33,7 +33,6 @@ public class AsyncArchitectureTests : ArchitectureTestsBase<AsyncTestArchitectur
|
||||
await Architecture!.InitializeAsync();
|
||||
|
||||
Assert.That(Architecture.InitCalled, Is.True);
|
||||
Assert.That(Architecture.Runtime, Is.Not.Null);
|
||||
Assert.That(Architecture.CurrentPhase, Is.EqualTo(ArchitecturePhase.Ready));
|
||||
|
||||
var context = Architecture.Context;
|
||||
|
||||
@ -30,7 +30,6 @@ public class SyncArchitectureTests : ArchitectureTestsBase<SyncTestArchitecture>
|
||||
// Assert
|
||||
Assert.That(Architecture.InitCalled, Is.True);
|
||||
|
||||
Assert.That(Architecture.Runtime, Is.Not.Null);
|
||||
|
||||
var phase = Architecture.CurrentPhase;
|
||||
Assert.That(phase, Is.EqualTo(ArchitecturePhase.Ready));
|
||||
|
||||
@ -1,9 +1,11 @@
|
||||
using GFramework.Core.Abstractions.architecture;
|
||||
using GFramework.Core.Abstractions.command;
|
||||
using GFramework.Core.Abstractions.enums;
|
||||
using GFramework.Core.Abstractions.events;
|
||||
using GFramework.Core.Abstractions.ioc;
|
||||
using GFramework.Core.Abstractions.logging;
|
||||
using GFramework.Core.Abstractions.model;
|
||||
using GFramework.Core.Abstractions.query;
|
||||
using GFramework.Core.Abstractions.system;
|
||||
using GFramework.Core.Abstractions.utility;
|
||||
using GFramework.Core.events;
|
||||
@ -55,13 +57,9 @@ public abstract class Architecture(
|
||||
/// </value>
|
||||
private ITypeEventSystem TypeEventSystem => Services.TypeEventSystem;
|
||||
|
||||
/// <summary>
|
||||
/// 获取架构运行时实例
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// 统一的操作入口,负责命令、查询、事件的执行
|
||||
/// </value>
|
||||
public IArchitectureRuntime Runtime { get; private set; } = null!;
|
||||
private ICommandBus CommandBus => Services.CommandBus;
|
||||
|
||||
private IQueryBus QueryBus => Services.QueryBus;
|
||||
|
||||
#region Module Management
|
||||
|
||||
@ -282,14 +280,16 @@ public abstract class Architecture(
|
||||
{
|
||||
await asyncInit.InitializeAsync();
|
||||
}
|
||||
else if (component is IModel model)
|
||||
{
|
||||
model.Init();
|
||||
}
|
||||
else if (component is ISystem system)
|
||||
{
|
||||
system.Init();
|
||||
}
|
||||
else
|
||||
switch (component)
|
||||
{
|
||||
case IModel model:
|
||||
model.Init();
|
||||
break;
|
||||
case ISystem system:
|
||||
system.Init();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -306,14 +306,10 @@ public abstract class Architecture(
|
||||
_logger = LoggerFactoryResolver.Provider.CreateLogger(GetType().Name);
|
||||
|
||||
// 初始化架构上下文(如果尚未初始化)
|
||||
_context ??= new ArchitectureContext(Container, TypeEventSystem);
|
||||
_context ??= new ArchitectureContext(Container, TypeEventSystem, CommandBus, QueryBus);
|
||||
// 将当前架构类型与上下文绑定到游戏上下文
|
||||
GameContext.Bind(GetType(), _context);
|
||||
|
||||
// 创建架构运行时实例
|
||||
Runtime = new ArchitectureRuntime(_context);
|
||||
// 设置上下文中的运行时引用
|
||||
((ArchitectureContext)_context).Runtime = Runtime;
|
||||
// 为服务设置上下文
|
||||
Services.SetContext(_context);
|
||||
|
||||
|
||||
@ -14,16 +14,18 @@ namespace GFramework.Core.architecture;
|
||||
/// </summary>
|
||||
public class ArchitectureContext(
|
||||
IIocContainer container,
|
||||
ITypeEventSystem typeEventSystem)
|
||||
ITypeEventSystem typeEventSystem,
|
||||
ICommandBus commandBus,
|
||||
IQueryBus queryBus)
|
||||
: IArchitectureContext
|
||||
{
|
||||
private readonly ICommandBus _commandBus = commandBus ?? throw new ArgumentNullException(nameof(commandBus));
|
||||
private readonly IIocContainer _container = container ?? throw new ArgumentNullException(nameof(container));
|
||||
private readonly IQueryBus _queryBus = queryBus ?? throw new ArgumentNullException(nameof(queryBus));
|
||||
|
||||
private readonly ITypeEventSystem _typeEventSystem =
|
||||
typeEventSystem ?? throw new ArgumentNullException(nameof(typeEventSystem));
|
||||
|
||||
internal IArchitectureRuntime Runtime { get; set; } = null!;
|
||||
|
||||
#region Query Execution
|
||||
|
||||
/// <summary>
|
||||
@ -34,7 +36,7 @@ public class ArchitectureContext(
|
||||
/// <returns>查询结果</returns>
|
||||
public TResult SendQuery<TResult>(IQuery<TResult> query)
|
||||
{
|
||||
return query == null ? throw new ArgumentNullException(nameof(query)) : Runtime.SendQuery(query);
|
||||
return query == null ? throw new ArgumentNullException(nameof(query)) : _queryBus.Send(query);
|
||||
}
|
||||
|
||||
#endregion
|
||||
@ -76,17 +78,17 @@ public class ArchitectureContext(
|
||||
#region Command Execution
|
||||
|
||||
/// <summary>
|
||||
/// 发送一个无返回结果的命令
|
||||
/// 发送一个命令请求
|
||||
/// </summary>
|
||||
/// <param name="command">要发送的命令</param>
|
||||
public void SendCommand(ICommand command)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(command);
|
||||
Runtime.SendCommand(command);
|
||||
_commandBus.Send(command);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 发送一个带返回值的命令
|
||||
/// 发送一个带返回值的命令请求
|
||||
/// </summary>
|
||||
/// <typeparam name="TResult">命令执行结果类型</typeparam>
|
||||
/// <param name="command">要发送的命令</param>
|
||||
@ -94,7 +96,7 @@ public class ArchitectureContext(
|
||||
public TResult SendCommand<TResult>(ICommand<TResult> command)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(command);
|
||||
return Runtime.SendCommand(command);
|
||||
return _commandBus.Send(command);
|
||||
}
|
||||
|
||||
#endregion
|
||||
@ -117,7 +119,7 @@ public class ArchitectureContext(
|
||||
/// <param name="e">事件参数</param>
|
||||
public void SendEvent<TEvent>(TEvent e) where TEvent : class
|
||||
{
|
||||
if (e == null) throw new ArgumentNullException(nameof(e));
|
||||
ArgumentNullException.ThrowIfNull(e);
|
||||
_typeEventSystem.Send(e);
|
||||
}
|
||||
|
||||
|
||||
@ -1,98 +0,0 @@
|
||||
using GFramework.Core.Abstractions.architecture;
|
||||
using GFramework.Core.Abstractions.command;
|
||||
using GFramework.Core.Abstractions.events;
|
||||
using GFramework.Core.Abstractions.query;
|
||||
|
||||
namespace GFramework.Core.architecture;
|
||||
|
||||
/// <summary>
|
||||
/// 架构运行时默认实现,委托 ArchitectureContext 执行具体操作
|
||||
/// </summary>
|
||||
public class ArchitectureRuntime(IArchitectureContext context) : IArchitectureRuntime
|
||||
{
|
||||
private readonly IArchitectureContext _context = context ?? throw new ArgumentNullException(nameof(context));
|
||||
|
||||
#region Query Execution
|
||||
|
||||
/// <summary>
|
||||
/// 发起一次查询请求并获得其结果
|
||||
/// </summary>
|
||||
/// <typeparam name="TResult">查询结果的数据类型</typeparam>
|
||||
/// <param name="query">要发起的查询对象</param>
|
||||
/// <returns>查询得到的结果数据</returns>
|
||||
public TResult SendQuery<TResult>(IQuery<TResult> query)
|
||||
{
|
||||
return _context.SendQuery(query);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Command Execution
|
||||
|
||||
/// <summary>
|
||||
/// 发送一个无返回结果的命令请求
|
||||
/// </summary>
|
||||
/// <typeparam name="TCommand">命令的具体类型</typeparam>
|
||||
/// <param name="command">要发送的命令对象</param>
|
||||
public void SendCommand<TCommand>(TCommand command) where TCommand : ICommand
|
||||
{
|
||||
_context.SendCommand(command);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 发送一个带返回结果的命令请求
|
||||
/// </summary>
|
||||
/// <typeparam name="TResult">命令执行后的返回值类型</typeparam>
|
||||
/// <param name="command">要发送的命令对象</param>
|
||||
/// <returns>命令执行的结果</returns>
|
||||
public TResult SendCommand<TResult>(ICommand<TResult> command)
|
||||
{
|
||||
return _context.SendCommand(command);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Event Management
|
||||
|
||||
/// <summary>
|
||||
/// 发布一个默认构造的新事件对象
|
||||
/// </summary>
|
||||
/// <typeparam name="TEvent">事件类型</typeparam>
|
||||
public void SendEvent<TEvent>() where TEvent : new()
|
||||
{
|
||||
_context.SendEvent<TEvent>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 发布一个具体的事件对象
|
||||
/// </summary>
|
||||
/// <typeparam name="TEvent">事件类型</typeparam>
|
||||
/// <param name="e">要发布的事件实例</param>
|
||||
public void SendEvent<TEvent>(TEvent e) where TEvent : class
|
||||
{
|
||||
_context.SendEvent(e);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 订阅某个特定类型的事件
|
||||
/// </summary>
|
||||
/// <typeparam name="TEvent">事件类型</typeparam>
|
||||
/// <param name="onEvent">当事件发生时触发的动作</param>
|
||||
/// <returns>可用于取消订阅的对象</returns>
|
||||
public IUnRegister RegisterEvent<TEvent>(Action<TEvent> onEvent)
|
||||
{
|
||||
return _context.RegisterEvent(onEvent);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 取消对某类型事件的监听
|
||||
/// </summary>
|
||||
/// <typeparam name="TEvent">事件类型</typeparam>
|
||||
/// <param name="onEvent">之前绑定的事件处理器</param>
|
||||
public void UnRegisterEvent<TEvent>(Action<TEvent> onEvent)
|
||||
{
|
||||
_context.UnRegisterEvent(onEvent);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@ -1,23 +1,56 @@
|
||||
using GFramework.Core.Abstractions.architecture;
|
||||
using GFramework.Core.Abstractions.command;
|
||||
using GFramework.Core.Abstractions.events;
|
||||
using GFramework.Core.Abstractions.ioc;
|
||||
using GFramework.Core.Abstractions.query;
|
||||
using GFramework.Core.command;
|
||||
using GFramework.Core.events;
|
||||
using GFramework.Core.ioc;
|
||||
using GFramework.Core.query;
|
||||
|
||||
namespace GFramework.Core.architecture;
|
||||
|
||||
/// <summary>
|
||||
/// 架构服务类,提供依赖注入容器、事件系统、命令总线和查询总线等核心服务
|
||||
/// </summary>
|
||||
public class ArchitectureServices : IArchitectureServices
|
||||
{
|
||||
private IArchitectureContext _context = null!;
|
||||
|
||||
/// <summary>
|
||||
/// 获取依赖注入容器
|
||||
/// </summary>
|
||||
public IIocContainer Container { get; } = new IocContainer();
|
||||
|
||||
/// <summary>
|
||||
/// 获取类型事件系统
|
||||
/// </summary>
|
||||
public ITypeEventSystem TypeEventSystem { get; } = new TypeEventSystem();
|
||||
|
||||
/// <summary>
|
||||
/// 获取命令总线
|
||||
/// </summary>
|
||||
public ICommandBus CommandBus { get; } = new CommandBus();
|
||||
|
||||
/// <summary>
|
||||
/// 获取查询总线
|
||||
/// </summary>
|
||||
public IQueryBus QueryBus { get; } = new QueryBus();
|
||||
|
||||
/// <summary>
|
||||
/// 设置架构上下文
|
||||
/// </summary>
|
||||
/// <param name="context">架构上下文对象</param>
|
||||
public void SetContext(IArchitectureContext context)
|
||||
{
|
||||
_context = context;
|
||||
Container.SetContext(context);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取架构上下文
|
||||
/// </summary>
|
||||
/// <returns>架构上下文对象</returns>
|
||||
public IArchitectureContext GetContext()
|
||||
{
|
||||
return _context;
|
||||
|
||||
@ -38,7 +38,7 @@ public static class GameContext
|
||||
/// </summary>
|
||||
/// <returns>返回字典中的第一个架构上下文实例</returns>
|
||||
/// <exception cref="InvalidOperationException">当字典为空时抛出</exception>
|
||||
public static IArchitectureContext GetFirstArchitecture()
|
||||
public static IArchitectureContext GetFirstArchitectureContext()
|
||||
{
|
||||
return ArchitectureDictionary.Values.First();
|
||||
}
|
||||
|
||||
35
GFramework.Core/command/CommandBus.cs
Normal file
35
GFramework.Core/command/CommandBus.cs
Normal file
@ -0,0 +1,35 @@
|
||||
using GFramework.Core.Abstractions.command;
|
||||
|
||||
namespace GFramework.Core.command;
|
||||
|
||||
/// <summary>
|
||||
/// 命令总线实现类,用于发送和执行命令
|
||||
/// </summary>
|
||||
public sealed class CommandBus : ICommandBus
|
||||
{
|
||||
/// <summary>
|
||||
/// 发送并执行无返回值的命令
|
||||
/// </summary>
|
||||
/// <param name="command">要执行的命令对象,不能为空</param>
|
||||
/// <exception cref="ArgumentNullException">当command参数为null时抛出</exception>
|
||||
public void Send(ICommand command)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(command);
|
||||
|
||||
command.Execute();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 发送并执行有返回值的命令
|
||||
/// </summary>
|
||||
/// <typeparam name="TResult">命令执行结果的类型</typeparam>
|
||||
/// <param name="command">要执行的命令对象,不能为空</param>
|
||||
/// <returns>命令执行的结果</returns>
|
||||
/// <exception cref="ArgumentNullException">当command参数为null时抛出</exception>
|
||||
public TResult Send<TResult>(ICommand<TResult> command)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(command);
|
||||
|
||||
return command.Execute();
|
||||
}
|
||||
}
|
||||
23
GFramework.Core/query/QueryBus.cs
Normal file
23
GFramework.Core/query/QueryBus.cs
Normal file
@ -0,0 +1,23 @@
|
||||
using GFramework.Core.Abstractions.query;
|
||||
|
||||
namespace GFramework.Core.query;
|
||||
|
||||
/// <summary>
|
||||
/// 查询总线实现,负责执行查询并返回结果
|
||||
/// </summary>
|
||||
public sealed class QueryBus : IQueryBus
|
||||
{
|
||||
/// <summary>
|
||||
/// 执行指定的查询并返回结果
|
||||
/// </summary>
|
||||
/// <typeparam name="TResult">查询结果的类型</typeparam>
|
||||
/// <param name="query">要执行的查询对象</param>
|
||||
/// <returns>查询执行结果</returns>
|
||||
public TResult Send<TResult>(IQuery<TResult> query)
|
||||
{
|
||||
// 验证查询参数不为null
|
||||
ArgumentNullException.ThrowIfNull(query);
|
||||
|
||||
return query.Do();
|
||||
}
|
||||
}
|
||||
@ -1,5 +1,6 @@
|
||||
using GFramework.Core.Abstractions.architecture;
|
||||
using GFramework.Core.Abstractions.rule;
|
||||
using GFramework.Core.architecture;
|
||||
|
||||
namespace GFramework.Core.rule;
|
||||
|
||||
@ -11,7 +12,7 @@ public abstract class ContextAwareBase : IContextAware
|
||||
/// <summary>
|
||||
/// 获取当前实例的架构上下文
|
||||
/// </summary>
|
||||
protected IArchitectureContext Context { get; set; } = null!;
|
||||
protected IArchitectureContext? Context { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 设置架构上下文的实现方法,由框架调用
|
||||
@ -29,6 +30,7 @@ public abstract class ContextAwareBase : IContextAware
|
||||
/// <returns>当前架构上下文对象</returns>
|
||||
IArchitectureContext IContextAware.GetContext()
|
||||
{
|
||||
Context ??= GameContext.GetFirstArchitectureContext();
|
||||
return Context;
|
||||
}
|
||||
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using GFramework.Core.Abstractions.enums;
|
||||
using GFramework.Core.extensions;
|
||||
using GFramework.Core.system;
|
||||
using GFramework.Game.Abstractions.assets;
|
||||
using GFramework.Godot.Abstractions.assets;
|
||||
@ -63,8 +64,8 @@ public abstract class AbstractResourceFactorySystem : AbstractSystem, IResourceF
|
||||
protected override void OnInit()
|
||||
{
|
||||
_registry = new ResourceFactory.Registry();
|
||||
_resourceLoadSystem = Context.GetSystem<IResourceLoadSystem>();
|
||||
_assetCatalogSystem = Context.GetSystem<IAssetCatalogSystem>();
|
||||
_assetCatalogSystem = this.GetSystem<IAssetCatalogSystem>();
|
||||
_assetCatalogSystem = this.GetSystem<IAssetCatalogSystem>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
using GFramework.Core.extensions;
|
||||
using GFramework.Core.system;
|
||||
using GFramework.Game.Abstractions.assets;
|
||||
using GFramework.Godot.Abstractions.assets;
|
||||
@ -431,9 +432,9 @@ public abstract class AbstractAudioManagerSystem : AbstractSystem, IAudioManager
|
||||
protected override void OnInit()
|
||||
{
|
||||
// 获取依赖的系统
|
||||
ResourceLoadSystem = Context.GetSystem<IResourceLoadSystem>();
|
||||
AssetCatalogSystem = Context.GetSystem<IAssetCatalogSystem>();
|
||||
ResourceFactorySystem = Context.GetSystem<IResourceFactorySystem>();
|
||||
ResourceLoadSystem = this.GetSystem<IResourceLoadSystem>();
|
||||
AssetCatalogSystem = this.GetSystem<IAssetCatalogSystem>();
|
||||
ResourceFactorySystem = this.GetSystem<IResourceFactorySystem>();
|
||||
|
||||
// 初始化背景音乐播放器
|
||||
MusicPlayer = new AudioStreamPlayer();
|
||||
|
||||
@ -64,7 +64,7 @@ public class ContextAwareGeneratorSnapshotTests
|
||||
/// </summary>
|
||||
/// <returns>返回字典中的第一个架构上下文实例</returns>
|
||||
/// <exception cref="InvalidOperationException">当字典为空时抛出</exception>
|
||||
public static IArchitectureContext GetFirstArchitecture()
|
||||
public static IArchitectureContext GetFirstArchitectureContext()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -140,7 +140,7 @@ public sealed class ContextAwareGenerator : MetadataAttributeClassGeneratorBase
|
||||
sb.AppendLine(" if (_context == null)");
|
||||
sb.AppendLine(" {");
|
||||
sb.AppendLine(
|
||||
" _context = global::GFramework.Core.architecture.GameContext.GetFirstArchitecture();");
|
||||
" _context = global::GFramework.Core.architecture.GameContext.GetFirstArchitectureContext();");
|
||||
sb.AppendLine(" }");
|
||||
sb.AppendLine();
|
||||
sb.AppendLine(" return _context;");
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user