From 910c3b916ac75a5defd8cf80614c535749c74b6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E6=80=9D=E6=B5=B7?= <1464576565@qq.com> Date: Thu, 26 Mar 2026 19:50:59 +0800 Subject: [PATCH] fix --- Runtime/ABase/Base/Service/Core/AppScope.cs | 10 +++++++++- Runtime/ABase/Base/Service/Core/AppServices.cs | 8 ++++---- Runtime/ABase/Base/Service/Core/ServiceContext.cs | 6 +++--- Runtime/ABase/Base/Service/Core/ServiceWorld.cs | 10 +++++----- .../ABase/Base/Service/Unity/MonoServiceBehaviour.cs | 2 +- Runtime/ABase/GameObjectPool/GameObjectPoolManager.cs | 2 +- 6 files changed, 23 insertions(+), 15 deletions(-) diff --git a/Runtime/ABase/Base/Service/Core/AppScope.cs b/Runtime/ABase/Base/Service/Core/AppScope.cs index 740f4b9..6147de2 100644 --- a/Runtime/ABase/Base/Service/Core/AppScope.cs +++ b/Runtime/ABase/Base/Service/Core/AppScope.cs @@ -3,5 +3,13 @@ namespace AlicizaX /// /// 框架内置的 App Scope 标记类,生命周期与 ServiceWorld 相同。 /// - public sealed class AppScope { } + public sealed class AppScope : IScope + { + public int Order => -10000; + } + + public interface IScope + { + public int Order { get; } + } } diff --git a/Runtime/ABase/Base/Service/Core/AppServices.cs b/Runtime/ABase/Base/Service/Core/AppServices.cs index 27bedaa..2b76544 100644 --- a/Runtime/ABase/Base/Service/Core/AppServices.cs +++ b/Runtime/ABase/Base/Service/Core/AppServices.cs @@ -29,19 +29,19 @@ namespace AlicizaX // ── Scope 管理 ────────────────────────────────────────────────────────── - public static ServiceScope CreateScope(int order = 0) where TScope : class + public static ServiceScope CreateScope(int order = 0) where TScope : IScope => World.CreateScope(order); - public static ServiceScope GetOrCreateScope(int order = 0) where TScope : class + public static ServiceScope GetOrCreateScope(int order = 0) where TScope : IScope => World.GetOrCreateScope(order); - public static bool TryGetScope(out ServiceScope scope) where TScope : class + public static bool TryGetScope(out ServiceScope scope) where TScope : IScope { if (_world == null) { scope = null; return false; } return _world.TryGetScope(out scope); } - public static bool DestroyScope() where TScope : class + public static bool DestroyScope() where TScope : IScope { if (_world == null) return false; return _world.DestroyScope(); diff --git a/Runtime/ABase/Base/Service/Core/ServiceContext.cs b/Runtime/ABase/Base/Service/Core/ServiceContext.cs index 9585391..8c1e038 100644 --- a/Runtime/ABase/Base/Service/Core/ServiceContext.cs +++ b/Runtime/ABase/Base/Service/Core/ServiceContext.cs @@ -20,13 +20,13 @@ namespace AlicizaX public bool TryGet(out T service) where T : class, IService => World.TryGet(Scope, out service); - public ServiceScope CreateScope(int order = 0) where TScope : class + public ServiceScope CreateScope(int order = 0) where TScope : IScope => World.CreateScope(order); - public ServiceScope GetOrCreateScope(int order = 0) where TScope : class + public ServiceScope GetOrCreateScope(int order = 0) where TScope : IScope => World.GetOrCreateScope(order); - public bool TryGetScope(out ServiceScope scope) where TScope : class + public bool TryGetScope(out ServiceScope scope) where TScope : IScope => World.TryGetScope(out scope); } } diff --git a/Runtime/ABase/Base/Service/Core/ServiceWorld.cs b/Runtime/ABase/Base/Service/Core/ServiceWorld.cs index b0afe5c..0ad088f 100644 --- a/Runtime/ABase/Base/Service/Core/ServiceWorld.cs +++ b/Runtime/ABase/Base/Service/Core/ServiceWorld.cs @@ -20,7 +20,7 @@ namespace AlicizaX // ── Scope 管理(Type-based) ──────────────────────────────────────────── - public ServiceScope CreateScope(int order = 0) where TScope : class + public ServiceScope CreateScope(int order = 0) where TScope : IScope { var type = typeof(TScope); if (_scopesByType.ContainsKey(type)) @@ -28,7 +28,7 @@ namespace AlicizaX return CreateScopeInternal(type, order); } - public ServiceScope GetOrCreateScope(int order = 0) where TScope : class + public ServiceScope GetOrCreateScope(int order = 0) where TScope : IScope { var type = typeof(TScope); if (_scopesByType.TryGetValue(type, out var existing)) @@ -36,16 +36,16 @@ namespace AlicizaX return CreateScopeInternal(type, order); } - public bool TryGetScope(out ServiceScope scope) where TScope : class + public bool TryGetScope(out ServiceScope scope) where TScope : IScope => _scopesByType.TryGetValue(typeof(TScope), out scope); - public ServiceScope GetScope() where TScope : class + public ServiceScope GetScope() where TScope : IScope { if (TryGetScope(out var scope)) return scope; throw new InvalidOperationException($"Scope {typeof(TScope).Name} does not exist."); } - public bool DestroyScope() where TScope : class + public bool DestroyScope() where TScope : IScope { if (typeof(TScope) == typeof(AppScope)) throw new InvalidOperationException("AppScope can only be destroyed when the world is disposed."); diff --git a/Runtime/ABase/Base/Service/Unity/MonoServiceBehaviour.cs b/Runtime/ABase/Base/Service/Unity/MonoServiceBehaviour.cs index 89fd552..e56ece6 100644 --- a/Runtime/ABase/Base/Service/Unity/MonoServiceBehaviour.cs +++ b/Runtime/ABase/Base/Service/Unity/MonoServiceBehaviour.cs @@ -53,7 +53,7 @@ namespace AlicizaX /// /// public abstract class MonoServiceBehaviour : MonoServiceBehaviour - where TScope : class + where TScope : IScope { [SerializeField] private bool _dontDestroyOnLoad = false; diff --git a/Runtime/ABase/GameObjectPool/GameObjectPoolManager.cs b/Runtime/ABase/GameObjectPool/GameObjectPoolManager.cs index 0b1081e..3d65ee7 100644 --- a/Runtime/ABase/GameObjectPool/GameObjectPoolManager.cs +++ b/Runtime/ABase/GameObjectPool/GameObjectPoolManager.cs @@ -7,7 +7,7 @@ using UnityEngine; namespace AlicizaX { - public sealed class GameObjectPoolManager : MonoServiceBehaviour + public sealed class GameObjectPoolManager : MonoServiceBehaviour { private static readonly Comparison SnapshotComparer = (left, right) => {