diff --git a/Editor/GameObjectPool/GameObjectPoolEditor.cs b/Editor/GameObjectPool/GameObjectPoolEditor.cs index e893c44..1609618 100644 --- a/Editor/GameObjectPool/GameObjectPoolEditor.cs +++ b/Editor/GameObjectPool/GameObjectPoolEditor.cs @@ -4,7 +4,7 @@ using UnityEngine; namespace AlicizaX { - [CustomEditor(typeof(GameObjectPool))] + [CustomEditor(typeof(GameObjectPoolManager))] public sealed class GameObjectPoolEditor : UnityEditor.Editor { private readonly Dictionary _foldoutState = new Dictionary(); @@ -16,7 +16,7 @@ namespace AlicizaX DrawDefaultInspector(); serializedObject.ApplyModifiedProperties(); - var pool = (GameObjectPool)target; + var pool = (GameObjectPoolManager)target; if (!Application.isPlaying) { EditorGUILayout.HelpBox("Enter Play Mode to inspect runtime pool state.", MessageType.Info); @@ -34,19 +34,19 @@ namespace AlicizaX public override bool RequiresConstantRepaint() { - var pool = target as GameObjectPool; + var pool = target as GameObjectPoolManager; return pool != null && Application.isPlaying && pool.showDetailedInfo; } - private void DrawRuntimeState(GameObjectPool pool) + private void DrawRuntimeState(GameObjectPoolManager poolManager) { - if (!pool.IsReady) + if (!poolManager.IsReady) { EditorGUILayout.HelpBox("GameObjectPool is initializing.", MessageType.Info); return; } - List snapshots = pool.GetDebugSnapshots(); + List snapshots = poolManager.GetDebugSnapshots(); if (snapshots.Count == 0) { EditorGUILayout.HelpBox("No runtime pools have been created yet.", MessageType.Info); diff --git a/Entry.prefab b/Entry.prefab index f2db106..6e82e7c 100644 --- a/Entry.prefab +++ b/Entry.prefab @@ -156,37 +156,6 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 1e28a727443c86c40aeb42ff20e0a343, type: 3} m_Name: m_EditorClassIdentifier: ---- !u!1 &2946186047994278043 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 8452422965548084857} - m_Layer: 0 - m_Name: Fsm - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!4 &8452422965548084857 -Transform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 2946186047994278043} - serializedVersion: 2 - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 0, z: 0} - m_LocalScale: {x: 1, y: 1, z: 1} - m_ConstrainProportionsScale: 0 - m_Children: [] - m_Father: {fileID: 425597497363353001} - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &3646865557585103128 GameObject: m_ObjectHideFlags: 0 @@ -268,7 +237,6 @@ Transform: - {fileID: 424925309774805088} - {fileID: 7231588671532407876} - {fileID: 1640076400431107710} - - {fileID: 8452422965548084857} - {fileID: 9160912643551877041} - {fileID: 9144434048949093429} - {fileID: 5595937395452803435} @@ -288,6 +256,8 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 252fa1bb9e36411fb4582d0656b987bf, type: 3} m_Name: m_EditorClassIdentifier: + _dontDestroyOnLoad: 1 + _appScopeOrder: -10000 frameRate: 120 gameSpeed: 1 runInBackground: 1 @@ -304,9 +274,9 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: d544088dbfb44263bddb36004521fee5, type: 3} m_Name: m_EditorClassIdentifier: - _resourceComponent: {fileID: 7354290124713579766} - _debuggerComponent: {fileID: 8897508624174186059} - _localizationComponent: {fileID: 1599215827984154130} + resourceComponent: {fileID: 7354290124713579766} + debuggerComponent: {fileID: 8897508624174186059} + localizationComponent: {fileID: 1599215827984154130} --- !u!1 &6519989611955579811 GameObject: m_ObjectHideFlags: 0 diff --git a/Runtime/ABase/Base/Module.meta b/Runtime/ABase/Base/Module.meta deleted file mode 100644 index b324d54..0000000 --- a/Runtime/ABase/Base/Module.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: aeb86cc258fa4378ba3b259a5d38e4df -timeCreated: 1736424998 \ No newline at end of file diff --git a/Runtime/ABase/Base/Module/IModule.cs b/Runtime/ABase/Base/Module/IModule.cs deleted file mode 100644 index 5c390bf..0000000 --- a/Runtime/ABase/Base/Module/IModule.cs +++ /dev/null @@ -1,42 +0,0 @@ -namespace AlicizaX -{ - public interface IModule - { - protected internal void Dispose(); - } - - public interface IModuleAwake - { - protected internal void Awake(); - } - - public interface IExecuteSystem - { - abstract int Priority { get; } - } - - public interface IModuleUpdate : IExecuteSystem - { - protected internal void Update(float elapseSeconds, float realElapseSeconds); - } - - public interface IModuleLateUpdate : IExecuteSystem - { - protected internal void LateUpdate(); - } - - public interface IModuleFixedUpdate : IExecuteSystem - { - protected internal void FixedUpdate(); - } - - public interface IModuleDrawGizmos : IExecuteSystem - { - protected internal void DrawGizmos(); - } - - public interface IModuleGUI : IExecuteSystem - { - protected internal void OnGUI(); - } -} diff --git a/Runtime/ABase/Base/Module/IModule.cs.meta b/Runtime/ABase/Base/Module/IModule.cs.meta deleted file mode 100644 index e93bf72..0000000 --- a/Runtime/ABase/Base/Module/IModule.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 0ba192d5e9084d67b16b53e843e103b3 -timeCreated: 1736424999 \ No newline at end of file diff --git a/Runtime/ABase/Base/Module/ModuleSystem.cs b/Runtime/ABase/Base/Module/ModuleSystem.cs deleted file mode 100644 index 2898c70..0000000 --- a/Runtime/ABase/Base/Module/ModuleSystem.cs +++ /dev/null @@ -1,303 +0,0 @@ -using System; -using System.Buffers; -using System.Collections.Generic; - -namespace AlicizaX -{ - public static class ModuleSystem - { - internal const int DesignModuleCount = 32; - - private static readonly Dictionary _moduleMaps = new Dictionary(DesignModuleCount); - private static readonly GameFrameworkLinkedList _modules = new GameFrameworkLinkedList(); - - // Update systems - private static readonly GameFrameworkLinkedList _updateModules = new GameFrameworkLinkedList(); - private static readonly IModuleUpdate[] _updateExecuteArray = new IModuleUpdate[DesignModuleCount]; - private static int _updateExecuteCount; - - // LateUpdate systems - private static readonly GameFrameworkLinkedList _lateUpdateModules = new GameFrameworkLinkedList(); - private static readonly IModuleLateUpdate[] _lateUpdateExecuteArray = new IModuleLateUpdate[DesignModuleCount]; - private static int _lateUpdateExecuteCount; - - // FixedUpdate systems - private static readonly GameFrameworkLinkedList _fixedUpdateModules = new GameFrameworkLinkedList(); - private static readonly IModuleFixedUpdate[] _fixedUpdateExecuteArray = new IModuleFixedUpdate[DesignModuleCount]; - private static int _fixedUpdateExecuteCount; - - // Gizmos systems - private static readonly GameFrameworkLinkedList _gizmosUpdateModules = new GameFrameworkLinkedList(); - private static readonly IModuleDrawGizmos[] _gizmosUpdateExecuteArray = new IModuleDrawGizmos[DesignModuleCount]; - private static int _gizmosExecuteCount; - - // GUI systems - private static readonly GameFrameworkLinkedList _guiUpdateModules = new GameFrameworkLinkedList(); - private static readonly IModuleGUI[] _guiUpdateExecuteArray = new IModuleGUI[DesignModuleCount]; - private static int _guiExecuteCount; - - // Dirty flags - private static bool _isExecuteListDirty; - private static bool _isLateExecuteListDirty; - private static bool _isFixedExecuteListDirty; - private static bool _isGizmosExecuteListDirty; - private static bool _isGUIExecuteListDirty; - - internal static void Dispose() - { - // Clear all modules and execute arrays - _updateModules.Clear(); - Array.Clear(_updateExecuteArray, 0, _updateExecuteArray.Length); - _updateExecuteCount = 0; - - _lateUpdateModules.Clear(); - Array.Clear(_lateUpdateExecuteArray, 0, _lateUpdateExecuteArray.Length); - _lateUpdateExecuteCount = 0; - - _fixedUpdateModules.Clear(); - Array.Clear(_fixedUpdateExecuteArray, 0, _fixedUpdateExecuteArray.Length); - _fixedUpdateExecuteCount = 0; - - _gizmosUpdateModules.Clear(); - Array.Clear(_gizmosUpdateExecuteArray, 0, _gizmosUpdateExecuteArray.Length); - _gizmosExecuteCount = 0; - - _guiUpdateModules.Clear(); - Array.Clear(_guiUpdateExecuteArray, 0, _guiUpdateExecuteArray.Length); - _guiExecuteCount = 0; - - // Dispose all modules - for (var current = _modules.Last; current != null; current = current.Previous) - { - current.Value.Dispose(); - } - - _modules.Clear(); - _moduleMaps.Clear(); - } - - #region Public System - - public static T RegisterModule() where T : IModule where TImple : class, T, new() - { - Type interfaceType = typeof(T); - Type implType = typeof(TImple); - if (!interfaceType.IsInterface) - { - throw new GameFrameworkException(Utility.Text.Format("You must register module by interface, but '{0}' is not.", interfaceType.FullName)); - } - - if (!implType.IsClass || implType.IsInterface || implType.IsAbstract) - { - throw new GameFrameworkException(Utility.Text.Format("You must register module by Class and not Interface and Abstract, but '{0}' is not.", implType.FullName)); - } - - if (!typeof(IModule).IsAssignableFrom(interfaceType)) - { - throw new GameFrameworkException(Utility.Text.Format("Module must implement IModule.", interfaceType.FullName)); - } - - if (GetModule(interfaceType) != null) - { - Log.Error("Already Register {0}", interfaceType.FullName); - return default; - } - - TImple impl = new TImple(); - return (T)SetModuleInstance(interfaceType, impl); - } - - public static T GetModule() where T : class - { - Type interfaceType = typeof(T); - if (!interfaceType.IsInterface) - { - throw new GameFrameworkException(Utility.Text.Format("You must get module by interface, but '{0}' is not.", interfaceType.FullName)); - } - - return GetModule(interfaceType) as T; - } - - public static IModule GetModule(Type moduleType) - { - return _moduleMaps.TryGetValue(moduleType, out var ret) ? ret : default; - } - - private static IModule SetModuleInstance(Type interfaceType, TImpl impl) where TImpl : class, IModule - { - _moduleMaps[interfaceType] = impl; - _modules.AddLast(impl); - - if (impl is IModuleAwake awakeSystem) - { - awakeSystem.Awake(); - } - - CheckSystemLife(impl); - return impl; - } - - #endregion - - private static void CheckSystemLife(IModule module) - { - if (module is IModuleUpdate updateSystem) - { - BindSystemLife(updateSystem, _updateModules, ref _isExecuteListDirty); - } - - if (module is IModuleLateUpdate lateUpdate) - { - BindSystemLife(lateUpdate, _lateUpdateModules, ref _isLateExecuteListDirty); - } - - if (module is IModuleFixedUpdate fixedUpdate) - { - BindSystemLife(fixedUpdate, _fixedUpdateModules, ref _isFixedExecuteListDirty); - } - - if (module is IModuleDrawGizmos drawGizmosUpdate) - { - BindSystemLife(drawGizmosUpdate, _gizmosUpdateModules, ref _isGizmosExecuteListDirty); - } - - if (module is IModuleGUI guiUpdate) - { - BindSystemLife(guiUpdate, _guiUpdateModules, ref _isGUIExecuteListDirty); - } - } - - private static void BindSystemLife(T system, GameFrameworkLinkedList updateModule, ref bool executeDirty) where T : IExecuteSystem - { - var current = updateModule.First; - while (current != null && system.Priority <= current.Value.Priority) - { - current = current.Next; - } - - if (current != null) - { - updateModule.AddBefore(current, system); - } - else - { - updateModule.AddLast(system); - } - - executeDirty = true; - } - - #region BuildExecuteList - - private static void BuildExecuteList() - { - if (!_isExecuteListDirty) return; - _isExecuteListDirty = false; - _updateExecuteCount = 0; - foreach (var module in _updateModules) - { - if (_updateExecuteCount >= _updateExecuteArray.Length) break; - _updateExecuteArray[_updateExecuteCount++] = module; - } - } - - private static void BuildLateExecuteList() - { - if (!_isLateExecuteListDirty) return; - _isLateExecuteListDirty = false; - _lateUpdateExecuteCount = 0; - foreach (var module in _lateUpdateModules) - { - if (_lateUpdateExecuteCount >= _lateUpdateExecuteArray.Length) break; - _lateUpdateExecuteArray[_lateUpdateExecuteCount++] = module; - } - } - - private static void BuildFixedExecuteList() - { - if (!_isFixedExecuteListDirty) return; - _isFixedExecuteListDirty = false; - _fixedUpdateExecuteCount = 0; - foreach (var module in _fixedUpdateModules) - { - if (_fixedUpdateExecuteCount >= _fixedUpdateExecuteArray.Length) break; - _fixedUpdateExecuteArray[_fixedUpdateExecuteCount++] = module; - } - } - - private static void BuildGizmosExecuteList() - { - if (!_isGizmosExecuteListDirty) return; - _isGizmosExecuteListDirty = false; - _gizmosExecuteCount = 0; - foreach (var module in _gizmosUpdateModules) - { - if (_gizmosExecuteCount >= _gizmosUpdateExecuteArray.Length) break; - _gizmosUpdateExecuteArray[_gizmosExecuteCount++] = module; - } - } - - private static void BuildGUIExecuteList() - { - if (!_isGUIExecuteListDirty) return; - _isGUIExecuteListDirty = false; - _guiExecuteCount = 0; - foreach (var module in _guiUpdateModules) - { - if (_guiExecuteCount >= _guiUpdateExecuteArray.Length) break; - _guiUpdateExecuteArray[_guiExecuteCount++] = module; - } - } - - #endregion - - #region RunExecuteList - - internal static void UpdateExecuteList(float elapseSeconds, float realElapseSeconds) - { - BuildExecuteList(); - for (int i = 0; i < _updateExecuteCount; i++) - { - _updateExecuteArray[i].Update(elapseSeconds, realElapseSeconds); - } - } - - internal static void UpdateLateExecuteList() - { - BuildLateExecuteList(); - for (int i = 0; i < _lateUpdateExecuteCount; i++) - { - _lateUpdateExecuteArray[i].LateUpdate(); - } - } - - internal static void UpdateFixedExecuteList() - { - BuildFixedExecuteList(); - for (int i = 0; i < _fixedUpdateExecuteCount; i++) - { - _fixedUpdateExecuteArray[i].FixedUpdate(); - } - } - - internal static void UpdateGizmosExecuteList() - { - BuildGizmosExecuteList(); - for (int i = 0; i < _gizmosExecuteCount; i++) - { - _gizmosUpdateExecuteArray[i].DrawGizmos(); - } - } - - internal static void UpdateGUIExecuteList() - { - BuildGUIExecuteList(); - for (int i = 0; i < _guiExecuteCount; i++) - { - _guiUpdateExecuteArray[i].OnGUI(); - } - } - - #endregion - } -} diff --git a/Runtime/ABase/Base/Module/ModuleSystem.cs.meta b/Runtime/ABase/Base/Module/ModuleSystem.cs.meta deleted file mode 100644 index 35bbf77..0000000 --- a/Runtime/ABase/Base/Module/ModuleSystem.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: b9fa1d3abb954b57989b94b4c77e45ce -timeCreated: 1736928479 \ No newline at end of file diff --git a/Runtime/ABase/Base/RootModule.cs b/Runtime/ABase/Base/RootModule.cs index 6c24d3c..103fa54 100644 --- a/Runtime/ABase/Base/RootModule.cs +++ b/Runtime/ABase/Base/RootModule.cs @@ -1,4 +1,4 @@ -using System; +using System; using AlicizaX.ObjectPool; using Cysharp.Threading.Tasks; using UnityEngine; @@ -10,7 +10,7 @@ namespace AlicizaX /// [DisallowMultipleComponent] [UnityEngine.Scripting.Preserve] - public sealed class RootModule : MonoBehaviour + public sealed class RootModule : AppServiceRoot { private static RootModule _instance = null; @@ -134,8 +134,9 @@ namespace AlicizaX /// /// 游戏框架组件初始化。 /// - private void Awake() + protected override void Awake() { + base.Awake(); _instance = this; DontDestroyOnLoad(this); Utility.Unity.MakeEntity(transform); @@ -166,7 +167,7 @@ namespace AlicizaX } - internal void Shutdown() + private void Shutdown() { Destroy(gameObject); Utility.Unity.Shutdown(); @@ -174,43 +175,11 @@ namespace AlicizaX Utility.Marshal.FreeCachedHGlobal(); } - private void Update() - { - ModuleSystem.UpdateExecuteList(Time.deltaTime, Time.unscaledDeltaTime); - } - - private void LateUpdate() - { - ModuleSystem.UpdateLateExecuteList(); - } - - private void FixedUpdate() - { - ModuleSystem.UpdateFixedExecuteList(); - } - - private void OnDrawGizmos() - { - ModuleSystem.UpdateGizmosExecuteList(); - } - - private void OnGUI() - { - ModuleSystem.UpdateGUIExecuteList(); - } - - private async void OnDestroy() - { - await UniTask.Yield(); - ModuleSystem.Dispose(); - } - - private void OnLowMemory() { Log.Warning("Low memory reported..."); - IObjectPoolModule objectPoolModule = ModuleSystem.GetModule(); + IObjectPoolService objectPoolModule = AppServices.Require(); if (objectPoolModule != null) { objectPoolModule.ReleaseAllUnused(); diff --git a/Runtime/ABase/Base/Service/Unity/AppServiceRoot.cs b/Runtime/ABase/Base/Service/Unity/AppServiceRoot.cs index d25897e..1f025e1 100644 --- a/Runtime/ABase/Base/Service/Unity/AppServiceRoot.cs +++ b/Runtime/ABase/Base/Service/Unity/AppServiceRoot.cs @@ -1,3 +1,4 @@ +using Cysharp.Threading.Tasks; using UnityEngine; namespace AlicizaX @@ -54,13 +55,17 @@ namespace AlicizaX if (AppServices.HasWorld) AppServices.World.DrawGizmos(); } - protected virtual void OnDestroy() + protected virtual async void OnDestroy() { if (s_activeRoot == this) s_activeRoot = null; if (_ownsWorld && AppServices.HasWorld) + { + await UniTask.Yield(); AppServices.Shutdown(); + } + } protected virtual void RegisterAppServices(ServiceScope appScope) { } diff --git a/Runtime/ABase/GameObjectPool/GameObjectPoolService.cs b/Runtime/ABase/GameObjectPool/GameObjectPoolManager.cs similarity index 96% rename from Runtime/ABase/GameObjectPool/GameObjectPoolService.cs rename to Runtime/ABase/GameObjectPool/GameObjectPoolManager.cs index 3f3ea2a..0b1081e 100644 --- a/Runtime/ABase/GameObjectPool/GameObjectPoolService.cs +++ b/Runtime/ABase/GameObjectPool/GameObjectPoolManager.cs @@ -7,7 +7,7 @@ using UnityEngine; namespace AlicizaX { - public sealed class GameObjectPool : MonoServiceBehaviour + public sealed class GameObjectPoolManager : MonoServiceBehaviour { private static readonly Comparison SnapshotComparer = (left, right) => { @@ -17,17 +17,14 @@ namespace AlicizaX int groupCompare = string.Compare(left.group, right.group, StringComparison.Ordinal); return groupCompare != 0 ? groupCompare : string.Compare(left.assetPath, right.assetPath, StringComparison.Ordinal); }; - [Header("检查间隔")] - public float checkInterval = 10f; - [Header("配置路径")] - public string poolConfigPath = "Assets/Bundles/Configs/PoolConfig"; + [Header("检查间隔")] public float checkInterval = 10f; - [Header("Inspector显示设置")] - public bool showDetailedInfo = true; + [Header("配置路径")] public string poolConfigPath = "Assets/Bundles/Configs/PoolConfig"; - [SerializeField] - internal Transform poolContainer; + [Header("Inspector显示设置")] public bool showDetailedInfo = true; + + [SerializeField] internal Transform poolContainer; private const PoolResourceLoaderType DefaultDirectLoadResourceLoaderType = PoolResourceLoaderType.AssetBundle; @@ -219,6 +216,7 @@ namespace AlicizaX pool.Shutdown(); MemoryPool.Release(pool); } + _isShuttingDown = false; _poolsByKey.Clear(); @@ -392,9 +390,8 @@ namespace AlicizaX _resolvedConfigCache.Clear(); _groupLoaderCache.Clear(); - IResourceModule resourceModule = ModuleSystem.GetModule(); - PoolConfigScriptableObject configAsset = - resourceModule.LoadAsset(poolConfigPath); + IResourceService resourceService = AppServices.Require(); + PoolConfigScriptableObject configAsset = resourceService.LoadAsset(poolConfigPath); if (configAsset == null || configAsset.configs == null) { @@ -431,7 +428,7 @@ namespace AlicizaX } } - resourceModule.UnloadAsset(configAsset); + resourceService.UnloadAsset(configAsset); } private async UniTask PrewarmConfiguredPoolsAsync(CancellationToken cancellationToken) diff --git a/Runtime/ABase/GameObjectPool/GameObjectPoolService.cs.meta b/Runtime/ABase/GameObjectPool/GameObjectPoolManager.cs.meta similarity index 100% rename from Runtime/ABase/GameObjectPool/GameObjectPoolService.cs.meta rename to Runtime/ABase/GameObjectPool/GameObjectPoolManager.cs.meta diff --git a/Runtime/ABase/GameObjectPool/IResourceLoader.cs b/Runtime/ABase/GameObjectPool/IResourceLoader.cs index 4b91a48..f4b2888 100644 --- a/Runtime/ABase/GameObjectPool/IResourceLoader.cs +++ b/Runtime/ABase/GameObjectPool/IResourceLoader.cs @@ -63,45 +63,45 @@ namespace AlicizaX public class AssetBundleResourceLoader : IResourceLoader { - private IResourceModule _resourceModule; + private IResourceService _resourceService; - IResourceModule ResourceModule + IResourceService ResourceService { get { - if (_resourceModule == null) + if (_resourceService == null) { - _resourceModule = ModuleSystem.GetModule(); + _resourceService = AppServices.Require(); } - return _resourceModule; + return _resourceService; } } public GameObject LoadPrefab(string location) { - return ResourceModule.LoadAsset(location); + return ResourceService.LoadAsset(location); } public async UniTask LoadPrefabAsync(string location, CancellationToken cancellationToken = default) { - return await ResourceModule.LoadAssetAsync(location, cancellationToken); + return await ResourceService.LoadAssetAsync(location, cancellationToken); } public GameObject LoadGameObject(string location, Transform parent = null) { - return ResourceModule.LoadGameObject(location, parent); + return ResourceService.LoadGameObject(location, parent); } public async UniTask LoadGameObjectAsync(string location, Transform parent = null, CancellationToken cancellationToken = default) { - return await ResourceModule.LoadGameObjectAsync(location, parent, cancellationToken); + return await ResourceService.LoadGameObjectAsync(location, parent, cancellationToken); } public void UnloadAsset(GameObject gameObject) { - ResourceModule.UnloadAsset(gameObject); + ResourceService.UnloadAsset(gameObject); } } } diff --git a/Runtime/ABase/GameObjectPool/RuntimePoolModels.cs b/Runtime/ABase/GameObjectPool/RuntimePoolModels.cs index d9c295b..47859a6 100644 --- a/Runtime/ABase/GameObjectPool/RuntimePoolModels.cs +++ b/Runtime/ABase/GameObjectPool/RuntimePoolModels.cs @@ -128,7 +128,7 @@ namespace AlicizaX private PoolConfig _config; private string _assetPath; private IResourceLoader _loader; - private GameObjectPool _service; + private GameObjectPoolManager _service; private CancellationToken _shutdownToken; private Dictionary _instancesByObject; private LinkedList _inactiveInstances; @@ -151,7 +151,7 @@ namespace AlicizaX PoolConfig config, string assetPath, IResourceLoader loader, - GameObjectPool service, + GameObjectPoolManager service, CancellationToken shutdownToken) { _config = config ?? throw new ArgumentNullException(nameof(config)); diff --git a/Runtime/ABase/ModuleDynamicBind.cs b/Runtime/ABase/ModuleDynamicBind.cs index 15c35da..d6f267a 100644 --- a/Runtime/ABase/ModuleDynamicBind.cs +++ b/Runtime/ABase/ModuleDynamicBind.cs @@ -3,21 +3,22 @@ using AlicizaX.Debugger.Runtime; using AlicizaX.Localization.Runtime; using AlicizaX.Resource.Runtime; using UnityEngine; +using UnityEngine.Serialization; namespace AlicizaX { public class ModuleDynamicBind : MonoBehaviour { - [SerializeField] private ResourceComponent _resourceComponent; - [SerializeField] private DebuggerComponent _debuggerComponent; - [SerializeField] private LocalizationComponent _localizationComponent; + [FormerlySerializedAs("_resourceServiceBehaviour")] [SerializeField] private ResourceComponent resourceComponent; + [FormerlySerializedAs("_debuggerServiceBehaviour")] [SerializeField] private DebuggerComponent debuggerComponent; + [FormerlySerializedAs("_localizationServiceBehaviour")] [SerializeField] private LocalizationComponent localizationComponent; private ModuleDynamicBindInfo _dynamicBindInfo; private void OnValidate() { - _resourceComponent = GetComponentInChildren(); - _debuggerComponent = GetComponentInChildren(); - _localizationComponent = GetComponentInChildren(); + resourceComponent = GetComponentInChildren(); + debuggerComponent = GetComponentInChildren(); + localizationComponent = GetComponentInChildren(); } private void Awake() @@ -26,20 +27,20 @@ namespace AlicizaX TextAsset text = Resources.Load("ModuleDynamicBindInfo"); _dynamicBindInfo = Utility.Json.ToObject(text.text); - if (_resourceComponent != null) + if (resourceComponent != null) { - _resourceComponent.SetPlayMode(_dynamicBindInfo.ResMode); - _resourceComponent.SetDecryptionServices(_dynamicBindInfo.DecryptionServices); + resourceComponent.SetPlayMode(_dynamicBindInfo.ResMode); + resourceComponent.SetDecryptionServices(_dynamicBindInfo.DecryptionServices); } - if (_debuggerComponent != null) + if (debuggerComponent != null) { - _debuggerComponent.SetActiveMode(_dynamicBindInfo.DebuggerActiveWindowType); + debuggerComponent.SetActiveMode(_dynamicBindInfo.DebuggerActiveWindowType); } - if (_localizationComponent != null) + if (localizationComponent != null) { - _localizationComponent.SetLanguage(_dynamicBindInfo.Language); + localizationComponent.SetLanguage(_dynamicBindInfo.Language); } } } diff --git a/Runtime/ABase/ObjectPool/IObjectPoolModule.cs b/Runtime/ABase/ObjectPool/IObjectPoolService.cs similarity index 99% rename from Runtime/ABase/ObjectPool/IObjectPoolModule.cs rename to Runtime/ABase/ObjectPool/IObjectPoolService.cs index 56c0432..369981a 100644 --- a/Runtime/ABase/ObjectPool/IObjectPoolModule.cs +++ b/Runtime/ABase/ObjectPool/IObjectPoolService.cs @@ -7,7 +7,7 @@ namespace AlicizaX.ObjectPool /// /// 对象池管理器。 /// - public interface IObjectPoolModule: IModule, IModuleUpdate + public interface IObjectPoolService : IService, IServiceTickable { /// /// 获取对象池数量。 diff --git a/Runtime/ABase/ObjectPool/IObjectPoolModule.cs.meta b/Runtime/ABase/ObjectPool/IObjectPoolService.cs.meta similarity index 100% rename from Runtime/ABase/ObjectPool/IObjectPoolModule.cs.meta rename to Runtime/ABase/ObjectPool/IObjectPoolService.cs.meta diff --git a/Runtime/ABase/ObjectPool/ObjectPoolComponent.cs b/Runtime/ABase/ObjectPool/ObjectPoolComponent.cs index 1e55b3c..c0978d7 100644 --- a/Runtime/ABase/ObjectPool/ObjectPoolComponent.cs +++ b/Runtime/ABase/ObjectPool/ObjectPoolComponent.cs @@ -8,24 +8,24 @@ namespace AlicizaX /// public sealed class ObjectPoolComponent : MonoBehaviour { - private IObjectPoolModule _mObjectPoolModule = null; + private IObjectPoolService _mObjectPoolService = null; /// /// 获取对象池数量。 /// public int Count { - get { return _mObjectPoolModule.Count; } + get { return _mObjectPoolService.Count; } } private void Awake() { - _mObjectPoolModule = ModuleSystem.RegisterModule(); + _mObjectPoolService = AppServices.GetOrCreateScope().Register(new ObjectPoolService()); } private void OnDestroy() { - _mObjectPoolModule = null; + _mObjectPoolService = null; } /// @@ -35,7 +35,7 @@ namespace AlicizaX /// 所有对象池。 public ObjectPoolBase[] GetAllObjectPools(bool sort) { - return _mObjectPoolModule.GetAllObjectPools(sort); + return _mObjectPoolService.GetAllObjectPools(sort); } } } diff --git a/Runtime/ABase/ObjectPool/ObjectPoolManager.Object.cs b/Runtime/ABase/ObjectPool/ObjectPoolService.Object.cs similarity index 98% rename from Runtime/ABase/ObjectPool/ObjectPoolManager.Object.cs rename to Runtime/ABase/ObjectPool/ObjectPoolService.Object.cs index c9a8933..6ef9130 100644 --- a/Runtime/ABase/ObjectPool/ObjectPoolManager.Object.cs +++ b/Runtime/ABase/ObjectPool/ObjectPoolService.Object.cs @@ -1,10 +1,10 @@ -using System; +using System; using System.Collections.Generic; using AlicizaX; namespace AlicizaX.ObjectPool { - internal sealed partial class ObjectPoolModule : IObjectPoolModule + internal sealed partial class ObjectPoolService : IObjectPoolService { /// /// 内部对象。 diff --git a/Runtime/ABase/ObjectPool/ObjectPoolManager.Object.cs.meta b/Runtime/ABase/ObjectPool/ObjectPoolService.Object.cs.meta similarity index 100% rename from Runtime/ABase/ObjectPool/ObjectPoolManager.Object.cs.meta rename to Runtime/ABase/ObjectPool/ObjectPoolService.Object.cs.meta diff --git a/Runtime/ABase/ObjectPool/ObjectPoolManager.ObjectPool.cs b/Runtime/ABase/ObjectPool/ObjectPoolService.ObjectPool.cs similarity index 99% rename from Runtime/ABase/ObjectPool/ObjectPoolManager.ObjectPool.cs rename to Runtime/ABase/ObjectPool/ObjectPoolService.ObjectPool.cs index 1c7dd19..ce1e227 100644 --- a/Runtime/ABase/ObjectPool/ObjectPoolManager.ObjectPool.cs +++ b/Runtime/ABase/ObjectPool/ObjectPoolService.ObjectPool.cs @@ -1,10 +1,10 @@ -using System; +using System; using System.Collections.Generic; using AlicizaX; namespace AlicizaX.ObjectPool { - internal sealed partial class ObjectPoolModule : IObjectPoolModule + internal sealed partial class ObjectPoolService : IObjectPoolService { /// /// 对象池。 diff --git a/Runtime/ABase/ObjectPool/ObjectPoolManager.ObjectPool.cs.meta b/Runtime/ABase/ObjectPool/ObjectPoolService.ObjectPool.cs.meta similarity index 100% rename from Runtime/ABase/ObjectPool/ObjectPoolManager.ObjectPool.cs.meta rename to Runtime/ABase/ObjectPool/ObjectPoolService.ObjectPool.cs.meta diff --git a/Runtime/ABase/ObjectPool/ObjectPoolModule.cs b/Runtime/ABase/ObjectPool/ObjectPoolService.cs similarity index 99% rename from Runtime/ABase/ObjectPool/ObjectPoolModule.cs rename to Runtime/ABase/ObjectPool/ObjectPoolService.cs index 399e6bf..26367e3 100644 --- a/Runtime/ABase/ObjectPool/ObjectPoolModule.cs +++ b/Runtime/ABase/ObjectPool/ObjectPoolService.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using AlicizaX; +using UnityEngine; namespace AlicizaX.ObjectPool { @@ -8,7 +9,7 @@ namespace AlicizaX.ObjectPool /// 对象池管理器。 /// [UnityEngine.Scripting.Preserve] - internal sealed partial class ObjectPoolModule : IObjectPoolModule + internal sealed partial class ObjectPoolService : ServiceBase, IObjectPoolService { private const int DefaultCapacity = int.MaxValue; private const float DefaultExpireTime = float.MaxValue; @@ -21,7 +22,7 @@ namespace AlicizaX.ObjectPool /// /// 初始化对象池管理器的新实例。 /// - public ObjectPoolModule() + public ObjectPoolService() { m_ObjectPools = new Dictionary(); m_CachedAllObjectPools = new List(); @@ -47,18 +48,20 @@ namespace AlicizaX.ObjectPool /// /// 逻辑流逝时间,以秒为单位。 /// 真实流逝时间,以秒为单位。 - void IModuleUpdate.Update(float elapseSeconds, float realElapseSeconds) + void IServiceTickable.Tick(float deltaTime) { foreach (KeyValuePair objectPool in m_ObjectPools) { - objectPool.Value.Update(elapseSeconds, realElapseSeconds); + objectPool.Value.Update(Time.deltaTime,Time.unscaledDeltaTime); } } /// /// 关闭并清理对象池管理器。 /// - void IModule.Dispose() + protected override void OnInitialize() { } + + protected override void OnDestroyService() { foreach (KeyValuePair objectPool in m_ObjectPools) { diff --git a/Runtime/ABase/ObjectPool/ObjectPoolModule.cs.meta b/Runtime/ABase/ObjectPool/ObjectPoolService.cs.meta similarity index 100% rename from Runtime/ABase/ObjectPool/ObjectPoolModule.cs.meta rename to Runtime/ABase/ObjectPool/ObjectPoolService.cs.meta diff --git a/Runtime/Audio/AudioAgent.cs b/Runtime/Audio/AudioAgent.cs index f53c018..6170895 100644 --- a/Runtime/Audio/AudioAgent.cs +++ b/Runtime/Audio/AudioAgent.cs @@ -1,4 +1,4 @@ -using AlicizaX.Resource.Runtime; +using AlicizaX.Resource.Runtime; using AlicizaX; using UnityEngine; using UnityEngine.Audio; @@ -14,8 +14,8 @@ namespace AlicizaX.Audio.Runtime private int _instanceId; private AudioSource _source; private AudioData _audioData; - private IAudioModule _audioModule; - private IResourceModule _resourceModule; + private IAudioService _audioService; + private IResourceService _resourceService; private Transform _transform; private float _volume = 1.0f; private float _duration; @@ -237,8 +237,8 @@ namespace AlicizaX.Audio.Runtime /// 音频代理辅助器编号。 public void Init(AudioCategory audioCategory, int index = 0) { - _audioModule = ModuleSystem.GetModule(); - _resourceModule = ModuleSystem.GetModule(); + _audioService = AppServices.Require(); + _resourceService = AppServices.Require(); GameObject host = new GameObject(Utility.Text.Format("Audio Agent Helper - {0} - {1}", audioCategory.AudioMixerGroup.name, index)); host.transform.SetParent(audioCategory.InstanceRoot); host.transform.localPosition = Vector3.zero; @@ -269,7 +269,7 @@ namespace AlicizaX.Audio.Runtime _duration = 0; if (!string.IsNullOrEmpty(path)) { - if (bInPool && _audioModule.AudioClipPool.TryGetValue(path, out var operationHandle)) + if (bInPool && _audioService.AudioClipPool.TryGetValue(path, out var operationHandle)) { OnAssetLoadComplete(operationHandle); return; @@ -278,12 +278,12 @@ namespace AlicizaX.Audio.Runtime if (bAsync) { _audioAgentRuntimeState = AudioAgentRuntimeState.Loading; - AssetHandle handle = _resourceModule.LoadAssetAsyncHandle(path); + AssetHandle handle = _resourceService.LoadAssetAsyncHandle(path); handle.Completed += OnAssetLoadComplete; } else { - AssetHandle handle = _resourceModule.LoadAssetSyncHandle(path); + AssetHandle handle = _resourceService.LoadAssetSyncHandle(path); OnAssetLoadComplete(handle); } } @@ -352,7 +352,7 @@ namespace AlicizaX.Audio.Runtime { if (_inPool) { - _audioModule.AudioClipPool.TryAdd(handle.GetAssetInfo().Address, handle); + _audioService.AudioClipPool.TryAdd(handle.GetAssetInfo().Address, handle); } } diff --git a/Runtime/Audio/AudioCategory.cs b/Runtime/Audio/AudioCategory.cs index 1afede2..0be4b1d 100644 --- a/Runtime/Audio/AudioCategory.cs +++ b/Runtime/Audio/AudioCategory.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using UnityEngine; using UnityEngine.Audio; @@ -72,7 +72,7 @@ namespace AlicizaX.Audio.Runtime /// 音频轨道组配置。 public AudioCategory(int maxChannel, AudioMixer audioMixer, AudioGroupConfig audioGroupConfig) { - var audioModule = ModuleSystem.GetModule(); + var audioModule = AppServices.Require(); this.audioMixer = audioMixer; _maxChannel = maxChannel; diff --git a/Runtime/Audio/AudioComponent.cs b/Runtime/Audio/AudioComponent.cs index 3a42305..f11741c 100644 --- a/Runtime/Audio/AudioComponent.cs +++ b/Runtime/Audio/AudioComponent.cs @@ -18,11 +18,11 @@ namespace AlicizaX.Audio.Runtime [SerializeField] private AudioGroupConfig[] m_AudioGroupConfigs = null; - private IAudioModule _audioModule; + private IAudioService _audioService; private void Awake() { - _audioModule = ModuleSystem.RegisterModule(); + _audioService = AppServices.GetOrCreateScope().Register(new AudioService()); } /// @@ -32,7 +32,7 @@ namespace AlicizaX.Audio.Runtime { if (m_InstanceRoot == null) { - m_InstanceRoot = new GameObject("[AudioModule Instances]").transform; + m_InstanceRoot = new GameObject("[AudioService Instances]").transform; m_InstanceRoot.SetParent(gameObject.transform); m_InstanceRoot.localScale = Vector3.one; } @@ -42,7 +42,7 @@ namespace AlicizaX.Audio.Runtime m_AudioMixer = Resources.Load("AudioMixer"); } - _audioModule.Initialize(m_AudioGroupConfigs, m_InstanceRoot, m_AudioMixer); + _audioService.Initialize(m_AudioGroupConfigs, m_InstanceRoot, m_AudioMixer); } } } diff --git a/Runtime/Audio/AudioModule.cs b/Runtime/Audio/AudioService.cs similarity index 96% rename from Runtime/Audio/AudioModule.cs rename to Runtime/Audio/AudioService.cs index d5fdbad..b7df2a4 100644 --- a/Runtime/Audio/AudioModule.cs +++ b/Runtime/Audio/AudioService.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Reflection; @@ -12,7 +12,7 @@ using AudioType = AlicizaX.Audio.Runtime.AudioType; namespace AlicizaX.Audio.Runtime { - internal class AudioModule : IAudioModule + internal class AudioService : ServiceBase, IAudioService { public const string MUSIC_VOLUME_NAME = "MusicVolume"; public const string UI_SOUND_VOLUME_NAME = "UISoundVolume"; @@ -321,10 +321,12 @@ namespace AlicizaX.Audio.Runtime #endregion - private IResourceModule _resourceModule; + private IResourceService _resourceService; - void IModule.Dispose() + protected override void OnInitialize() { } + + protected override void OnDestroyService() { StopAll(fadeout: false); CleanSoundPool(); @@ -339,7 +341,7 @@ namespace AlicizaX.Audio.Runtime /// public void Initialize(AudioGroupConfig[] audioGroupConfigs, Transform instanceRoot = null, AudioMixer audioMixer = null) { - _resourceModule = ModuleSystem.GetModule(); + _resourceService = AppServices.Require(); if (_instanceRoot == null) { _instanceRoot = instanceRoot; @@ -526,7 +528,7 @@ namespace AlicizaX.Audio.Runtime { if (AudioClipPool != null && !AudioClipPool.ContainsKey(path)) { - AssetHandle assetData = _resourceModule.LoadAssetAsyncHandle(path); + AssetHandle assetData = _resourceService.LoadAssetAsyncHandle(path); assetData.Completed += handle => { AudioClipPool?.Add(path, handle); }; } } @@ -576,18 +578,19 @@ namespace AlicizaX.Audio.Runtime /// /// 逻辑流逝时间,以秒为单位。 /// 真实流逝时间,以秒为单位。 - void IModuleUpdate.Update(float elapseSeconds, float realElapseSeconds) + void IServiceTickable.Tick(float deltaTime) { foreach (var audioCategory in _audioCategories) { if (audioCategory != null) { - audioCategory.Update(elapseSeconds); + audioCategory.Update(deltaTime); } } } public int Priority { get; } + } } diff --git a/Runtime/Audio/AudioModule.cs.meta b/Runtime/Audio/AudioService.cs.meta similarity index 100% rename from Runtime/Audio/AudioModule.cs.meta rename to Runtime/Audio/AudioService.cs.meta diff --git a/Runtime/Audio/IAudioModule.cs b/Runtime/Audio/IAudioService.cs similarity index 97% rename from Runtime/Audio/IAudioModule.cs rename to Runtime/Audio/IAudioService.cs index b46f74e..92fce10 100644 --- a/Runtime/Audio/IAudioModule.cs +++ b/Runtime/Audio/IAudioService.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using AlicizaX; using UnityEngine; using UnityEngine.Audio; @@ -6,7 +6,7 @@ using YooAsset; namespace AlicizaX.Audio.Runtime { - public interface IAudioModule:IModule,IModuleUpdate + public interface IAudioService:IService, IServiceTickable { /// /// 总音量控制。 diff --git a/Runtime/Audio/IAudioModule.cs.meta b/Runtime/Audio/IAudioService.cs.meta similarity index 100% rename from Runtime/Audio/IAudioModule.cs.meta rename to Runtime/Audio/IAudioService.cs.meta diff --git a/Runtime/Debugger/DebuggerComponent.ObjectPoolInformationWindow.cs b/Runtime/Debugger/DebuggerComponent.ObjectPoolInformationWindow.cs index 4345b9f..31f606a 100644 --- a/Runtime/Debugger/DebuggerComponent.ObjectPoolInformationWindow.cs +++ b/Runtime/Debugger/DebuggerComponent.ObjectPoolInformationWindow.cs @@ -1,4 +1,4 @@ -using AlicizaX.ObjectPool; +using AlicizaX.ObjectPool; using UnityEngine; namespace AlicizaX.Debugger.Runtime @@ -7,16 +7,11 @@ namespace AlicizaX.Debugger.Runtime { private sealed class ObjectPoolInformationWindow : ScrollableDebuggerWindowBase { - private IObjectPoolModule m_ObjectPoolComponent = null; + private IObjectPoolService m_ObjectPoolService = null; public override void Initialize(params object[] args) { - m_ObjectPoolComponent = ModuleSystem.GetModule(); - if (m_ObjectPoolComponent == null) - { - Log.Error("Object pool component is invalid."); - return; - } + m_ObjectPoolService = AppServices.Require(); } protected override void OnDrawScrollableWindow() @@ -24,10 +19,10 @@ namespace AlicizaX.Debugger.Runtime GUILayout.Label("Object Pool Information"); GUILayout.BeginVertical("box"); { - DrawItem("Object Pool Count", m_ObjectPoolComponent.Count.ToString()); + DrawItem("Object Pool Count", m_ObjectPoolService.Count.ToString()); } GUILayout.EndVertical(); - ObjectPoolBase[] objectPools = m_ObjectPoolComponent.GetAllObjectPools(true); + ObjectPoolBase[] objectPools = m_ObjectPoolService.GetAllObjectPools(true); for (int i = 0; i < objectPools.Length; i++) { DrawObjectPool(objectPools[i]); diff --git a/Runtime/Debugger/DebuggerComponent.OperationsWindow.cs b/Runtime/Debugger/DebuggerComponent.OperationsWindow.cs deleted file mode 100644 index 8cfdf15..0000000 --- a/Runtime/Debugger/DebuggerComponent.OperationsWindow.cs +++ /dev/null @@ -1,67 +0,0 @@ -// //------------------------------------------------------------ -// // Game Framework -// // Copyright © 2013-2021 Jiang Yin. All rights reserved. -// // Homepage: https://gameframework.cn/ -// // Feedback: mailto:ellan@gameframework.cn -// //------------------------------------------------------------ -// -// using GameFrameX.Runtime; -// using UnityEngine; -// -// namespace GameFrameX.Debugger.Runtime -// { -// public sealed partial class DebuggerComponent : GameFrameworkComponent -// { -// private sealed class OperationsWindow : ScrollableDebuggerWindowBase -// { -// protected override void OnDrawScrollableWindow() -// { -// GUILayout.Label("Operations"); -// GUILayout.BeginVertical("box"); -// { -// ObjectPoolComponent objectPoolComponent = GameEntry.GetComponent(); -// if (objectPoolComponent != null) -// { -// if (GUILayout.Button("Object Pool Release", GUILayout.Height(30f))) -// { -// objectPoolComponent.Release(); -// } -// -// if (GUILayout.Button("Object Pool Release All Unused", GUILayout.Height(30f))) -// { -// objectPoolComponent.ReleaseAllUnused(); -// } -// } -// -// ResourceComponent resourceCompoent = GameEntry.GetComponent(); -// if (resourceCompoent != null) -// { -// if (GUILayout.Button("Unload Unused Assets", GUILayout.Height(30f))) -// { -// resourceCompoent.ForceUnloadUnusedAssets(false); -// } -// -// if (GUILayout.Button("Unload Unused Assets and Garbage Collect", GUILayout.Height(30f))) -// { -// resourceCompoent.ForceUnloadUnusedAssets(true); -// } -// } -// -// if (GUILayout.Button("Shutdown Game Framework (None)", GUILayout.Height(30f))) -// { -// GameEntry.Shutdown(ShutdownType.None); -// } -// if (GUILayout.Button("Shutdown Game Framework (Restart)", GUILayout.Height(30f))) -// { -// GameEntry.Shutdown(ShutdownType.Restart); -// } -// if (GUILayout.Button("Shutdown Game Framework (Quit)", GUILayout.Height(30f))) -// { -// GameEntry.Shutdown(ShutdownType.Quit); -// } -// } -// GUILayout.EndVertical(); -// } -// } -// } -// } diff --git a/Runtime/Debugger/DebuggerComponent.OperationsWindow.cs.meta b/Runtime/Debugger/DebuggerComponent.OperationsWindow.cs.meta deleted file mode 100644 index ac4e910..0000000 --- a/Runtime/Debugger/DebuggerComponent.OperationsWindow.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: a695dd87b92d7374fbe3790f5a25e9d5 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Runtime/Debugger/DebuggerComponent.SettingsWindow.cs b/Runtime/Debugger/DebuggerComponent.SettingsWindow.cs index 677abb1..579349a 100644 --- a/Runtime/Debugger/DebuggerComponent.SettingsWindow.cs +++ b/Runtime/Debugger/DebuggerComponent.SettingsWindow.cs @@ -7,7 +7,7 @@ namespace AlicizaX.Debugger.Runtime { private sealed class SettingsWindow : ScrollableDebuggerWindowBase { - private DebuggerComponent m_DebuggerComponent = null; + private DebuggerComponent _mDebuggerComponent = null; private float m_LastIconX = 0f; private float m_LastIconY = 0f; private float m_LastWindowX = 0f; @@ -18,8 +18,8 @@ namespace AlicizaX.Debugger.Runtime public override void Initialize(params object[] args) { - m_DebuggerComponent = DebuggerComponent.Instance; - if (m_DebuggerComponent == null) + _mDebuggerComponent = DebuggerComponent.Instance; + if (_mDebuggerComponent == null) { Log.Error("Debugger component is invalid."); return; @@ -32,53 +32,53 @@ namespace AlicizaX.Debugger.Runtime m_LastWindowY = Utility.PlayerPrefsX.GetFloat("Debugger.Window.Y", DefaultWindowRect.y); m_LastWindowWidth = Utility.PlayerPrefsX.GetFloat("Debugger.Window.Width", DefaultWindowRect.width); m_LastWindowHeight = Utility.PlayerPrefsX.GetFloat("Debugger.Window.Height", DefaultWindowRect.height); - m_DebuggerComponent.WindowScale = m_LastWindowScale = Utility.PlayerPrefsX.GetFloat("Debugger.Window.Scale", DefaultWindowScale); - m_DebuggerComponent.IconRect = new Rect(m_LastIconX, m_LastIconY, DefaultIconRect.width, DefaultIconRect.height); - m_DebuggerComponent.WindowRect = new Rect(m_LastWindowX, m_LastWindowY, m_LastWindowWidth, m_LastWindowHeight); + _mDebuggerComponent.WindowScale = m_LastWindowScale = Utility.PlayerPrefsX.GetFloat("Debugger.Window.Scale", DefaultWindowScale); + _mDebuggerComponent.IconRect = new Rect(m_LastIconX, m_LastIconY, DefaultIconRect.width, DefaultIconRect.height); + _mDebuggerComponent.WindowRect = new Rect(m_LastWindowX, m_LastWindowY, m_LastWindowWidth, m_LastWindowHeight); } public override void OnUpdate(float elapseSeconds, float realElapseSeconds) { - if (m_LastIconX != m_DebuggerComponent.IconRect.x) + if (m_LastIconX != _mDebuggerComponent.IconRect.x) { - m_LastIconX = m_DebuggerComponent.IconRect.x; - Utility.PlayerPrefsX.SetFloat("Debugger.Icon.X", m_DebuggerComponent.IconRect.x); + m_LastIconX = _mDebuggerComponent.IconRect.x; + Utility.PlayerPrefsX.SetFloat("Debugger.Icon.X", _mDebuggerComponent.IconRect.x); } - if (m_LastIconY != m_DebuggerComponent.IconRect.y) + if (m_LastIconY != _mDebuggerComponent.IconRect.y) { - m_LastIconY = m_DebuggerComponent.IconRect.y; - Utility.PlayerPrefsX.SetFloat("Debugger.Icon.Y", m_DebuggerComponent.IconRect.y); + m_LastIconY = _mDebuggerComponent.IconRect.y; + Utility.PlayerPrefsX.SetFloat("Debugger.Icon.Y", _mDebuggerComponent.IconRect.y); } - if (m_LastWindowX != m_DebuggerComponent.WindowRect.x) + if (m_LastWindowX != _mDebuggerComponent.WindowRect.x) { - m_LastWindowX = m_DebuggerComponent.WindowRect.x; - Utility.PlayerPrefsX.SetFloat("Debugger.Window.X", m_DebuggerComponent.WindowRect.x); + m_LastWindowX = _mDebuggerComponent.WindowRect.x; + Utility.PlayerPrefsX.SetFloat("Debugger.Window.X", _mDebuggerComponent.WindowRect.x); } - if (m_LastWindowY != m_DebuggerComponent.WindowRect.y) + if (m_LastWindowY != _mDebuggerComponent.WindowRect.y) { - m_LastWindowY = m_DebuggerComponent.WindowRect.y; - Utility.PlayerPrefsX.SetFloat("Debugger.Window.Y", m_DebuggerComponent.WindowRect.y); + m_LastWindowY = _mDebuggerComponent.WindowRect.y; + Utility.PlayerPrefsX.SetFloat("Debugger.Window.Y", _mDebuggerComponent.WindowRect.y); } - if (m_LastWindowWidth != m_DebuggerComponent.WindowRect.width) + if (m_LastWindowWidth != _mDebuggerComponent.WindowRect.width) { - m_LastWindowWidth = m_DebuggerComponent.WindowRect.width; - Utility.PlayerPrefsX.SetFloat("Debugger.Window.Width", m_DebuggerComponent.WindowRect.width); + m_LastWindowWidth = _mDebuggerComponent.WindowRect.width; + Utility.PlayerPrefsX.SetFloat("Debugger.Window.Width", _mDebuggerComponent.WindowRect.width); } - if (m_LastWindowHeight != m_DebuggerComponent.WindowRect.height) + if (m_LastWindowHeight != _mDebuggerComponent.WindowRect.height) { - m_LastWindowHeight = m_DebuggerComponent.WindowRect.height; - Utility.PlayerPrefsX.SetFloat("Debugger.Window.Height", m_DebuggerComponent.WindowRect.height); + m_LastWindowHeight = _mDebuggerComponent.WindowRect.height; + Utility.PlayerPrefsX.SetFloat("Debugger.Window.Height", _mDebuggerComponent.WindowRect.height); } - if (m_LastWindowScale != m_DebuggerComponent.WindowScale) + if (m_LastWindowScale != _mDebuggerComponent.WindowScale) { - m_LastWindowScale = m_DebuggerComponent.WindowScale; - Utility.PlayerPrefsX.SetFloat("Debugger.Window.Scale", m_DebuggerComponent.WindowScale); + m_LastWindowScale = _mDebuggerComponent.WindowScale; + Utility.PlayerPrefsX.SetFloat("Debugger.Window.Scale", _mDebuggerComponent.WindowScale); } } @@ -96,7 +96,7 @@ namespace AlicizaX.Debugger.Runtime GUILayout.BeginHorizontal(); { - float width = m_DebuggerComponent.WindowRect.width; + float width = _mDebuggerComponent.WindowRect.width; GUILayout.Label("Width:", GUILayout.Width(60f)); if (GUILayout.RepeatButton("-", GUILayout.Width(30f))) { @@ -110,16 +110,16 @@ namespace AlicizaX.Debugger.Runtime } width = Mathf.Clamp(width, 100f, Screen.width - 20f); - if (width != m_DebuggerComponent.WindowRect.width) + if (width != _mDebuggerComponent.WindowRect.width) { - m_DebuggerComponent.WindowRect = new Rect(m_DebuggerComponent.WindowRect.x, m_DebuggerComponent.WindowRect.y, width, m_DebuggerComponent.WindowRect.height); + _mDebuggerComponent.WindowRect = new Rect(_mDebuggerComponent.WindowRect.x, _mDebuggerComponent.WindowRect.y, width, _mDebuggerComponent.WindowRect.height); } } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); { - float height = m_DebuggerComponent.WindowRect.height; + float height = _mDebuggerComponent.WindowRect.height; GUILayout.Label("Height:", GUILayout.Width(60f)); if (GUILayout.RepeatButton("-", GUILayout.Width(30f))) { @@ -133,16 +133,16 @@ namespace AlicizaX.Debugger.Runtime } height = Mathf.Clamp(height, 100f, Screen.height - 20f); - if (height != m_DebuggerComponent.WindowRect.height) + if (height != _mDebuggerComponent.WindowRect.height) { - m_DebuggerComponent.WindowRect = new Rect(m_DebuggerComponent.WindowRect.x, m_DebuggerComponent.WindowRect.y, m_DebuggerComponent.WindowRect.width, height); + _mDebuggerComponent.WindowRect = new Rect(_mDebuggerComponent.WindowRect.x, _mDebuggerComponent.WindowRect.y, _mDebuggerComponent.WindowRect.width, height); } } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); { - float scale = m_DebuggerComponent.WindowScale; + float scale = _mDebuggerComponent.WindowScale; GUILayout.Label("Scale:", GUILayout.Width(60f)); if (GUILayout.RepeatButton("-", GUILayout.Width(30f))) { @@ -156,9 +156,9 @@ namespace AlicizaX.Debugger.Runtime } scale = Mathf.Clamp(scale, 0.5f, 4f); - if (scale != m_DebuggerComponent.WindowScale) + if (scale != _mDebuggerComponent.WindowScale) { - m_DebuggerComponent.WindowScale = scale; + _mDebuggerComponent.WindowScale = scale; } } GUILayout.EndHorizontal(); @@ -167,49 +167,49 @@ namespace AlicizaX.Debugger.Runtime { if (GUILayout.Button("0.5x", GUILayout.Height(60f))) { - m_DebuggerComponent.WindowScale = 0.5f; + _mDebuggerComponent.WindowScale = 0.5f; } if (GUILayout.Button("1.0x", GUILayout.Height(60f))) { - m_DebuggerComponent.WindowScale = 1f; + _mDebuggerComponent.WindowScale = 1f; } if (GUILayout.Button("1.5x", GUILayout.Height(60f))) { - m_DebuggerComponent.WindowScale = 1.5f; + _mDebuggerComponent.WindowScale = 1.5f; } if (GUILayout.Button("2.0x", GUILayout.Height(60f))) { - m_DebuggerComponent.WindowScale = 2f; + _mDebuggerComponent.WindowScale = 2f; } if (GUILayout.Button("2.5x", GUILayout.Height(60f))) { - m_DebuggerComponent.WindowScale = 2.5f; + _mDebuggerComponent.WindowScale = 2.5f; } if (GUILayout.Button("3.0x", GUILayout.Height(60f))) { - m_DebuggerComponent.WindowScale = 3f; + _mDebuggerComponent.WindowScale = 3f; } if (GUILayout.Button("3.5x", GUILayout.Height(60f))) { - m_DebuggerComponent.WindowScale = 3.5f; + _mDebuggerComponent.WindowScale = 3.5f; } if (GUILayout.Button("4.0x", GUILayout.Height(60f))) { - m_DebuggerComponent.WindowScale = 4f; + _mDebuggerComponent.WindowScale = 4f; } } GUILayout.EndHorizontal(); if (GUILayout.Button("Reset Layout", GUILayout.Height(30f))) { - m_DebuggerComponent.ResetLayout(); + _mDebuggerComponent.ResetLayout(); } } GUILayout.EndVertical(); diff --git a/Runtime/Debugger/DebuggerComponent.cs b/Runtime/Debugger/DebuggerComponent.cs index 3e424f5..b1ee856 100644 --- a/Runtime/Debugger/DebuggerComponent.cs +++ b/Runtime/Debugger/DebuggerComponent.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using UnityEngine; using Object = UnityEngine.Object; @@ -43,7 +43,7 @@ namespace AlicizaX.Debugger.Runtime internal static readonly float DefaultWindowScale = 1f; // private static readonly TextEditor s_TextEditor = new TextEditor(); - private IDebuggerModule _mDebuggerModule = null; + private IDebuggerService _mDebuggerService = null; private Rect m_DragRect = new Rect(0f, 0f, float.MaxValue, 25f); private Rect m_IconRect = DefaultIconRect; private Rect m_WindowRect = DefaultWindowRect; @@ -99,10 +99,10 @@ namespace AlicizaX.Debugger.Runtime /// public bool ActiveWindow { - get { return _mDebuggerModule.ActiveWindow; } + get { return _mDebuggerService.ActiveWindow; } set { - _mDebuggerModule.ActiveWindow = value; + _mDebuggerService.ActiveWindow = value; enabled = value; } } @@ -149,8 +149,8 @@ namespace AlicizaX.Debugger.Runtime private void Awake() { _instance = this; - _mDebuggerModule = ModuleSystem.RegisterModule(); - if (_mDebuggerModule == null) + _mDebuggerService = AppServices.GetOrCreateScope().Register(new DebuggerService()); + if (_mDebuggerService == null) { Log.Error("Debugger manager is invalid."); return; @@ -231,7 +231,7 @@ namespace AlicizaX.Debugger.Runtime private void OnGUI() { - if (_mDebuggerModule == null || !_mDebuggerModule.ActiveWindow) + if (_mDebuggerService == null || !_mDebuggerService.ActiveWindow) { return; } @@ -263,7 +263,7 @@ namespace AlicizaX.Debugger.Runtime /// 初始化调试器窗口参数。 public void RegisterDebuggerWindow(string path, IDebuggerWindow debuggerWindow, params object[] args) { - _mDebuggerModule.RegisterDebuggerWindow(path, debuggerWindow, args); + _mDebuggerService.RegisterDebuggerWindow(path, debuggerWindow, args); } /// @@ -273,7 +273,7 @@ namespace AlicizaX.Debugger.Runtime /// 是否解除注册调试器窗口成功。 public bool UnregisterDebuggerWindow(string path) { - return _mDebuggerModule.UnregisterDebuggerWindow(path); + return _mDebuggerService.UnregisterDebuggerWindow(path); } /// @@ -283,7 +283,7 @@ namespace AlicizaX.Debugger.Runtime /// 要获取的调试器窗口。 public IDebuggerWindow GetDebuggerWindow(string path) { - return _mDebuggerModule.GetDebuggerWindow(path); + return _mDebuggerService.GetDebuggerWindow(path); } /// @@ -293,7 +293,7 @@ namespace AlicizaX.Debugger.Runtime /// 是否成功选中调试器窗口。 public bool SelectDebuggerWindow(string path) { - return _mDebuggerModule.SelectDebuggerWindow(path); + return _mDebuggerService.SelectDebuggerWindow(path); } /// @@ -328,7 +328,7 @@ namespace AlicizaX.Debugger.Runtime private void DrawWindow(int windowId) { GUI.DragWindow(m_DragRect); - DrawDebuggerWindowGroup(_mDebuggerModule.DebuggerWindowRoot); + DrawDebuggerWindowGroup(_mDebuggerService.DebuggerWindowRoot); } private void DrawDebuggerWindowGroup(IDebuggerWindowGroup debuggerWindowGroup) @@ -345,7 +345,7 @@ namespace AlicizaX.Debugger.Runtime names.Add(Utility.Text.Format("{0}", debuggerWindowNames[i])); } - if (debuggerWindowGroup == _mDebuggerModule.DebuggerWindowRoot) + if (debuggerWindowGroup == _mDebuggerService.DebuggerWindowRoot) { names.Add("Close"); } diff --git a/Runtime/Debugger/DebuggerManager.DebuggerWindowGroup.cs b/Runtime/Debugger/DebuggerService.DebuggerWindowGroup.cs similarity index 99% rename from Runtime/Debugger/DebuggerManager.DebuggerWindowGroup.cs rename to Runtime/Debugger/DebuggerService.DebuggerWindowGroup.cs index 673a1bc..ca37981 100644 --- a/Runtime/Debugger/DebuggerManager.DebuggerWindowGroup.cs +++ b/Runtime/Debugger/DebuggerService.DebuggerWindowGroup.cs @@ -1,9 +1,9 @@ -using System.Collections.Generic; +using System.Collections.Generic; using AlicizaX; namespace AlicizaX.Debugger.Runtime { - internal sealed partial class DebuggerModule : IDebuggerModule + internal sealed partial class DebuggerService : IDebuggerService { /// /// 调试器窗口组。 diff --git a/Runtime/Debugger/DebuggerManager.DebuggerWindowGroup.cs.meta b/Runtime/Debugger/DebuggerService.DebuggerWindowGroup.cs.meta similarity index 100% rename from Runtime/Debugger/DebuggerManager.DebuggerWindowGroup.cs.meta rename to Runtime/Debugger/DebuggerService.DebuggerWindowGroup.cs.meta diff --git a/Runtime/Debugger/DebuggerModule.cs b/Runtime/Debugger/DebuggerService.cs similarity index 90% rename from Runtime/Debugger/DebuggerModule.cs rename to Runtime/Debugger/DebuggerService.cs index 2c1a94f..a9fd2a7 100644 --- a/Runtime/Debugger/DebuggerModule.cs +++ b/Runtime/Debugger/DebuggerService.cs @@ -1,4 +1,5 @@ using AlicizaX; +using UnityEngine; namespace AlicizaX.Debugger.Runtime { @@ -6,7 +7,7 @@ namespace AlicizaX.Debugger.Runtime /// 调试器管理器。 /// [UnityEngine.Scripting.Preserve] - internal sealed partial class DebuggerModule : IDebuggerModule + internal sealed partial class DebuggerService : ServiceBase, IDebuggerService { private readonly DebuggerWindowGroup m_DebuggerWindowRoot; private bool m_ActiveWindow; @@ -15,7 +16,7 @@ namespace AlicizaX.Debugger.Runtime /// 初始化调试器管理器的新实例。 /// [UnityEngine.Scripting.Preserve] - public DebuggerModule() + public DebuggerService() { m_DebuggerWindowRoot = new DebuggerWindowGroup(); m_ActiveWindow = false; @@ -48,20 +49,22 @@ namespace AlicizaX.Debugger.Runtime /// /// 逻辑流逝时间,以秒为单位。 /// 真实流逝时间,以秒为单位。 - void IModuleUpdate.Update(float elapseSeconds, float realElapseSeconds) + void IServiceTickable.Tick(float deltaTime) { if (!m_ActiveWindow) { return; } - m_DebuggerWindowRoot.OnUpdate(elapseSeconds, realElapseSeconds); + m_DebuggerWindowRoot.OnUpdate(Time.deltaTime,Time.realtimeSinceStartup); } /// /// 关闭并清理调试器管理器。 /// - void IModule.Dispose() + protected override void OnInitialize() { } + + protected override void OnDestroyService() { m_ActiveWindow = false; m_DebuggerWindowRoot.Shutdown(); diff --git a/Runtime/Debugger/DebuggerModule.cs.meta b/Runtime/Debugger/DebuggerService.cs.meta similarity index 100% rename from Runtime/Debugger/DebuggerModule.cs.meta rename to Runtime/Debugger/DebuggerService.cs.meta diff --git a/Runtime/Debugger/IDebuggerModule.cs b/Runtime/Debugger/IDebuggerService.cs similarity index 95% rename from Runtime/Debugger/IDebuggerModule.cs rename to Runtime/Debugger/IDebuggerService.cs index 9852d47..1bbd262 100644 --- a/Runtime/Debugger/IDebuggerModule.cs +++ b/Runtime/Debugger/IDebuggerService.cs @@ -1,4 +1,4 @@ - + using AlicizaX; @@ -6,7 +6,7 @@ using AlicizaX; namespace AlicizaX.Debugger.Runtime { /// 调试器管理器接口。 - public interface IDebuggerModule:IModule,IModuleUpdate + public interface IDebuggerService:IService, IServiceTickable { /// 获取或设置调试器窗口是否激活。 bool ActiveWindow { get; set; } diff --git a/Runtime/Debugger/IDebuggerModule.cs.meta b/Runtime/Debugger/IDebuggerService.cs.meta similarity index 100% rename from Runtime/Debugger/IDebuggerModule.cs.meta rename to Runtime/Debugger/IDebuggerService.cs.meta diff --git a/Runtime/GameApp.cs b/Runtime/GameApp.cs new file mode 100644 index 0000000..bea9658 --- /dev/null +++ b/Runtime/GameApp.cs @@ -0,0 +1,164 @@ +using AlicizaX; +using AlicizaX.Audio.Runtime; +using AlicizaX.Localization.Runtime; +using AlicizaX.ObjectPool; +using AlicizaX.Resource.Runtime; +using AlicizaX.Scene.Runtime; +using AlicizaX.UI.Runtime; + +public static partial class GameApp +{ + /// + /// 获取游戏基础组件。 + /// + public static RootModule Base => RootModule.Instance; + + + /// + /// 获取声音组件。 + /// + public static IAudioService Audio + { + get + { + if (_audio == null) + { + _audio = AppServices.App.Require(); + } + + return _audio; + } + } + + private static IAudioService _audio; + + + /// + /// 获取本地化组件。 + /// + public static ILocalizationService Localization + { + get + { + if (_localization == null) + { + _localization = AppServices.App.Require(); + } + + return _localization; + } + } + + private static ILocalizationService _localization; + + /// + /// 获取对象池组件。 + /// + public static IObjectPoolService ObjectPool + { + get + { + if (_objectPool == null) + { + _objectPool = AppServices.App.Require(); + } + + return _objectPool; + } + } + + private static IObjectPoolService _objectPool; + + + /// + /// 获取有限状态机组件。 + /// + public static IProcedureService Procedure + { + get + { + if (_procedure == null) + { + _procedure = AppServices.App.Require(); + } + + return _procedure; + } + } + + private static IProcedureService _procedure; + + + /// + /// 获取Asset组件。 + /// + public static IResourceService Resource + { + get + { + if (_resource == null) + { + _resource = AppServices.App.Require(); + } + + return _resource; + } + } + + private static IResourceService _resource; + + /// + /// 获取场景组件。 + /// + public static ISceneService Scene + { + get + { + if (_scene == null) + { + _scene = AppServices.App.Require(); + } + + return _scene; + } + } + + private static ISceneService _scene; + + /// + /// 获取定时器组件。 + /// + public static ITimerService Timer + { + get + { + if (_timer == null) + { + _timer = AppServices.App.Require(); + } + + return _timer; + } + } + + private static ITimerService _timer; + + + /// + /// 获取UI组件。 + /// + public static IUIService UI + { + get + { + if (_ui == null) + { + _ui = AppServices.App.Require(); + } + + return _ui; + } + } + + private static IUIService _ui; +} diff --git a/Runtime/GameApp/GameApp.cs.meta b/Runtime/GameApp.cs.meta similarity index 100% rename from Runtime/GameApp/GameApp.cs.meta rename to Runtime/GameApp.cs.meta diff --git a/Runtime/GameApp.meta b/Runtime/GameApp.meta deleted file mode 100644 index c4cc15d..0000000 --- a/Runtime/GameApp.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: f06920c335296ea4694dab52e8bd493a -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Runtime/GameApp/GameApp.Audio.cs b/Runtime/GameApp/GameApp.Audio.cs deleted file mode 100644 index 5489a6a..0000000 --- a/Runtime/GameApp/GameApp.Audio.cs +++ /dev/null @@ -1,23 +0,0 @@ -using AlicizaX; -using AlicizaX.Audio.Runtime; - -public static partial class GameApp -{ - /// - /// 获取声音组件。 - /// - public static IAudioModule Audio - { - get - { - if (_audio == null) - { - _audio = ModuleSystem.GetModule(); - } - - return _audio; - } - } - - internal static IAudioModule _audio; -} diff --git a/Runtime/GameApp/GameApp.Audio.cs.meta b/Runtime/GameApp/GameApp.Audio.cs.meta deleted file mode 100644 index 56904ef..0000000 --- a/Runtime/GameApp/GameApp.Audio.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 3e9812a7462843d48a0660209e7bf8aa -timeCreated: 1737440423 \ No newline at end of file diff --git a/Runtime/GameApp/GameApp.Localization.cs b/Runtime/GameApp/GameApp.Localization.cs deleted file mode 100644 index f21866b..0000000 --- a/Runtime/GameApp/GameApp.Localization.cs +++ /dev/null @@ -1,23 +0,0 @@ -using AlicizaX.Localization.Runtime; -using AlicizaX; - -public static partial class GameApp -{ - /// - /// 获取本地化组件。 - /// - public static ILocalizationModule Localization - { - get - { - if (_localization == null) - { - _localization = ModuleSystem.GetModule(); - } - - return _localization; - } - } - - internal static ILocalizationModule _localization; -} diff --git a/Runtime/GameApp/GameApp.Localization.cs.meta b/Runtime/GameApp/GameApp.Localization.cs.meta deleted file mode 100644 index 015bd9a..0000000 --- a/Runtime/GameApp/GameApp.Localization.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: a8c610d4005146509b2dd9a685bb15af -timeCreated: 1737440423 \ No newline at end of file diff --git a/Runtime/GameApp/GameApp.ObjectPool.cs b/Runtime/GameApp/GameApp.ObjectPool.cs deleted file mode 100644 index 7591f2a..0000000 --- a/Runtime/GameApp/GameApp.ObjectPool.cs +++ /dev/null @@ -1,23 +0,0 @@ -using AlicizaX.ObjectPool; -using AlicizaX; - -public static partial class GameApp -{ - /// - /// 获取对象池组件。 - /// - public static IObjectPoolModule ObjectPool - { - get - { - if (_objectPool == null) - { - _objectPool = ModuleSystem.GetModule(); - } - - return _objectPool; - } - } - - internal static IObjectPoolModule _objectPool; -} diff --git a/Runtime/GameApp/GameApp.ObjectPool.cs.meta b/Runtime/GameApp/GameApp.ObjectPool.cs.meta deleted file mode 100644 index 39a6f19..0000000 --- a/Runtime/GameApp/GameApp.ObjectPool.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 10a6970b6ffc472d801816ffbdf8f1e1 -timeCreated: 1737440423 \ No newline at end of file diff --git a/Runtime/GameApp/GameApp.Procedure.cs b/Runtime/GameApp/GameApp.Procedure.cs deleted file mode 100644 index c638a01..0000000 --- a/Runtime/GameApp/GameApp.Procedure.cs +++ /dev/null @@ -1,22 +0,0 @@ -using AlicizaX; - -public static partial class GameApp -{ - /// - /// 获取有限状态机组件。 - /// - public static IProcedureModule Procedure - { - get - { - if (_procedure == null) - { - _procedure = ModuleSystem.GetModule(); - } - - return _procedure; - } - } - - internal static IProcedureModule _procedure; -} diff --git a/Runtime/GameApp/GameApp.Procedure.cs.meta b/Runtime/GameApp/GameApp.Procedure.cs.meta deleted file mode 100644 index 46135e8..0000000 --- a/Runtime/GameApp/GameApp.Procedure.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 577055df4d464c3999cdd432e009000e -timeCreated: 1763452169 \ No newline at end of file diff --git a/Runtime/GameApp/GameApp.Resource.cs b/Runtime/GameApp/GameApp.Resource.cs deleted file mode 100644 index 938f40e..0000000 --- a/Runtime/GameApp/GameApp.Resource.cs +++ /dev/null @@ -1,23 +0,0 @@ -using AlicizaX.Resource.Runtime; -using AlicizaX; - -public static partial class GameApp -{ - /// - /// 获取Asset组件。 - /// - public static IResourceModule Resource - { - get - { - if (_resource == null) - { - _resource = ModuleSystem.GetModule(); - } - - return _resource; - } - } - - internal static IResourceModule _resource; -} diff --git a/Runtime/GameApp/GameApp.Resource.cs.meta b/Runtime/GameApp/GameApp.Resource.cs.meta deleted file mode 100644 index 7a0810c..0000000 --- a/Runtime/GameApp/GameApp.Resource.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: ba1f965b36d44ae2ac5820bc7fbb64ac -timeCreated: 1737440423 \ No newline at end of file diff --git a/Runtime/GameApp/GameApp.Scene.cs b/Runtime/GameApp/GameApp.Scene.cs deleted file mode 100644 index f577b1c..0000000 --- a/Runtime/GameApp/GameApp.Scene.cs +++ /dev/null @@ -1,23 +0,0 @@ -using AlicizaX; -using AlicizaX.Scene.Runtime; - -public static partial class GameApp -{ - /// - /// 获取场景组件。 - /// - public static ISceneModule Scene - { - get - { - if (_scene == null) - { - _scene = ModuleSystem.GetModule(); - } - - return _scene; - } - } - - internal static ISceneModule _scene; -} diff --git a/Runtime/GameApp/GameApp.Scene.cs.meta b/Runtime/GameApp/GameApp.Scene.cs.meta deleted file mode 100644 index 6db3043..0000000 --- a/Runtime/GameApp/GameApp.Scene.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 214b27a946ff481fb669e0cf645398ee -timeCreated: 1737440423 \ No newline at end of file diff --git a/Runtime/GameApp/GameApp.Timer.cs b/Runtime/GameApp/GameApp.Timer.cs deleted file mode 100644 index 256fbdf..0000000 --- a/Runtime/GameApp/GameApp.Timer.cs +++ /dev/null @@ -1,23 +0,0 @@ -using AlicizaX; -using AlicizaX.Timer.Runtime; - -public static partial class GameApp -{ - /// - /// 获取定时器组件。 - /// - public static ITimerModule Timer - { - get - { - if (_timer == null) - { - _timer = ModuleSystem.GetModule(); - } - - return _timer; - } - } - - internal static ITimerModule _timer; -} diff --git a/Runtime/GameApp/GameApp.Timer.cs.meta b/Runtime/GameApp/GameApp.Timer.cs.meta deleted file mode 100644 index dea2606..0000000 --- a/Runtime/GameApp/GameApp.Timer.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 669e997f79b44a11bf93c9da9af48397 -timeCreated: 1737440423 \ No newline at end of file diff --git a/Runtime/GameApp/GameApp.UI.cs b/Runtime/GameApp/GameApp.UI.cs deleted file mode 100644 index f051607..0000000 --- a/Runtime/GameApp/GameApp.UI.cs +++ /dev/null @@ -1,23 +0,0 @@ -using AlicizaX; -using AlicizaX.UI.Runtime; - -public static partial class GameApp -{ - /// - /// 获取UI组件。 - /// - public static IUIModule UI - { - get - { - if (_ui == null) - { - _ui = ModuleSystem.GetModule(); - } - - return _ui; - } - } - - internal static IUIModule _ui; -} diff --git a/Runtime/GameApp/GameApp.UI.cs.meta b/Runtime/GameApp/GameApp.UI.cs.meta deleted file mode 100644 index 67e65dc..0000000 --- a/Runtime/GameApp/GameApp.UI.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 198f337af87540e2be6fe76fa1abec0f -timeCreated: 1737440423 \ No newline at end of file diff --git a/Runtime/GameApp/GameApp.cs b/Runtime/GameApp/GameApp.cs deleted file mode 100644 index 7fb2f45..0000000 --- a/Runtime/GameApp/GameApp.cs +++ /dev/null @@ -1,22 +0,0 @@ -using AlicizaX; - -public static partial class GameApp -{ - /// - /// 获取游戏基础组件。 - /// - public static RootModule Base - { - get - { - if (_base == null) - { - _base = RootModule.Instance; - } - - return _base; - } - } - - internal static RootModule _base; -} diff --git a/Runtime/GameApp/GameAppStaticMemberReset.cs b/Runtime/GameApp/GameAppStaticMemberReset.cs deleted file mode 100644 index 378776e..0000000 --- a/Runtime/GameApp/GameAppStaticMemberReset.cs +++ /dev/null @@ -1,24 +0,0 @@ -#if UNITY_EDITOR -using UnityEditor; - -internal static class GameAppStaticMemberReset -{ - [UnityEditor.Callbacks.DidReloadScripts] - private static void ResetAllEventContainers() - { - GameApp._base = null; - GameApp._audio = null; - GameApp._localization = null; - -#if ALICIZAX_NETWORK - GameApp._network = null; -#endif - GameApp._objectPool = null; - GameApp._resource = null; - GameApp._scene = null; - GameApp._timer = null; - GameApp._ui = null; - } -} - -#endif diff --git a/Runtime/GameApp/GameAppStaticMemberReset.cs.meta b/Runtime/GameApp/GameAppStaticMemberReset.cs.meta deleted file mode 100644 index 0c1eecb..0000000 --- a/Runtime/GameApp/GameAppStaticMemberReset.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: a0120d62fb8349d58e950bdaa50145e4 -timeCreated: 1743593118 \ No newline at end of file diff --git a/Runtime/Localization/LocalizationComponent.cs b/Runtime/Localization/LocalizationComponent.cs index 28c47f7..d460950 100644 --- a/Runtime/Localization/LocalizationComponent.cs +++ b/Runtime/Localization/LocalizationComponent.cs @@ -9,7 +9,7 @@ namespace AlicizaX.Localization.Runtime [AddComponentMenu("Game Framework/Localization")] public sealed class LocalizationComponent : MonoBehaviour { - private ILocalizationModule _mLocalizationModule = null; + private ILocalizationService _mLocalizationService = null; public static string PrefsKey = Application.dataPath.GetHashCode() + "Language"; @@ -22,15 +22,15 @@ namespace AlicizaX.Localization.Runtime private void Start() { - _mLocalizationModule = ModuleSystem.RegisterModule(); - if (_mLocalizationModule == null) + _mLocalizationService = AppServices.GetOrCreateScope().Register(new LocalizationService()); + if (_mLocalizationService == null) { Log.Info("Localization manager is invalid."); } #if UNITY_EDITOR _language = UnityEditor.EditorPrefs.GetString(LocalizationComponent.PrefsKey, "None"); #endif - _mLocalizationModule.Initialize(_language); + _mLocalizationService.Initialize(_language); } } } diff --git a/Runtime/Localization/Manager.meta b/Runtime/Localization/Service.meta similarity index 100% rename from Runtime/Localization/Manager.meta rename to Runtime/Localization/Service.meta diff --git a/Runtime/Localization/Manager/ILocalizationModule.cs b/Runtime/Localization/Service/ILocalizationService.cs similarity index 99% rename from Runtime/Localization/Manager/ILocalizationModule.cs rename to Runtime/Localization/Service/ILocalizationService.cs index 38ced9d..489ba61 100644 --- a/Runtime/Localization/Manager/ILocalizationModule.cs +++ b/Runtime/Localization/Service/ILocalizationService.cs @@ -6,7 +6,7 @@ namespace AlicizaX.Localization.Runtime /// /// 本地化管理器接口。 /// - public interface ILocalizationModule : IModule + public interface ILocalizationService : IService { public string Language { get; } diff --git a/Runtime/Localization/Manager/ILocalizationModule.cs.meta b/Runtime/Localization/Service/ILocalizationService.cs.meta similarity index 100% rename from Runtime/Localization/Manager/ILocalizationModule.cs.meta rename to Runtime/Localization/Service/ILocalizationService.cs.meta diff --git a/Runtime/Localization/Manager/LocalizationModule.cs b/Runtime/Localization/Service/LocalizationService.cs similarity index 99% rename from Runtime/Localization/Manager/LocalizationModule.cs rename to Runtime/Localization/Service/LocalizationService.cs index c307caf..328e5d4 100644 --- a/Runtime/Localization/Manager/LocalizationModule.cs +++ b/Runtime/Localization/Service/LocalizationService.cs @@ -8,7 +8,7 @@ namespace AlicizaX.Localization.Runtime /// 本地化管理器。 /// [UnityEngine.Scripting.Preserve] - internal sealed partial class LocalizationModule : ILocalizationModule + internal sealed partial class LocalizationService : ServiceBase, ILocalizationService { private readonly Dictionary Dic = new(); private string _language; @@ -749,7 +749,9 @@ namespace AlicizaX.Localization.Runtime } } - void IModule.Dispose() + protected override void OnInitialize() { } + + protected override void OnDestroyService() { Dic.Clear(); } diff --git a/Runtime/Localization/Manager/LocalizationModule.cs.meta b/Runtime/Localization/Service/LocalizationService.cs.meta similarity index 100% rename from Runtime/Localization/Manager/LocalizationModule.cs.meta rename to Runtime/Localization/Service/LocalizationService.cs.meta diff --git a/Runtime/Procedure/IProcedureModule.cs b/Runtime/Procedure/IProcedureService.cs similarity index 83% rename from Runtime/Procedure/IProcedureModule.cs rename to Runtime/Procedure/IProcedureService.cs index f7be84e..41bce6f 100644 --- a/Runtime/Procedure/IProcedureModule.cs +++ b/Runtime/Procedure/IProcedureService.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; namespace AlicizaX { - public interface IProcedureModule:IModule,IModuleUpdate + public interface IProcedureService:IService, IServiceTickable { void InitializeProcedure(List availableProcedures, Type defaultProcedureType); void ClearAllProcedures(); diff --git a/Runtime/Procedure/IProcedureModule.cs.meta b/Runtime/Procedure/IProcedureService.cs.meta similarity index 100% rename from Runtime/Procedure/IProcedureModule.cs.meta rename to Runtime/Procedure/IProcedureService.cs.meta diff --git a/Runtime/Procedure/ProcedureBase.cs b/Runtime/Procedure/ProcedureBase.cs index 06bc46a..43ef003 100644 --- a/Runtime/Procedure/ProcedureBase.cs +++ b/Runtime/Procedure/ProcedureBase.cs @@ -2,7 +2,7 @@ namespace AlicizaX { public interface IProcedure { - IProcedureModule ProcedureModule { get; set; } + IProcedureService ProcedureService { get; set; } void Init(); void Enter(); void Leave(); @@ -15,7 +15,7 @@ namespace AlicizaX /// public abstract class ProcedureBase : IProcedure { - public IProcedureModule ProcedureModule { get; set; } + public IProcedureService ProcedureService { get; set; } void IProcedure.Init() { @@ -66,7 +66,7 @@ namespace AlicizaX protected internal void SwitchProcedure() where T : ProcedureBase { - ProcedureModule.SwitchProcedure(); + AppServices.Require().SwitchProcedure(); } } } diff --git a/Runtime/Procedure/ProcedureComponent.cs b/Runtime/Procedure/ProcedureComponent.cs index 2576f96..a29d8f5 100644 --- a/Runtime/Procedure/ProcedureComponent.cs +++ b/Runtime/Procedure/ProcedureComponent.cs @@ -6,11 +6,9 @@ namespace AlicizaX [AddComponentMenu("Game Framework/Procedure")] public sealed class ProcedureComponent : MonoBehaviour { - private IProcedureModule _mProcedureModule = null; - private void Awake() { - _mProcedureModule = ModuleSystem.RegisterModule(); + AppServices.GetOrCreateScope().Register(new ProcedureService()); } } } diff --git a/Runtime/Procedure/ProcedureModule.cs b/Runtime/Procedure/ProcedureService.cs similarity index 91% rename from Runtime/Procedure/ProcedureModule.cs rename to Runtime/Procedure/ProcedureService.cs index 695e698..ac54342 100644 --- a/Runtime/Procedure/ProcedureModule.cs +++ b/Runtime/Procedure/ProcedureService.cs @@ -4,7 +4,7 @@ using UnityEngine; namespace AlicizaX { - internal class ProcedureModule : IProcedureModule + internal class ProcedureService : ServiceBase, IProcedureService { private readonly Dictionary _procedures = new Dictionary(); private IProcedure _currentProcedure; @@ -18,7 +18,7 @@ namespace AlicizaX { var type = procedure.GetType(); _procedures[type] = procedure; - procedure.ProcedureModule = this; + procedure.ProcedureService = this; procedure.Init(); } @@ -114,14 +114,17 @@ namespace AlicizaX } - void IModule.Dispose() + protected override void OnInitialize() + { + + } + + protected override void OnDestroyService() { ClearAllProcedures(); } - public int Priority { get; } - - void IModuleUpdate.Update(float elapseSeconds, float realElapseSeconds) + void IServiceTickable.Tick(float deltaTime) { if (_currentProcedure != null) { diff --git a/Runtime/Procedure/ProcedureModule.cs.meta b/Runtime/Procedure/ProcedureService.cs.meta similarity index 100% rename from Runtime/Procedure/ProcedureModule.cs.meta rename to Runtime/Procedure/ProcedureService.cs.meta diff --git a/Runtime/Resource/Resource/Extension/AssetItemObject.cs b/Runtime/Resource/Resource/Extension/AssetItemObject.cs index 2b3bd16..fb38326 100644 --- a/Runtime/Resource/Resource/Extension/AssetItemObject.cs +++ b/Runtime/Resource/Resource/Extension/AssetItemObject.cs @@ -20,7 +20,7 @@ namespace AlicizaX.Resource.Runtime return; } - ModuleSystem.GetModule().UnloadAsset(Target); + AppServices.Require().UnloadAsset(Target); } } } diff --git a/Runtime/Resource/Resource/Extension/ResourceExtComponent.Resource.cs b/Runtime/Resource/Resource/Extension/ResourceExtComponent.Resource.cs index 32eba83..fcac2ea 100644 --- a/Runtime/Resource/Resource/Extension/ResourceExtComponent.Resource.cs +++ b/Runtime/Resource/Resource/Extension/ResourceExtComponent.Resource.cs @@ -7,9 +7,9 @@ namespace AlicizaX.Resource.Runtime { public partial class ResourceExtComponent { - private static IResourceModule _resourceModule; + private static IResourceService _resourceService; - public static IResourceModule ResourceModule => _resourceModule; + public static IResourceService ResourceService => _resourceService; private class LoadingState : IMemory { @@ -37,7 +37,7 @@ namespace AlicizaX.Resource.Runtime private void InitializedResources() { - _resourceModule = ModuleSystem.GetModule(); + _resourceService = AppServices.Require(); } private void OnLoadAssetSuccess(string assetName, object asset, float duration, object userdata) @@ -62,7 +62,7 @@ namespace AlicizaX.Resource.Runtime } else { - _resourceModule.UnloadAsset(assetObject); + _resourceService.UnloadAsset(assetObject); } } @@ -113,7 +113,7 @@ namespace AlicizaX.Resource.Runtime return; } - T resource = await _resourceModule.LoadAssetAsync(location, linkedTokenSource.Token); + T resource = await _resourceService.LoadAssetAsync(location, linkedTokenSource.Token); if (resource == null) { ClearLoadingState(target); @@ -166,7 +166,7 @@ namespace AlicizaX.Resource.Runtime if (_assetItemPool.CanSpawn(location)) { var cachedAsset = _assetItemPool.Spawn(location).Target as UnityEngine.Object; - _resourceModule.UnloadAsset(assetObject); + _resourceService.UnloadAsset(assetObject); return cachedAsset; } diff --git a/Runtime/Resource/Resource/Extension/ResourceExtComponent.cs b/Runtime/Resource/Resource/Extension/ResourceExtComponent.cs index 9bb225c..9598ba4 100644 --- a/Runtime/Resource/Resource/Extension/ResourceExtComponent.cs +++ b/Runtime/Resource/Resource/Extension/ResourceExtComponent.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections; using System.Collections.Generic; using AlicizaX.ObjectPool; @@ -66,7 +66,7 @@ namespace AlicizaX.Resource.Runtime { Instance = this; yield return new WaitForEndOfFrame(); - IObjectPoolModule objectPoolComponent = ModuleSystem.GetModule(); + IObjectPoolService objectPoolComponent = AppServices.Require(); _assetItemPool = objectPoolComponent.CreateMultiSpawnObjectPool( "SetAssetPool", autoReleaseInterval, 16, 60, 0); diff --git a/Runtime/Resource/Resource/IResourceModule.cs b/Runtime/Resource/Resource/IResourceService.cs similarity index 99% rename from Runtime/Resource/Resource/IResourceModule.cs rename to Runtime/Resource/Resource/IResourceService.cs index f73f9cf..573404e 100644 --- a/Runtime/Resource/Resource/IResourceModule.cs +++ b/Runtime/Resource/Resource/IResourceService.cs @@ -10,7 +10,7 @@ namespace AlicizaX.Resource.Runtime /// /// 资源管理器接口。 /// - public interface IResourceModule : IModule + public interface IResourceService : IService { /// /// 获取当前资源适用的游戏版本号。 diff --git a/Runtime/Resource/Resource/IResourceModule.cs.meta b/Runtime/Resource/Resource/IResourceService.cs.meta similarity index 100% rename from Runtime/Resource/Resource/IResourceModule.cs.meta rename to Runtime/Resource/Resource/IResourceService.cs.meta diff --git a/Runtime/Resource/Resource/Reference/AssetsReference.cs b/Runtime/Resource/Resource/Reference/AssetsReference.cs index 29ed325..a89f963 100644 --- a/Runtime/Resource/Resource/Reference/AssetsReference.cs +++ b/Runtime/Resource/Resource/Reference/AssetsReference.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using UnityEngine; using Object = UnityEngine.Object; @@ -28,25 +28,25 @@ namespace AlicizaX.Resource.Runtime [SerializeField] private List refAssetInfoList; - private static IResourceModule _resourceModule; + private static IResourceService _resourceService; private HashSet _refAssetIds; private bool TryEnsureResourceModule() { - if (_resourceModule != null) + if (_resourceService != null) { return true; } - _resourceModule = ModuleSystem.GetModule(); - return _resourceModule != null; + _resourceService = AppServices.Require(); + return _resourceService != null; } private void ReleaseSourceReference() { if (sourceGameObject != null) { - _resourceModule.UnloadAsset(sourceGameObject); + _resourceService.UnloadAsset(sourceGameObject); sourceGameObject = null; } } @@ -93,7 +93,7 @@ namespace AlicizaX.Resource.Runtime { foreach (var refInfo in refAssetInfoList) { - _resourceModule.UnloadAsset(refInfo.refAsset); + _resourceService.UnloadAsset(refInfo.refAsset); } refAssetInfoList.Clear(); @@ -102,7 +102,7 @@ namespace AlicizaX.Resource.Runtime _refAssetIds?.Clear(); } - public AssetsReference Ref(GameObject source, IResourceModule resourceModule = null) + public AssetsReference Ref(GameObject source, IResourceService resourceService = null) { if (source == null) { @@ -114,9 +114,9 @@ namespace AlicizaX.Resource.Runtime throw new GameFrameworkException($"Source gameObject is in scene."); } - if (resourceModule != null) + if (resourceService != null) { - _resourceModule = resourceModule; + _resourceService = resourceService; } if (sourceGameObject != null && sourceGameObject != source && TryEnsureResourceModule()) @@ -128,16 +128,16 @@ namespace AlicizaX.Resource.Runtime return this; } - public AssetsReference Ref(T source, IResourceModule resourceModule = null) where T : Object + public AssetsReference Ref(T source, IResourceService resourceService = null) where T : Object { if (source == null) { throw new GameFrameworkException($"Source gameObject is null."); } - if (resourceModule != null) + if (resourceService != null) { - _resourceModule = resourceModule; + _resourceService = resourceService; } EnsureReferenceCache(); @@ -156,7 +156,7 @@ namespace AlicizaX.Resource.Runtime return this; } - internal static AssetsReference Instantiate(GameObject source, Transform parent = null, IResourceModule resourceModule = null) + internal static AssetsReference Instantiate(GameObject source, Transform parent = null, IResourceService resourceService = null) { if (source == null) { @@ -169,10 +169,10 @@ namespace AlicizaX.Resource.Runtime } GameObject instance = Object.Instantiate(source, parent); - return instance.AddComponent().Ref(source, resourceModule); + return instance.AddComponent().Ref(source, resourceService); } - public static AssetsReference Ref(GameObject source, GameObject instance, IResourceModule resourceModule = null) + public static AssetsReference Ref(GameObject source, GameObject instance, IResourceService resourceService = null) { if (source == null) { @@ -185,10 +185,10 @@ namespace AlicizaX.Resource.Runtime } var comp = instance.GetComponent(); - return comp ? comp.Ref(source, resourceModule) : instance.AddComponent().Ref(source, resourceModule); + return comp ? comp.Ref(source, resourceService) : instance.AddComponent().Ref(source, resourceService); } - public static AssetsReference Ref(T source, GameObject instance, IResourceModule resourceModule = null) where T : Object + public static AssetsReference Ref(T source, GameObject instance, IResourceService resourceService = null) where T : Object { if (source == null) { @@ -196,7 +196,7 @@ namespace AlicizaX.Resource.Runtime } var comp = instance.GetComponent(); - return comp ? comp.Ref(source, resourceModule) : instance.AddComponent().Ref(source, resourceModule); + return comp ? comp.Ref(source, resourceService) : instance.AddComponent().Ref(source, resourceService); } } } diff --git a/Runtime/Resource/Resource/Reference/AssetsSetHelper.cs b/Runtime/Resource/Resource/Reference/AssetsSetHelper.cs index 0e798c2..b89f81b 100644 --- a/Runtime/Resource/Resource/Reference/AssetsSetHelper.cs +++ b/Runtime/Resource/Resource/Reference/AssetsSetHelper.cs @@ -1,4 +1,4 @@ -using AlicizaX; +using AlicizaX; using UnityEngine; using UnityEngine.UI; @@ -6,13 +6,13 @@ namespace AlicizaX.Resource.Runtime { public static class AssetsSetHelper { - private static IResourceModule _resourceModule; + private static IResourceService _resourceService; private static void CheckResourceManager() { - if (_resourceModule == null) + if (_resourceService == null) { - _resourceModule = ModuleSystem.GetModule(); + _resourceService = AppServices.Require(); } } @@ -29,17 +29,17 @@ namespace AlicizaX.Resource.Runtime if (!isAsync) { - Material material = _resourceModule.LoadAsset(location, packageName); + Material material = _resourceService.LoadAsset(location, packageName); image.material = material; AssetsReference.Ref(material, image.gameObject); } else { - _resourceModule.LoadAsset(location, material => + _resourceService.LoadAsset(location, material => { if (image == null || image.gameObject == null) { - _resourceModule.UnloadAsset(material); + _resourceService.UnloadAsset(material); material = null; return; } @@ -61,17 +61,17 @@ namespace AlicizaX.Resource.Runtime if (!isAsync) { - Material material = _resourceModule.LoadAsset(location, packageName); + Material material = _resourceService.LoadAsset(location, packageName); spriteRenderer.material = material; AssetsReference.Ref(material, spriteRenderer.gameObject); } else { - _resourceModule.LoadAsset(location, material => + _resourceService.LoadAsset(location, material => { if (spriteRenderer == null || spriteRenderer.gameObject == null) { - _resourceModule.UnloadAsset(material); + _resourceService.UnloadAsset(material); material = null; return; } @@ -93,17 +93,17 @@ namespace AlicizaX.Resource.Runtime if (!isAsync) { - Material material = _resourceModule.LoadAsset(location, packageName); + Material material = _resourceService.LoadAsset(location, packageName); meshRenderer.material = needInstance ? Object.Instantiate(material) : material; AssetsReference.Ref(material, meshRenderer.gameObject); } else { - _resourceModule.LoadAsset(location, material => + _resourceService.LoadAsset(location, material => { if (meshRenderer == null || meshRenderer.gameObject == null) { - _resourceModule.UnloadAsset(material); + _resourceService.UnloadAsset(material); material = null; return; } @@ -125,17 +125,17 @@ namespace AlicizaX.Resource.Runtime if (!isAsync) { - Material material = _resourceModule.LoadAsset(location, packageName); + Material material = _resourceService.LoadAsset(location, packageName); meshRenderer.sharedMaterial = material; AssetsReference.Ref(material, meshRenderer.gameObject); } else { - _resourceModule.LoadAsset(location, material => + _resourceService.LoadAsset(location, material => { if (meshRenderer == null || meshRenderer.gameObject == null) { - _resourceModule.UnloadAsset(material); + _resourceService.UnloadAsset(material); material = null; return; } diff --git a/Runtime/Resource/Resource/ResourceComponent.cs b/Runtime/Resource/Resource/ResourceComponent.cs index 86e5b50..b60fad2 100644 --- a/Runtime/Resource/Resource/ResourceComponent.cs +++ b/Runtime/Resource/Resource/ResourceComponent.cs @@ -16,7 +16,7 @@ namespace AlicizaX.Resource.Runtime private const int DEFAULT_PRIORITY = 0; - private IResourceModule _resourceModule; + private IResourceService _resourceService; private bool _forceUnloadUnusedAssets = false; @@ -94,12 +94,12 @@ namespace AlicizaX.Resource.Runtime /// /// 获取当前资源适用的游戏版本号。 /// - public string ApplicableGameVersion => _resourceModule.ApplicableGameVersion; + public string ApplicableGameVersion => _resourceService.ApplicableGameVersion; /// /// 获取当前内部资源版本号。 /// - public int InternalResourceVersion => _resourceModule.InternalResourceVersion; + public int InternalResourceVersion => _resourceService.InternalResourceVersion; /// /// 获取或设置无用资源释放的最小间隔时间,以秒为单位。 @@ -146,8 +146,8 @@ namespace AlicizaX.Resource.Runtime /// public float AssetAutoReleaseInterval { - get => _resourceModule.AssetAutoReleaseInterval; - set => _resourceModule.AssetAutoReleaseInterval = assetAutoReleaseInterval = value; + get => _resourceService.AssetAutoReleaseInterval; + set => _resourceService.AssetAutoReleaseInterval = assetAutoReleaseInterval = value; } /// @@ -155,8 +155,8 @@ namespace AlicizaX.Resource.Runtime /// public int AssetCapacity { - get => _resourceModule.AssetCapacity; - set => _resourceModule.AssetCapacity = assetCapacity = value; + get => _resourceService.AssetCapacity; + set => _resourceService.AssetCapacity = assetCapacity = value; } /// @@ -164,8 +164,8 @@ namespace AlicizaX.Resource.Runtime /// public float AssetExpireTime { - get => _resourceModule.AssetExpireTime; - set => _resourceModule.AssetExpireTime = assetExpireTime = value; + get => _resourceService.AssetExpireTime; + set => _resourceService.AssetExpireTime = assetExpireTime = value; } /// @@ -173,8 +173,8 @@ namespace AlicizaX.Resource.Runtime /// public int AssetPriority { - get => _resourceModule.AssetPriority; - set => _resourceModule.AssetPriority = assetPriority = value; + get => _resourceService.AssetPriority; + set => _resourceService.AssetPriority = assetPriority = value; } #endregion @@ -191,7 +191,7 @@ namespace AlicizaX.Resource.Runtime private void Awake() { - _resourceModule = ModuleSystem.RegisterModule(); + _resourceService = AppServices.GetOrCreateScope().Register(new ResourceService()); Application.lowMemory += OnLowMemory; } @@ -201,21 +201,21 @@ namespace AlicizaX.Resource.Runtime private void Start() { #if UNITY_EDITOR - _playMode = (EPlayMode)UnityEditor.EditorPrefs.GetInt(ResourceComponent.PrefsKey, 0); + _playMode = (EPlayMode)UnityEditor.EditorPrefs.GetInt(PrefsKey, 0); #endif - _resourceModule.DefaultPackageName = PackageName; - _resourceModule.DecryptionServices = decryptionServices; - _resourceModule.AutoUnloadBundleWhenUnused = autoUnloadBundleWhenUnused; - _resourceModule.PlayMode = _playMode; - _resourceModule.Milliseconds = milliseconds; - _resourceModule.DownloadingMaxNum = DownloadingMaxNum; - _resourceModule.FailedTryAgain = FailedTryAgain; - _resourceModule.Initialize(); - _resourceModule.AssetAutoReleaseInterval = assetAutoReleaseInterval; - _resourceModule.AssetCapacity = assetCapacity; - _resourceModule.AssetExpireTime = assetExpireTime; - _resourceModule.AssetPriority = assetPriority; - _resourceModule.SetForceUnloadUnusedAssetsAction(ForceUnloadUnusedAssets); + _resourceService.DefaultPackageName = PackageName; + _resourceService.DecryptionServices = decryptionServices; + _resourceService.AutoUnloadBundleWhenUnused = autoUnloadBundleWhenUnused; + _resourceService.PlayMode = _playMode; + _resourceService.Milliseconds = milliseconds; + _resourceService.DownloadingMaxNum = DownloadingMaxNum; + _resourceService.FailedTryAgain = FailedTryAgain; + _resourceService.Initialize(); + _resourceService.AssetAutoReleaseInterval = assetAutoReleaseInterval; + _resourceService.AssetCapacity = assetCapacity; + _resourceService.AssetExpireTime = assetExpireTime; + _resourceService.AssetPriority = assetPriority; + _resourceService.SetForceUnloadUnusedAssetsAction(ForceUnloadUnusedAssets); Log.Info($"ResourceModule Run Mode:{_playMode}"); } @@ -251,7 +251,7 @@ namespace AlicizaX.Resource.Runtime _forceUnloadUnusedAssets = false; _preorderUnloadUnusedAssets = false; _lastUnloadUnusedAssetsOperationElapseSeconds = 0f; - _resourceModule.UnloadUnusedAssets(); + _resourceService.UnloadUnusedAssets(); _asyncOperation = useSystemUnloadUnusedAssets ? Resources.UnloadUnusedAssets() : null; } @@ -286,9 +286,9 @@ namespace AlicizaX.Resource.Runtime private void OnLowMemory() { Log.Warning("Low memory reported..."); - if (_resourceModule != null) + if (_resourceService != null) { - _resourceModule.OnLowMemory(); + _resourceService.OnLowMemory(); } } diff --git a/Runtime/Resource/Resource/ResourceModule.AssetObject.cs b/Runtime/Resource/Resource/ResourceService.AssetObject.cs similarity index 85% rename from Runtime/Resource/Resource/ResourceModule.AssetObject.cs rename to Runtime/Resource/Resource/ResourceService.AssetObject.cs index 9618cca..5a8d1d6 100644 --- a/Runtime/Resource/Resource/ResourceModule.AssetObject.cs +++ b/Runtime/Resource/Resource/ResourceService.AssetObject.cs @@ -1,4 +1,4 @@ -using System.Buffers; +using System.Buffers; using System.Collections.Generic; using AlicizaX.ObjectPool; using AlicizaX; @@ -6,7 +6,7 @@ using YooAsset; namespace AlicizaX.Resource.Runtime { - internal partial class ResourceModule + internal partial class ResourceService { /// /// 资源对象。 @@ -14,7 +14,7 @@ namespace AlicizaX.Resource.Runtime private sealed class AssetObject : ObjectBase { private AssetHandle m_AssetHandle; - private ResourceModule _mResourceModule; + private IResourceService _resourceService; public AssetObject() @@ -22,14 +22,14 @@ namespace AlicizaX.Resource.Runtime m_AssetHandle = null; } - public static AssetObject Create(string name, object target, object assetHandle, ResourceModule resourceModule) + public static AssetObject Create(string name, object target, object assetHandle, IResourceService resourceService) { if (assetHandle == null) { throw new GameFrameworkException("Resource is invalid."); } - if (resourceModule == null) + if (resourceService == null) { throw new GameFrameworkException("Resource Manager is invalid."); } @@ -37,7 +37,7 @@ namespace AlicizaX.Resource.Runtime AssetObject assetObject = MemoryPool.Acquire(); assetObject.Initialize(name, target); assetObject.m_AssetHandle = (AssetHandle)assetHandle; - assetObject._mResourceModule = resourceModule; + assetObject._resourceService = resourceService; return assetObject; } diff --git a/Runtime/Resource/Resource/ResourceModule.AssetObject.cs.meta b/Runtime/Resource/Resource/ResourceService.AssetObject.cs.meta similarity index 100% rename from Runtime/Resource/Resource/ResourceModule.AssetObject.cs.meta rename to Runtime/Resource/Resource/ResourceService.AssetObject.cs.meta diff --git a/Runtime/Resource/Resource/ResourceModule.Initialization.cs b/Runtime/Resource/Resource/ResourceService.Initialization.cs similarity index 99% rename from Runtime/Resource/Resource/ResourceModule.Initialization.cs rename to Runtime/Resource/Resource/ResourceService.Initialization.cs index 7c89242..93d72bc 100644 --- a/Runtime/Resource/Resource/ResourceModule.Initialization.cs +++ b/Runtime/Resource/Resource/ResourceService.Initialization.cs @@ -4,7 +4,7 @@ using YooAsset; namespace AlicizaX.Resource.Runtime { - internal partial class ResourceModule + internal partial class ResourceService { /// /// 根据运行模式创建初始化操作数据 diff --git a/Runtime/Resource/Resource/ResourceModule.Initialization.cs.meta b/Runtime/Resource/Resource/ResourceService.Initialization.cs.meta similarity index 100% rename from Runtime/Resource/Resource/ResourceModule.Initialization.cs.meta rename to Runtime/Resource/Resource/ResourceService.Initialization.cs.meta diff --git a/Runtime/Resource/Resource/ResourceModule.Pool.cs b/Runtime/Resource/Resource/ResourceService.Pool.cs similarity index 80% rename from Runtime/Resource/Resource/ResourceModule.Pool.cs rename to Runtime/Resource/Resource/ResourceService.Pool.cs index b526c5e..7ef6296 100644 --- a/Runtime/Resource/Resource/ResourceModule.Pool.cs +++ b/Runtime/Resource/Resource/ResourceService.Pool.cs @@ -1,9 +1,9 @@ -using AlicizaX.ObjectPool; +using AlicizaX.ObjectPool; using AlicizaX; namespace AlicizaX.Resource.Runtime { - internal partial class ResourceModule + internal partial class ResourceService { private IObjectPool _assetPool; @@ -59,13 +59,9 @@ namespace AlicizaX.Resource.Runtime /// 设置对象池管理器。 /// /// 对象池管理器。 - public void SetObjectPoolModule(IObjectPoolModule objectPoolModule) + public void CreateAssetPool( ) { - if (objectPoolModule == null) - { - throw new GameFrameworkException("Object pool manager is invalid."); - } - _assetPool = objectPoolModule.CreateMultiSpawnObjectPool("Asset Pool"); + _assetPool = Context.Require().CreateMultiSpawnObjectPool("Asset Pool"); } } } diff --git a/Runtime/Resource/Resource/ResourceModule.Pool.cs.meta b/Runtime/Resource/Resource/ResourceService.Pool.cs.meta similarity index 100% rename from Runtime/Resource/Resource/ResourceModule.Pool.cs.meta rename to Runtime/Resource/Resource/ResourceService.Pool.cs.meta diff --git a/Runtime/Resource/Resource/ResourceModule.Services.cs b/Runtime/Resource/Resource/ResourceService.Services.cs similarity index 100% rename from Runtime/Resource/Resource/ResourceModule.Services.cs rename to Runtime/Resource/Resource/ResourceService.Services.cs diff --git a/Runtime/Resource/Resource/ResourceModule.Services.cs.meta b/Runtime/Resource/Resource/ResourceService.Services.cs.meta similarity index 100% rename from Runtime/Resource/Resource/ResourceModule.Services.cs.meta rename to Runtime/Resource/Resource/ResourceService.Services.cs.meta diff --git a/Runtime/Resource/Resource/ResourceModule.cs b/Runtime/Resource/Resource/ResourceService.cs similarity index 99% rename from Runtime/Resource/Resource/ResourceModule.cs rename to Runtime/Resource/Resource/ResourceService.cs index 945a59b..1f84ba6 100644 --- a/Runtime/Resource/Resource/ResourceModule.cs +++ b/Runtime/Resource/Resource/ResourceService.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections; using System.Collections.Generic; using System.Threading; @@ -13,7 +13,7 @@ namespace AlicizaX.Resource.Runtime /// /// 资源管理器。 /// - internal sealed partial class ResourceModule : IResourceModule + internal sealed partial class ResourceService : ServiceBase, IResourceService { /// /// 默认资源包名称。 @@ -111,12 +111,15 @@ namespace AlicizaX.Resource.Runtime DefaultPackage = defaultPackage; PackageMap[packageName] = defaultPackage; - IObjectPoolModule objectPoolModule = ModuleSystem.GetModule(); - SetObjectPoolModule(objectPoolModule); + CreateAssetPool(); } - void IModule.Dispose() + protected override void OnInitialize() + { + } + + protected override void OnDestroyService() { foreach (var loadingOperation in _assetLoadingOperations.Values) { diff --git a/Runtime/Resource/Resource/ResourceModule.cs.meta b/Runtime/Resource/Resource/ResourceService.cs.meta similarity index 100% rename from Runtime/Resource/Resource/ResourceModule.cs.meta rename to Runtime/Resource/Resource/ResourceService.cs.meta diff --git a/Runtime/Scene/ISceneModule.cs b/Runtime/Scene/ISceneService.cs similarity index 98% rename from Runtime/Scene/ISceneModule.cs rename to Runtime/Scene/ISceneService.cs index 9011a24..a13d4ac 100644 --- a/Runtime/Scene/ISceneModule.cs +++ b/Runtime/Scene/ISceneService.cs @@ -7,7 +7,7 @@ using YooAsset; namespace AlicizaX.Scene.Runtime { - public interface ISceneModule : IModule,IModuleAwake + public interface ISceneService : IService { /// /// 当前主场景名称。 diff --git a/Runtime/Scene/ISceneModule.cs.meta b/Runtime/Scene/ISceneService.cs.meta similarity index 100% rename from Runtime/Scene/ISceneModule.cs.meta rename to Runtime/Scene/ISceneService.cs.meta diff --git a/Runtime/Scene/SceneComponent.cs b/Runtime/Scene/SceneComponent.cs index 3964062..c728ec2 100644 --- a/Runtime/Scene/SceneComponent.cs +++ b/Runtime/Scene/SceneComponent.cs @@ -10,7 +10,7 @@ namespace AlicizaX.Scene.Runtime { private void Awake() { - ModuleSystem.RegisterModule(); + AppServices.GetOrCreateScope().Register(new SceneService()); } } } diff --git a/Runtime/Scene/SceneModule.cs b/Runtime/Scene/SceneService.cs similarity index 97% rename from Runtime/Scene/SceneModule.cs rename to Runtime/Scene/SceneService.cs index 4ca667e..d7741df 100644 --- a/Runtime/Scene/SceneModule.cs +++ b/Runtime/Scene/SceneService.cs @@ -7,7 +7,7 @@ using YooAsset; namespace AlicizaX.Scene.Runtime { - internal class SceneModule : ISceneModule + internal class SceneService : ServiceBase, ISceneService { private string _currentMainSceneName = string.Empty; @@ -22,13 +22,13 @@ namespace AlicizaX.Scene.Runtime /// public string CurrentMainSceneName => _currentMainSceneName; - void IModuleAwake.Awake() + protected override void OnInitialize() { _currentMainScene = null; _currentMainSceneName = SceneManager.GetSceneByBuildIndex(0).name; } - void IModule.Dispose() + protected override void OnDestroyService() { var iter = _subScenes.Values.GetEnumerator(); while (iter.MoveNext()) @@ -117,7 +117,7 @@ namespace AlicizaX.Scene.Runtime await _currentMainScene.ToUniTask(); } - ModuleSystem.GetModule().ForceUnloadUnusedAssets(gcCollect); + Context.Require().ForceUnloadUnusedAssets(gcCollect); _handlingScene.Remove(location); @@ -191,7 +191,7 @@ namespace AlicizaX.Scene.Runtime InvokeProgress(_currentMainScene, progressCallBack).Forget(); } - ModuleSystem.GetModule().ForceUnloadUnusedAssets(gcCollect); + Context.Require().ForceUnloadUnusedAssets(gcCollect); } } diff --git a/Runtime/Scene/SceneModule.cs.meta b/Runtime/Scene/SceneService.cs.meta similarity index 100% rename from Runtime/Scene/SceneModule.cs.meta rename to Runtime/Scene/SceneService.cs.meta diff --git a/Runtime/Timer/ITimerModule.cs b/Runtime/Timer/ITimerService.cs similarity index 86% rename from Runtime/Timer/ITimerModule.cs rename to Runtime/Timer/ITimerService.cs index 4d0a683..fa1a492 100644 --- a/Runtime/Timer/ITimerModule.cs +++ b/Runtime/Timer/ITimerService.cs @@ -1,11 +1,9 @@ using System; -using System.Collections.Generic; -using AlicizaX; namespace AlicizaX { [UnityEngine.Scripting.Preserve] - public interface ITimerModule : IModule, IModuleUpdate + public interface ITimerService : IService, IServiceTickable { int AddTimer(TimerHandler callback, float time, bool isLoop = false, bool isUnscaled = false, params object[] args); int AddTimer(TimerHandlerNoArgs callback, float time, bool isLoop = false, bool isUnscaled = false); diff --git a/Runtime/Timer/ITimerModule.cs.meta b/Runtime/Timer/ITimerService.cs.meta similarity index 100% rename from Runtime/Timer/ITimerModule.cs.meta rename to Runtime/Timer/ITimerService.cs.meta diff --git a/Runtime/Timer/TimerComponent.cs b/Runtime/Timer/TimerComponent.cs index 4fec6ed..4fb4390 100644 --- a/Runtime/Timer/TimerComponent.cs +++ b/Runtime/Timer/TimerComponent.cs @@ -1,4 +1,3 @@ -using System; using AlicizaX; using UnityEngine; @@ -7,11 +6,11 @@ namespace AlicizaX.Timer.Runtime [DisallowMultipleComponent] [AddComponentMenu("Game Framework/Timer")] [UnityEngine.Scripting.Preserve] - public sealed class TimerComponent:MonoBehaviour + public sealed class TimerComponent : MonoBehaviour { private void Awake() { - ModuleSystem.RegisterModule(); + AppServices.GetOrCreateScope().Register(new TimerService()); } } } diff --git a/Runtime/Timer/TimerModule.cs b/Runtime/Timer/TimerService.cs similarity index 98% rename from Runtime/Timer/TimerModule.cs rename to Runtime/Timer/TimerService.cs index c23939c..6e91821 100644 --- a/Runtime/Timer/TimerModule.cs +++ b/Runtime/Timer/TimerService.cs @@ -77,7 +77,7 @@ namespace AlicizaX [UnityEngine.Scripting.Preserve] [Il2CppSetOption(Option.NullChecks, false)] [Il2CppSetOption(Option.ArrayBoundsChecks, false)] - internal sealed class TimerModule : ITimerModule + internal sealed class TimerService : ServiceBase, ITimerService { private const float TimeWheelSlotInterval = 0.001f; @@ -306,7 +306,7 @@ namespace AlicizaX } } - public TimerModule() + public TimerService() { _timerPoolCapacity = 64; _timerPool = new TimerInfo[_timerPoolCapacity]; @@ -596,7 +596,7 @@ namespace AlicizaX } } - void IModuleUpdate.Update(float elapseSeconds, float realElapseSeconds) + void IServiceTickable.Tick(float deltaTime) { _scaledTimeWheel.Advance(Time.time, _timerPool, ProcessTimer); _unscaledTimeWheel.Advance(Time.unscaledTime, _timerPool, ProcessTimer); @@ -669,8 +669,9 @@ namespace AlicizaX _pendingRemoveCount = 0; } - void IModule.Dispose() => RemoveAllTimer(); + protected override void OnInitialize() { } + protected override void OnDestroyService() => RemoveAllTimer(); - public int Priority => 0; + public int Order => 0; } } diff --git a/Runtime/Timer/TimerModule.cs.meta b/Runtime/Timer/TimerService.cs.meta similarity index 100% rename from Runtime/Timer/TimerModule.cs.meta rename to Runtime/Timer/TimerService.cs.meta diff --git a/Runtime/UI/Constant/UIHolderFactory.cs b/Runtime/UI/Constant/UIHolderFactory.cs index 6153310..8799b0a 100644 --- a/Runtime/UI/Constant/UIHolderFactory.cs +++ b/Runtime/UI/Constant/UIHolderFactory.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Linq; using AlicizaX.Resource.Runtime; using AlicizaX; @@ -10,7 +10,7 @@ namespace AlicizaX.UI.Runtime { public static class UIHolderFactory { - private static IResourceModule ResourceModule => ModuleSystem.GetModule(); + private static IResourceService ResourceService => AppServices.Require(); public static async UniTask CreateUIHolderAsync(Transform parent) where T : UIHolderObjectBase { @@ -40,14 +40,14 @@ namespace AlicizaX.UI.Runtime internal static async UniTask LoadUIResourcesAsync(UIResRegistry.UIResInfo resInfo, Transform parent) { return resInfo.LoadType == EUIResLoadType.AssetBundle - ? await ResourceModule.LoadGameObjectAsync(resInfo.Location, parent) + ? await ResourceService.LoadGameObjectAsync(resInfo.Location, parent) : await InstantiateResourceAsync(resInfo.Location, parent); } internal static GameObject LoadUIResourcesSync(UIResRegistry.UIResInfo resInfo, Transform parent) { return resInfo.LoadType == EUIResLoadType.AssetBundle - ? ResourceModule.LoadGameObject(resInfo.Location, parent) + ? ResourceService.LoadGameObject(resInfo.Location, parent) : InstantiateResourceSync(resInfo.Location, parent); } diff --git a/Runtime/UI/Constant/UIMetadataFactory.cs b/Runtime/UI/Constant/UIMetadataFactory.cs index dfb8470..90f9905 100644 --- a/Runtime/UI/Constant/UIMetadataFactory.cs +++ b/Runtime/UI/Constant/UIMetadataFactory.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using AlicizaX; using AlicizaX.ObjectPool; @@ -13,7 +13,7 @@ namespace AlicizaX.UI.Runtime static UIMetadataFactory() { - m_UIMetadataPool = ModuleSystem.GetModule().CreateSingleSpawnObjectPool("UI Metadata Pool", 60, 16, 60f, 0); + m_UIMetadataPool = AppServices.Require().CreateSingleSpawnObjectPool("UI Metadata Pool", 60, 16, 60f, 0); } internal static UIMetadata GetWindowMetadata() diff --git a/Runtime/UI/Manager/IUIModule.cs b/Runtime/UI/Manager/IUIService.cs similarity index 95% rename from Runtime/UI/Manager/IUIModule.cs rename to Runtime/UI/Manager/IUIService.cs index fb1f9b2..1e66db0 100644 --- a/Runtime/UI/Manager/IUIModule.cs +++ b/Runtime/UI/Manager/IUIService.cs @@ -9,7 +9,7 @@ namespace AlicizaX.UI.Runtime /// UI 模块接口:负责 UI 的创建、显示、关闭与查询。 /// 支持异步与同步(预加载)两种打开方式。 /// - public interface IUIModule : IModule, IModuleUpdate + public interface IUIService : IService, IServiceTickable { /// /// 初始化 UI 模块。 @@ -74,6 +74,6 @@ namespace AlicizaX.UI.Runtime /// /// 由框架内部注入计时模块。 /// - protected internal void SetTimerManager(ITimerModule timerModule); + protected internal void SetTimerService(ITimerService timerService); } } diff --git a/Runtime/UI/Manager/IUIModule.cs.meta b/Runtime/UI/Manager/IUIService.cs.meta similarity index 100% rename from Runtime/UI/Manager/IUIModule.cs.meta rename to Runtime/UI/Manager/IUIService.cs.meta diff --git a/Runtime/UI/Manager/UIModule.Block.cs b/Runtime/UI/Manager/UIService.Block.cs similarity index 89% rename from Runtime/UI/Manager/UIModule.Block.cs rename to Runtime/UI/Manager/UIService.Block.cs index 95be9b1..ef627fa 100644 --- a/Runtime/UI/Manager/UIModule.Block.cs +++ b/Runtime/UI/Manager/UIService.Block.cs @@ -3,7 +3,7 @@ using UnityEngine; namespace AlicizaX.UI.Runtime { - internal sealed partial class UIModule + internal sealed partial class UIService { private GameObject m_LayerBlock; //内部屏蔽对象 显示时之下的所有UI将不可操作 @@ -29,11 +29,11 @@ namespace AlicizaX.UI.Runtime { if (m_LastCountDownGuid != 0) { - _timerModule.RemoveTimer(m_LastCountDownGuid); + _timerService.RemoveTimer(m_LastCountDownGuid); } SetLayerBlockOption(true); - m_LastCountDownGuid = _timerModule.AddTimer(OnBlockCountDown, timeDuration); + m_LastCountDownGuid = _timerService.AddTimer(OnBlockCountDown, timeDuration); } /// @@ -43,7 +43,7 @@ namespace AlicizaX.UI.Runtime { if (m_LastCountDownGuid != 0) { - _timerModule.RemoveTimer(m_LastCountDownGuid); + _timerService.RemoveTimer(m_LastCountDownGuid); } RecoverLayerOptionAll(); diff --git a/Runtime/UI/Manager/UIModule.Block.cs.meta b/Runtime/UI/Manager/UIService.Block.cs.meta similarity index 100% rename from Runtime/UI/Manager/UIModule.Block.cs.meta rename to Runtime/UI/Manager/UIService.Block.cs.meta diff --git a/Runtime/UI/Manager/UIModule.Cache.cs b/Runtime/UI/Manager/UIService.Cache.cs similarity index 93% rename from Runtime/UI/Manager/UIModule.Cache.cs rename to Runtime/UI/Manager/UIService.Cache.cs index 9eb7bb0..6792155 100644 --- a/Runtime/UI/Manager/UIModule.Cache.cs +++ b/Runtime/UI/Manager/UIService.Cache.cs @@ -4,7 +4,7 @@ using AlicizaX; namespace AlicizaX.UI.Runtime { - internal sealed partial class UIModule + internal sealed partial class UIService { private readonly struct CacheEntry { @@ -40,7 +40,7 @@ namespace AlicizaX.UI.Runtime uiMetadata.View.Holder.transform.SetParent(UICacheLayer); if (uiMetadata.MetaInfo.CacheTime > 0) { - timerId = _timerModule.AddTimer( + timerId = _timerService.AddTimer( OnTimerDisposeWindow, uiMetadata, uiMetadata.MetaInfo.CacheTime, @@ -75,7 +75,7 @@ namespace AlicizaX.UI.Runtime entry.Metadata.InCache = false; if (entry.TimerId > 0) { - _timerModule.RemoveTimer(entry.TimerId); + _timerService.RemoveTimer(entry.TimerId); } } } diff --git a/Runtime/UI/Manager/UIModule.Cache.cs.meta b/Runtime/UI/Manager/UIService.Cache.cs.meta similarity index 100% rename from Runtime/UI/Manager/UIModule.Cache.cs.meta rename to Runtime/UI/Manager/UIService.Cache.cs.meta diff --git a/Runtime/UI/Manager/UIModule.Initlize.cs b/Runtime/UI/Manager/UIService.Initlize.cs similarity index 98% rename from Runtime/UI/Manager/UIModule.Initlize.cs rename to Runtime/UI/Manager/UIService.Initlize.cs index 4e2303f..9e0e24f 100644 --- a/Runtime/UI/Manager/UIModule.Initlize.cs +++ b/Runtime/UI/Manager/UIService.Initlize.cs @@ -3,7 +3,7 @@ using UnityEngine; namespace AlicizaX.UI.Runtime { - internal sealed partial class UIModule + internal sealed partial class UIService { public Camera UICamera { get; set; } public Canvas UICanvas; diff --git a/Runtime/UI/Manager/UIModule.Initlize.cs.meta b/Runtime/UI/Manager/UIService.Initlize.cs.meta similarity index 100% rename from Runtime/UI/Manager/UIModule.Initlize.cs.meta rename to Runtime/UI/Manager/UIService.Initlize.cs.meta diff --git a/Runtime/UI/Manager/UIModule.Open.cs b/Runtime/UI/Manager/UIService.Open.cs similarity index 99% rename from Runtime/UI/Manager/UIModule.Open.cs rename to Runtime/UI/Manager/UIService.Open.cs index 7de4a97..853092d 100644 --- a/Runtime/UI/Manager/UIModule.Open.cs +++ b/Runtime/UI/Manager/UIService.Open.cs @@ -21,7 +21,7 @@ namespace AlicizaX.UI.Runtime } } - internal sealed partial class UIModule + internal sealed partial class UIService { private readonly LayerData[] _openUI = new LayerData[(int)UILayer.All]; diff --git a/Runtime/UI/Manager/UIModule.Open.cs.meta b/Runtime/UI/Manager/UIService.Open.cs.meta similarity index 100% rename from Runtime/UI/Manager/UIModule.Open.cs.meta rename to Runtime/UI/Manager/UIService.Open.cs.meta diff --git a/Runtime/UI/Manager/UIModule.cs b/Runtime/UI/Manager/UIService.cs similarity index 87% rename from Runtime/UI/Manager/UIModule.cs rename to Runtime/UI/Manager/UIService.cs index 96ce2cc..8206d01 100644 --- a/Runtime/UI/Manager/UIModule.cs +++ b/Runtime/UI/Manager/UIService.cs @@ -7,17 +7,21 @@ using UnityEngine; namespace AlicizaX.UI.Runtime { - internal sealed partial class UIModule : IUIModule + internal sealed partial class UIService : ServiceBase, IUIService { public int Priority { get; } - private ITimerModule _timerModule; + private ITimerService _timerService; - void IModule.Dispose() + protected override void OnInitialize() { } - void IModuleUpdate.Update(float elapseSeconds, float realElapseSeconds) + protected override void OnDestroyService() + { + } + + void IServiceTickable.Tick(float deltaTime) { for (int layerIndex = 0; layerIndex < _openUI.Length; layerIndex++) { @@ -93,9 +97,9 @@ namespace AlicizaX.UI.Runtime } - void IUIModule.SetTimerManager(ITimerModule timerModule) + void IUIService.SetTimerService(ITimerService timerService) { - _timerModule = timerModule; + _timerService = timerService; } } } diff --git a/Runtime/UI/Manager/UIModule.cs.meta b/Runtime/UI/Manager/UIService.cs.meta similarity index 100% rename from Runtime/UI/Manager/UIModule.cs.meta rename to Runtime/UI/Manager/UIService.cs.meta diff --git a/Runtime/UI/UIBase/UIHolderObjectBase.cs b/Runtime/UI/UIBase/UIHolderObjectBase.cs index 4a1a0ba..f2c83c2 100644 --- a/Runtime/UI/UIBase/UIHolderObjectBase.cs +++ b/Runtime/UI/UIBase/UIHolderObjectBase.cs @@ -89,7 +89,7 @@ namespace AlicizaX.UI.Runtime for (int i = 0; i < behaviours.Length; i++) { MonoBehaviour behaviour = behaviours[i]; - if (!behaviour.isActiveAndEnabled || behaviour is not IUITransitionPlayer player) + if (behaviours.IsNull() || !behaviour.isActiveAndEnabled || behaviour is not IUITransitionPlayer player) { continue; } diff --git a/Runtime/UI/UIBase/UITabWindow.cs b/Runtime/UI/UIBase/UITabWindow.cs index 6fab2df..7028caa 100644 --- a/Runtime/UI/UIBase/UITabWindow.cs +++ b/Runtime/UI/UIBase/UITabWindow.cs @@ -30,7 +30,7 @@ namespace AlicizaX.UI.Runtime protected void CloseSelf(bool forceClose = false) { - ModuleSystem.GetModule().CloseUI(RuntimeTypeHandler, forceClose); + AppServices.Require().CloseUI(RuntimeTypeHandler, forceClose); } internal sealed override void BindUIHolder(UIHolderObjectBase holder, UIBase owner) diff --git a/Runtime/UI/UIBase/UIWindow.cs b/Runtime/UI/UIBase/UIWindow.cs index b6ebe14..2b03088 100644 --- a/Runtime/UI/UIBase/UIWindow.cs +++ b/Runtime/UI/UIBase/UIWindow.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Reflection; using AlicizaX; using UnityEngine; @@ -17,12 +17,12 @@ namespace AlicizaX.UI.Runtime /// protected void ForceCloseSlef() { - ModuleSystem.GetModule().CloseUI(RuntimeTypeHandler, true); + AppServices.Require().CloseUI(RuntimeTypeHandler, true); } protected void CloseSelf() { - ModuleSystem.GetModule().CloseUI(RuntimeTypeHandler, false); + AppServices.Require().CloseUI(RuntimeTypeHandler, false); } internal sealed override void BindUIHolder(UIHolderObjectBase holder, UIBase owner) diff --git a/Runtime/UI/UIComponent.cs b/Runtime/UI/UIComponent.cs index 3c47f34..10e8aab 100644 --- a/Runtime/UI/UIComponent.cs +++ b/Runtime/UI/UIComponent.cs @@ -21,7 +21,7 @@ namespace AlicizaX.UI.Runtime [SerializeField] private bool _isOrthographic = true; private Transform _instanceRoot = null; - private IUIModule _uiModule; + private IUIService _uiService; public const int UIHideLayer = 2; // Ignore Raycast public const int UIShowLayer = 5; // UI @@ -29,7 +29,7 @@ namespace AlicizaX.UI.Runtime private void Awake() { - _uiModule = ModuleSystem.RegisterModule(); + _uiService = AppServices.GetOrCreateScope().Register(new UIService()); if (uiRoot == null) { throw new GameFrameworkException("UIRoot Prefab is invalid."); @@ -38,12 +38,12 @@ namespace AlicizaX.UI.Runtime obj.name = "------UI Root------"; _instanceRoot = obj.transform; Object.DontDestroyOnLoad(_instanceRoot); - _uiModule.Initialize(_instanceRoot,_isOrthographic); + _uiService.Initialize(_instanceRoot,_isOrthographic); } private void Start() { - _uiModule.SetTimerManager(ModuleSystem.GetModule()); + _uiService.SetTimerService(AppServices.Require()); } @@ -55,7 +55,7 @@ namespace AlicizaX.UI.Runtime /// 安全区域 public void ApplyScreenSafeRect(Rect safeRect) { - CanvasScaler scaler = _uiModule.UICanvasRoot.GetComponent(); + CanvasScaler scaler = _uiService.UICanvasRoot.GetComponent(); if (scaler == null) { Log.Error($"Not found {nameof(CanvasScaler)} !"); @@ -74,7 +74,7 @@ namespace AlicizaX.UI.Runtime float offsetMaxY = scaler.referenceResolution.y - height - posY; // 注意:安全区坐标系的原点为左下角 - var rectTrans = _uiModule.UICanvasRoot.transform as RectTransform; + var rectTrans = _uiService.UICanvasRoot.transform as RectTransform; if (rectTrans != null) { rectTrans.offsetMin = new Vector2(posX, posY); //锚框状态下的屏幕左下角偏移向量