1.重名所有App级模块为Service
2.移除Module中心 移除SingletonManager
3.引入Service Scope Context概念  避免上下文Manager到处引用
4.修复部分bug
This commit is contained in:
陈思海 2026-03-26 16:14:05 +08:00
parent 58baa6269e
commit cad7722e44
121 changed files with 514 additions and 1096 deletions

View File

@ -4,7 +4,7 @@ using UnityEngine;
namespace AlicizaX
{
[CustomEditor(typeof(GameObjectPool))]
[CustomEditor(typeof(GameObjectPoolManager))]
public sealed class GameObjectPoolEditor : UnityEditor.Editor
{
private readonly Dictionary<string, bool> _foldoutState = new Dictionary<string, bool>();
@ -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<GameObjectPoolSnapshot> snapshots = pool.GetDebugSnapshots();
List<GameObjectPoolSnapshot> snapshots = poolManager.GetDebugSnapshots();
if (snapshots.Count == 0)
{
EditorGUILayout.HelpBox("No runtime pools have been created yet.", MessageType.Info);

View File

@ -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

View File

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: aeb86cc258fa4378ba3b259a5d38e4df
timeCreated: 1736424998

View File

@ -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();
}
}

View File

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 0ba192d5e9084d67b16b53e843e103b3
timeCreated: 1736424999

View File

@ -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<Type, IModule> _moduleMaps = new Dictionary<Type, IModule>(DesignModuleCount);
private static readonly GameFrameworkLinkedList<IModule> _modules = new GameFrameworkLinkedList<IModule>();
// Update systems
private static readonly GameFrameworkLinkedList<IModuleUpdate> _updateModules = new GameFrameworkLinkedList<IModuleUpdate>();
private static readonly IModuleUpdate[] _updateExecuteArray = new IModuleUpdate[DesignModuleCount];
private static int _updateExecuteCount;
// LateUpdate systems
private static readonly GameFrameworkLinkedList<IModuleLateUpdate> _lateUpdateModules = new GameFrameworkLinkedList<IModuleLateUpdate>();
private static readonly IModuleLateUpdate[] _lateUpdateExecuteArray = new IModuleLateUpdate[DesignModuleCount];
private static int _lateUpdateExecuteCount;
// FixedUpdate systems
private static readonly GameFrameworkLinkedList<IModuleFixedUpdate> _fixedUpdateModules = new GameFrameworkLinkedList<IModuleFixedUpdate>();
private static readonly IModuleFixedUpdate[] _fixedUpdateExecuteArray = new IModuleFixedUpdate[DesignModuleCount];
private static int _fixedUpdateExecuteCount;
// Gizmos systems
private static readonly GameFrameworkLinkedList<IModuleDrawGizmos> _gizmosUpdateModules = new GameFrameworkLinkedList<IModuleDrawGizmos>();
private static readonly IModuleDrawGizmos[] _gizmosUpdateExecuteArray = new IModuleDrawGizmos[DesignModuleCount];
private static int _gizmosExecuteCount;
// GUI systems
private static readonly GameFrameworkLinkedList<IModuleGUI> _guiUpdateModules = new GameFrameworkLinkedList<IModuleGUI>();
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<T, TImple>() 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<T>() 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<TImpl>(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>(T system, GameFrameworkLinkedList<T> 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
}
}

View File

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: b9fa1d3abb954b57989b94b4c77e45ce
timeCreated: 1736928479

View File

@ -1,4 +1,4 @@
using System;
using System;
using AlicizaX.ObjectPool;
using Cysharp.Threading.Tasks;
using UnityEngine;
@ -10,7 +10,7 @@ namespace AlicizaX
/// </summary>
[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
/// <summary>
/// 游戏框架组件初始化。
/// </summary>
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<IObjectPoolModule>();
IObjectPoolService objectPoolModule = AppServices.Require<IObjectPoolService>();
if (objectPoolModule != null)
{
objectPoolModule.ReleaseAllUnused();

View File

@ -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) { }

View File

@ -7,7 +7,7 @@ using UnityEngine;
namespace AlicizaX
{
public sealed class GameObjectPool : MonoServiceBehaviour<GameObjectPool>
public sealed class GameObjectPoolManager : MonoServiceBehaviour<GameObjectPoolManager>
{
private static readonly Comparison<GameObjectPoolSnapshot> 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<IResourceModule>();
PoolConfigScriptableObject configAsset =
resourceModule.LoadAsset<PoolConfigScriptableObject>(poolConfigPath);
IResourceService resourceService = AppServices.Require<IResourceService>();
PoolConfigScriptableObject configAsset = resourceService.LoadAsset<PoolConfigScriptableObject>(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)

View File

@ -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<IResourceModule>();
_resourceService = AppServices.Require<IResourceService>();
}
return _resourceModule;
return _resourceService;
}
}
public GameObject LoadPrefab(string location)
{
return ResourceModule.LoadAsset<GameObject>(location);
return ResourceService.LoadAsset<GameObject>(location);
}
public async UniTask<GameObject> LoadPrefabAsync(string location, CancellationToken cancellationToken = default)
{
return await ResourceModule.LoadAssetAsync<GameObject>(location, cancellationToken);
return await ResourceService.LoadAssetAsync<GameObject>(location, cancellationToken);
}
public GameObject LoadGameObject(string location, Transform parent = null)
{
return ResourceModule.LoadGameObject(location, parent);
return ResourceService.LoadGameObject(location, parent);
}
public async UniTask<GameObject> 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);
}
}
}

View File

@ -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<GameObject, RuntimePooledInstance> _instancesByObject;
private LinkedList<RuntimePooledInstance> _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));

View File

@ -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<ResourceComponent>();
_debuggerComponent = GetComponentInChildren<DebuggerComponent>();
_localizationComponent = GetComponentInChildren<LocalizationComponent>();
resourceComponent = GetComponentInChildren<ResourceComponent>();
debuggerComponent = GetComponentInChildren<DebuggerComponent>();
localizationComponent = GetComponentInChildren<LocalizationComponent>();
}
private void Awake()
@ -26,20 +27,20 @@ namespace AlicizaX
TextAsset text = Resources.Load<TextAsset>("ModuleDynamicBindInfo");
_dynamicBindInfo = Utility.Json.ToObject<ModuleDynamicBindInfo>(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);
}
}
}

View File

@ -7,7 +7,7 @@ namespace AlicizaX.ObjectPool
/// <summary>
/// 对象池管理器。
/// </summary>
public interface IObjectPoolModule: IModule, IModuleUpdate
public interface IObjectPoolService : IService, IServiceTickable
{
/// <summary>
/// 获取对象池数量。

View File

@ -8,24 +8,24 @@ namespace AlicizaX
/// </summary>
public sealed class ObjectPoolComponent : MonoBehaviour
{
private IObjectPoolModule _mObjectPoolModule = null;
private IObjectPoolService _mObjectPoolService = null;
/// <summary>
/// 获取对象池数量。
/// </summary>
public int Count
{
get { return _mObjectPoolModule.Count; }
get { return _mObjectPoolService.Count; }
}
private void Awake()
{
_mObjectPoolModule = ModuleSystem.RegisterModule<IObjectPoolModule,ObjectPoolModule>();
_mObjectPoolService = AppServices.GetOrCreateScope<AppScope>().Register(new ObjectPoolService());
}
private void OnDestroy()
{
_mObjectPoolModule = null;
_mObjectPoolService = null;
}
/// <summary>
@ -35,7 +35,7 @@ namespace AlicizaX
/// <returns>所有对象池。</returns>
public ObjectPoolBase[] GetAllObjectPools(bool sort)
{
return _mObjectPoolModule.GetAllObjectPools(sort);
return _mObjectPoolService.GetAllObjectPools(sort);
}
}
}

View File

@ -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
{
/// <summary>
/// 内部对象。

View File

@ -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
{
/// <summary>
/// 对象池。

View File

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using AlicizaX;
using UnityEngine;
namespace AlicizaX.ObjectPool
{
@ -8,7 +9,7 @@ namespace AlicizaX.ObjectPool
/// 对象池管理器。
/// </summary>
[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
/// <summary>
/// 初始化对象池管理器的新实例。
/// </summary>
public ObjectPoolModule()
public ObjectPoolService()
{
m_ObjectPools = new Dictionary<TypeNamePair, ObjectPoolBase>();
m_CachedAllObjectPools = new List<ObjectPoolBase>();
@ -47,18 +48,20 @@ namespace AlicizaX.ObjectPool
/// </summary>
/// <param name="elapseSeconds">逻辑流逝时间,以秒为单位。</param>
/// <param name="realElapseSeconds">真实流逝时间,以秒为单位。</param>
void IModuleUpdate.Update(float elapseSeconds, float realElapseSeconds)
void IServiceTickable.Tick(float deltaTime)
{
foreach (KeyValuePair<TypeNamePair, ObjectPoolBase> objectPool in m_ObjectPools)
{
objectPool.Value.Update(elapseSeconds, realElapseSeconds);
objectPool.Value.Update(Time.deltaTime,Time.unscaledDeltaTime);
}
}
/// <summary>
/// 关闭并清理对象池管理器。
/// </summary>
void IModule.Dispose()
protected override void OnInitialize() { }
protected override void OnDestroyService()
{
foreach (KeyValuePair<TypeNamePair, ObjectPoolBase> objectPool in m_ObjectPools)
{

View File

@ -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
/// <param name="index">音频代理辅助器编号。</param>
public void Init(AudioCategory audioCategory, int index = 0)
{
_audioModule = ModuleSystem.GetModule<IAudioModule>();
_resourceModule = ModuleSystem.GetModule<IResourceModule>();
_audioService = AppServices.Require<IAudioService>();
_resourceService = AppServices.Require<IResourceService>();
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<AudioClip>(path);
AssetHandle handle = _resourceService.LoadAssetAsyncHandle<AudioClip>(path);
handle.Completed += OnAssetLoadComplete;
}
else
{
AssetHandle handle = _resourceModule.LoadAssetSyncHandle<AudioClip>(path);
AssetHandle handle = _resourceService.LoadAssetSyncHandle<AudioClip>(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);
}
}

View File

@ -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
/// <param name="audioGroupConfig">音频轨道组配置。</param>
public AudioCategory(int maxChannel, AudioMixer audioMixer, AudioGroupConfig audioGroupConfig)
{
var audioModule = ModuleSystem.GetModule<IAudioModule>();
var audioModule = AppServices.Require<IAudioService>();
this.audioMixer = audioMixer;
_maxChannel = maxChannel;

View File

@ -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<IAudioModule,AudioModule>();
_audioService = AppServices.GetOrCreateScope<AppScope>().Register(new AudioService());
}
/// <summary>
@ -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>("AudioMixer");
}
_audioModule.Initialize(m_AudioGroupConfigs, m_InstanceRoot, m_AudioMixer);
_audioService.Initialize(m_AudioGroupConfigs, m_InstanceRoot, m_AudioMixer);
}
}
}

View File

@ -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
/// <exception cref="GameFrameworkException"></exception>
public void Initialize(AudioGroupConfig[] audioGroupConfigs, Transform instanceRoot = null, AudioMixer audioMixer = null)
{
_resourceModule = ModuleSystem.GetModule<IResourceModule>();
_resourceService = AppServices.Require<IResourceService>();
if (_instanceRoot == null)
{
_instanceRoot = instanceRoot;
@ -526,7 +528,7 @@ namespace AlicizaX.Audio.Runtime
{
if (AudioClipPool != null && !AudioClipPool.ContainsKey(path))
{
AssetHandle assetData = _resourceModule.LoadAssetAsyncHandle<AudioClip>(path);
AssetHandle assetData = _resourceService.LoadAssetAsyncHandle<AudioClip>(path);
assetData.Completed += handle => { AudioClipPool?.Add(path, handle); };
}
}
@ -576,18 +578,19 @@ namespace AlicizaX.Audio.Runtime
/// </summary>
/// <param name="elapseSeconds">逻辑流逝时间,以秒为单位。</param>
/// <param name="realElapseSeconds">真实流逝时间,以秒为单位。</param>
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; }
}
}

View File

@ -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
{
/// <summary>
/// 总音量控制。

View File

@ -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<IObjectPoolModule>();
if (m_ObjectPoolComponent == null)
{
Log.Error("Object pool component is invalid.");
return;
}
m_ObjectPoolService = AppServices.Require<IObjectPoolService>();
}
protected override void OnDrawScrollableWindow()
@ -24,10 +19,10 @@ namespace AlicizaX.Debugger.Runtime
GUILayout.Label("<b>Object Pool Information</b>");
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]);

View File

@ -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("<b>Operations</b>");
// GUILayout.BeginVertical("box");
// {
// ObjectPoolComponent objectPoolComponent = GameEntry.GetComponent<ObjectPoolComponent>();
// 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<ResourceComponent>();
// 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();
// }
// }
// }
// }

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: a695dd87b92d7374fbe3790f5a25e9d5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -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();

View File

@ -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
/// </summary>
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<IDebuggerModule, DebuggerModule>();
if (_mDebuggerModule == null)
_mDebuggerService = AppServices.GetOrCreateScope<AppScope>().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
/// <param name="args">初始化调试器窗口参数。</param>
public void RegisterDebuggerWindow(string path, IDebuggerWindow debuggerWindow, params object[] args)
{
_mDebuggerModule.RegisterDebuggerWindow(path, debuggerWindow, args);
_mDebuggerService.RegisterDebuggerWindow(path, debuggerWindow, args);
}
/// <summary>
@ -273,7 +273,7 @@ namespace AlicizaX.Debugger.Runtime
/// <returns>是否解除注册调试器窗口成功。</returns>
public bool UnregisterDebuggerWindow(string path)
{
return _mDebuggerModule.UnregisterDebuggerWindow(path);
return _mDebuggerService.UnregisterDebuggerWindow(path);
}
/// <summary>
@ -283,7 +283,7 @@ namespace AlicizaX.Debugger.Runtime
/// <returns>要获取的调试器窗口。</returns>
public IDebuggerWindow GetDebuggerWindow(string path)
{
return _mDebuggerModule.GetDebuggerWindow(path);
return _mDebuggerService.GetDebuggerWindow(path);
}
/// <summary>
@ -293,7 +293,7 @@ namespace AlicizaX.Debugger.Runtime
/// <returns>是否成功选中调试器窗口。</returns>
public bool SelectDebuggerWindow(string path)
{
return _mDebuggerModule.SelectDebuggerWindow(path);
return _mDebuggerService.SelectDebuggerWindow(path);
}
/// <summary>
@ -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("<b>{0}</b>", debuggerWindowNames[i]));
}
if (debuggerWindowGroup == _mDebuggerModule.DebuggerWindowRoot)
if (debuggerWindowGroup == _mDebuggerService.DebuggerWindowRoot)
{
names.Add("<b>Close</b>");
}

View File

@ -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
{
/// <summary>
/// 调试器窗口组。

View File

@ -1,4 +1,5 @@
using AlicizaX;
using UnityEngine;
namespace AlicizaX.Debugger.Runtime
{
@ -6,7 +7,7 @@ namespace AlicizaX.Debugger.Runtime
/// 调试器管理器。
/// </summary>
[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
/// 初始化调试器管理器的新实例。
/// </summary>
[UnityEngine.Scripting.Preserve]
public DebuggerModule()
public DebuggerService()
{
m_DebuggerWindowRoot = new DebuggerWindowGroup();
m_ActiveWindow = false;
@ -48,20 +49,22 @@ namespace AlicizaX.Debugger.Runtime
/// </summary>
/// <param name="elapseSeconds">逻辑流逝时间,以秒为单位。</param>
/// <param name="realElapseSeconds">真实流逝时间,以秒为单位。</param>
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);
}
/// <summary>
/// 关闭并清理调试器管理器。
/// </summary>
void IModule.Dispose()
protected override void OnInitialize() { }
protected override void OnDestroyService()
{
m_ActiveWindow = false;
m_DebuggerWindowRoot.Shutdown();

View File

@ -1,4 +1,4 @@

using AlicizaX;
@ -6,7 +6,7 @@ using AlicizaX;
namespace AlicizaX.Debugger.Runtime
{
/// <summary>调试器管理器接口。</summary>
public interface IDebuggerModule:IModule,IModuleUpdate
public interface IDebuggerService:IService, IServiceTickable
{
/// <summary>获取或设置调试器窗口是否激活。</summary>
bool ActiveWindow { get; set; }

164
Runtime/GameApp.cs Normal file
View File

@ -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
{
/// <summary>
/// 获取游戏基础组件。
/// </summary>
public static RootModule Base => RootModule.Instance;
/// <summary>
/// 获取声音组件。
/// </summary>
public static IAudioService Audio
{
get
{
if (_audio == null)
{
_audio = AppServices.App.Require<IAudioService>();
}
return _audio;
}
}
private static IAudioService _audio;
/// <summary>
/// 获取本地化组件。
/// </summary>
public static ILocalizationService Localization
{
get
{
if (_localization == null)
{
_localization = AppServices.App.Require<ILocalizationService>();
}
return _localization;
}
}
private static ILocalizationService _localization;
/// <summary>
/// 获取对象池组件。
/// </summary>
public static IObjectPoolService ObjectPool
{
get
{
if (_objectPool == null)
{
_objectPool = AppServices.App.Require<IObjectPoolService>();
}
return _objectPool;
}
}
private static IObjectPoolService _objectPool;
/// <summary>
/// 获取有限状态机组件。
/// </summary>
public static IProcedureService Procedure
{
get
{
if (_procedure == null)
{
_procedure = AppServices.App.Require<IProcedureService>();
}
return _procedure;
}
}
private static IProcedureService _procedure;
/// <summary>
/// 获取Asset组件。
/// </summary>
public static IResourceService Resource
{
get
{
if (_resource == null)
{
_resource = AppServices.App.Require<IResourceService>();
}
return _resource;
}
}
private static IResourceService _resource;
/// <summary>
/// 获取场景组件。
/// </summary>
public static ISceneService Scene
{
get
{
if (_scene == null)
{
_scene = AppServices.App.Require<ISceneService>();
}
return _scene;
}
}
private static ISceneService _scene;
/// <summary>
/// 获取定时器组件。
/// </summary>
public static ITimerService Timer
{
get
{
if (_timer == null)
{
_timer = AppServices.App.Require<ITimerService>();
}
return _timer;
}
}
private static ITimerService _timer;
/// <summary>
/// 获取UI组件。
/// </summary>
public static IUIService UI
{
get
{
if (_ui == null)
{
_ui = AppServices.App.Require<IUIService>();
}
return _ui;
}
}
private static IUIService _ui;
}

View File

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: f06920c335296ea4694dab52e8bd493a
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,23 +0,0 @@
using AlicizaX;
using AlicizaX.Audio.Runtime;
public static partial class GameApp
{
/// <summary>
/// 获取声音组件。
/// </summary>
public static IAudioModule Audio
{
get
{
if (_audio == null)
{
_audio = ModuleSystem.GetModule<IAudioModule>();
}
return _audio;
}
}
internal static IAudioModule _audio;
}

View File

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 3e9812a7462843d48a0660209e7bf8aa
timeCreated: 1737440423

View File

@ -1,23 +0,0 @@
using AlicizaX.Localization.Runtime;
using AlicizaX;
public static partial class GameApp
{
/// <summary>
/// 获取本地化组件。
/// </summary>
public static ILocalizationModule Localization
{
get
{
if (_localization == null)
{
_localization = ModuleSystem.GetModule<ILocalizationModule>();
}
return _localization;
}
}
internal static ILocalizationModule _localization;
}

View File

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: a8c610d4005146509b2dd9a685bb15af
timeCreated: 1737440423

View File

@ -1,23 +0,0 @@
using AlicizaX.ObjectPool;
using AlicizaX;
public static partial class GameApp
{
/// <summary>
/// 获取对象池组件。
/// </summary>
public static IObjectPoolModule ObjectPool
{
get
{
if (_objectPool == null)
{
_objectPool = ModuleSystem.GetModule<IObjectPoolModule>();
}
return _objectPool;
}
}
internal static IObjectPoolModule _objectPool;
}

View File

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 10a6970b6ffc472d801816ffbdf8f1e1
timeCreated: 1737440423

View File

@ -1,22 +0,0 @@
using AlicizaX;
public static partial class GameApp
{
/// <summary>
/// 获取有限状态机组件。
/// </summary>
public static IProcedureModule Procedure
{
get
{
if (_procedure == null)
{
_procedure = ModuleSystem.GetModule<IProcedureModule>();
}
return _procedure;
}
}
internal static IProcedureModule _procedure;
}

View File

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 577055df4d464c3999cdd432e009000e
timeCreated: 1763452169

View File

@ -1,23 +0,0 @@
using AlicizaX.Resource.Runtime;
using AlicizaX;
public static partial class GameApp
{
/// <summary>
/// 获取Asset组件。
/// </summary>
public static IResourceModule Resource
{
get
{
if (_resource == null)
{
_resource = ModuleSystem.GetModule<IResourceModule>();
}
return _resource;
}
}
internal static IResourceModule _resource;
}

View File

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: ba1f965b36d44ae2ac5820bc7fbb64ac
timeCreated: 1737440423

View File

@ -1,23 +0,0 @@
using AlicizaX;
using AlicizaX.Scene.Runtime;
public static partial class GameApp
{
/// <summary>
/// 获取场景组件。
/// </summary>
public static ISceneModule Scene
{
get
{
if (_scene == null)
{
_scene = ModuleSystem.GetModule<ISceneModule>();
}
return _scene;
}
}
internal static ISceneModule _scene;
}

View File

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 214b27a946ff481fb669e0cf645398ee
timeCreated: 1737440423

View File

@ -1,23 +0,0 @@
using AlicizaX;
using AlicizaX.Timer.Runtime;
public static partial class GameApp
{
/// <summary>
/// 获取定时器组件。
/// </summary>
public static ITimerModule Timer
{
get
{
if (_timer == null)
{
_timer = ModuleSystem.GetModule<ITimerModule>();
}
return _timer;
}
}
internal static ITimerModule _timer;
}

View File

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 669e997f79b44a11bf93c9da9af48397
timeCreated: 1737440423

View File

@ -1,23 +0,0 @@
using AlicizaX;
using AlicizaX.UI.Runtime;
public static partial class GameApp
{
/// <summary>
/// 获取UI组件。
/// </summary>
public static IUIModule UI
{
get
{
if (_ui == null)
{
_ui = ModuleSystem.GetModule<IUIModule>();
}
return _ui;
}
}
internal static IUIModule _ui;
}

View File

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 198f337af87540e2be6fe76fa1abec0f
timeCreated: 1737440423

View File

@ -1,22 +0,0 @@
using AlicizaX;
public static partial class GameApp
{
/// <summary>
/// 获取游戏基础组件。
/// </summary>
public static RootModule Base
{
get
{
if (_base == null)
{
_base = RootModule.Instance;
}
return _base;
}
}
internal static RootModule _base;
}

View File

@ -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

View File

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: a0120d62fb8349d58e950bdaa50145e4
timeCreated: 1743593118

View File

@ -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<ILocalizationModule, LocalizationModule>();
if (_mLocalizationModule == null)
_mLocalizationService = AppServices.GetOrCreateScope<AppScope>().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);
}
}
}

View File

@ -6,7 +6,7 @@ namespace AlicizaX.Localization.Runtime
/// <summary>
/// 本地化管理器接口。
/// </summary>
public interface ILocalizationModule : IModule
public interface ILocalizationService : IService
{
public string Language { get; }

View File

@ -8,7 +8,7 @@ namespace AlicizaX.Localization.Runtime
/// 本地化管理器。
/// </summary>
[UnityEngine.Scripting.Preserve]
internal sealed partial class LocalizationModule : ILocalizationModule
internal sealed partial class LocalizationService : ServiceBase, ILocalizationService
{
private readonly Dictionary<string, string> 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();
}

View File

@ -3,7 +3,7 @@ using System.Collections.Generic;
namespace AlicizaX
{
public interface IProcedureModule:IModule,IModuleUpdate
public interface IProcedureService:IService, IServiceTickable
{
void InitializeProcedure(List<IProcedure> availableProcedures, Type defaultProcedureType);
void ClearAllProcedures();

View File

@ -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
/// </summary>
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<T>() where T : ProcedureBase
{
ProcedureModule.SwitchProcedure<T>();
AppServices.Require<IProcedureService>().SwitchProcedure<T>();
}
}
}

View File

@ -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<IProcedureModule, ProcedureModule>();
AppServices.GetOrCreateScope<AppScope>().Register(new ProcedureService());
}
}
}

View File

@ -4,7 +4,7 @@ using UnityEngine;
namespace AlicizaX
{
internal class ProcedureModule : IProcedureModule
internal class ProcedureService : ServiceBase, IProcedureService
{
private readonly Dictionary<Type, IProcedure> _procedures = new Dictionary<Type, IProcedure>();
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)
{

View File

@ -20,7 +20,7 @@ namespace AlicizaX.Resource.Runtime
return;
}
ModuleSystem.GetModule<IResourceModule>().UnloadAsset(Target);
AppServices.Require<IResourceService>().UnloadAsset(Target);
}
}
}

View File

@ -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<IResourceModule>();
_resourceService = AppServices.Require<IResourceService>();
}
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<T>(location, linkedTokenSource.Token);
T resource = await _resourceService.LoadAssetAsync<T>(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;
}

View File

@ -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<IObjectPoolModule>();
IObjectPoolService objectPoolComponent = AppServices.Require<IObjectPoolService>();
_assetItemPool = objectPoolComponent.CreateMultiSpawnObjectPool<AssetItemObject>(
"SetAssetPool",
autoReleaseInterval, 16, 60, 0);

View File

@ -10,7 +10,7 @@ namespace AlicizaX.Resource.Runtime
/// <summary>
/// 资源管理器接口。
/// </summary>
public interface IResourceModule : IModule
public interface IResourceService : IService
{
/// <summary>
/// 获取当前资源适用的游戏版本号。

View File

@ -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<AssetsRefInfo> refAssetInfoList;
private static IResourceModule _resourceModule;
private static IResourceService _resourceService;
private HashSet<int> _refAssetIds;
private bool TryEnsureResourceModule()
{
if (_resourceModule != null)
if (_resourceService != null)
{
return true;
}
_resourceModule = ModuleSystem.GetModule<IResourceModule>();
return _resourceModule != null;
_resourceService = AppServices.Require<IResourceService>();
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>(T source, IResourceModule resourceModule = null) where T : Object
public AssetsReference Ref<T>(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<AssetsReference>().Ref(source, resourceModule);
return instance.AddComponent<AssetsReference>().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<AssetsReference>();
return comp ? comp.Ref(source, resourceModule) : instance.AddComponent<AssetsReference>().Ref(source, resourceModule);
return comp ? comp.Ref(source, resourceService) : instance.AddComponent<AssetsReference>().Ref(source, resourceService);
}
public static AssetsReference Ref<T>(T source, GameObject instance, IResourceModule resourceModule = null) where T : Object
public static AssetsReference Ref<T>(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<AssetsReference>();
return comp ? comp.Ref(source, resourceModule) : instance.AddComponent<AssetsReference>().Ref(source, resourceModule);
return comp ? comp.Ref(source, resourceService) : instance.AddComponent<AssetsReference>().Ref(source, resourceService);
}
}
}

View File

@ -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<IResourceModule>();
_resourceService = AppServices.Require<IResourceService>();
}
}
@ -29,17 +29,17 @@ namespace AlicizaX.Resource.Runtime
if (!isAsync)
{
Material material = _resourceModule.LoadAsset<Material>(location, packageName);
Material material = _resourceService.LoadAsset<Material>(location, packageName);
image.material = material;
AssetsReference.Ref(material, image.gameObject);
}
else
{
_resourceModule.LoadAsset<Material>(location, material =>
_resourceService.LoadAsset<Material>(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<Material>(location, packageName);
Material material = _resourceService.LoadAsset<Material>(location, packageName);
spriteRenderer.material = material;
AssetsReference.Ref(material, spriteRenderer.gameObject);
}
else
{
_resourceModule.LoadAsset<Material>(location, material =>
_resourceService.LoadAsset<Material>(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<Material>(location, packageName);
Material material = _resourceService.LoadAsset<Material>(location, packageName);
meshRenderer.material = needInstance ? Object.Instantiate(material) : material;
AssetsReference.Ref(material, meshRenderer.gameObject);
}
else
{
_resourceModule.LoadAsset<Material>(location, material =>
_resourceService.LoadAsset<Material>(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<Material>(location, packageName);
Material material = _resourceService.LoadAsset<Material>(location, packageName);
meshRenderer.sharedMaterial = material;
AssetsReference.Ref(material, meshRenderer.gameObject);
}
else
{
_resourceModule.LoadAsset<Material>(location, material =>
_resourceService.LoadAsset<Material>(location, material =>
{
if (meshRenderer == null || meshRenderer.gameObject == null)
{
_resourceModule.UnloadAsset(material);
_resourceService.UnloadAsset(material);
material = null;
return;
}

View File

@ -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
/// <summary>
/// 获取当前资源适用的游戏版本号。
/// </summary>
public string ApplicableGameVersion => _resourceModule.ApplicableGameVersion;
public string ApplicableGameVersion => _resourceService.ApplicableGameVersion;
/// <summary>
/// 获取当前内部资源版本号。
/// </summary>
public int InternalResourceVersion => _resourceModule.InternalResourceVersion;
public int InternalResourceVersion => _resourceService.InternalResourceVersion;
/// <summary>
/// 获取或设置无用资源释放的最小间隔时间,以秒为单位。
@ -146,8 +146,8 @@ namespace AlicizaX.Resource.Runtime
/// </summary>
public float AssetAutoReleaseInterval
{
get => _resourceModule.AssetAutoReleaseInterval;
set => _resourceModule.AssetAutoReleaseInterval = assetAutoReleaseInterval = value;
get => _resourceService.AssetAutoReleaseInterval;
set => _resourceService.AssetAutoReleaseInterval = assetAutoReleaseInterval = value;
}
/// <summary>
@ -155,8 +155,8 @@ namespace AlicizaX.Resource.Runtime
/// </summary>
public int AssetCapacity
{
get => _resourceModule.AssetCapacity;
set => _resourceModule.AssetCapacity = assetCapacity = value;
get => _resourceService.AssetCapacity;
set => _resourceService.AssetCapacity = assetCapacity = value;
}
/// <summary>
@ -164,8 +164,8 @@ namespace AlicizaX.Resource.Runtime
/// </summary>
public float AssetExpireTime
{
get => _resourceModule.AssetExpireTime;
set => _resourceModule.AssetExpireTime = assetExpireTime = value;
get => _resourceService.AssetExpireTime;
set => _resourceService.AssetExpireTime = assetExpireTime = value;
}
/// <summary>
@ -173,8 +173,8 @@ namespace AlicizaX.Resource.Runtime
/// </summary>
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<IResourceModule, ResourceModule>();
_resourceService = AppServices.GetOrCreateScope<AppScope>().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();
}
}

View File

@ -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
{
/// <summary>
/// 资源对象。
@ -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>();
assetObject.Initialize(name, target);
assetObject.m_AssetHandle = (AssetHandle)assetHandle;
assetObject._mResourceModule = resourceModule;
assetObject._resourceService = resourceService;
return assetObject;
}

View File

@ -4,7 +4,7 @@ using YooAsset;
namespace AlicizaX.Resource.Runtime
{
internal partial class ResourceModule
internal partial class ResourceService
{
/// <summary>
/// 根据运行模式创建初始化操作数据

View File

@ -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<AssetObject> _assetPool;
@ -59,13 +59,9 @@ namespace AlicizaX.Resource.Runtime
/// 设置对象池管理器。
/// </summary>
/// <param name="objectPoolModule">对象池管理器。</param>
public void SetObjectPoolModule(IObjectPoolModule objectPoolModule)
public void CreateAssetPool( )
{
if (objectPoolModule == null)
{
throw new GameFrameworkException("Object pool manager is invalid.");
}
_assetPool = objectPoolModule.CreateMultiSpawnObjectPool<AssetObject>("Asset Pool");
_assetPool = Context.Require<IObjectPoolService>().CreateMultiSpawnObjectPool<AssetObject>("Asset Pool");
}
}
}

View File

@ -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
/// <summary>
/// 资源管理器。
/// </summary>
internal sealed partial class ResourceModule : IResourceModule
internal sealed partial class ResourceService : ServiceBase, IResourceService
{
/// <summary>
/// 默认资源包名称。
@ -111,12 +111,15 @@ namespace AlicizaX.Resource.Runtime
DefaultPackage = defaultPackage;
PackageMap[packageName] = defaultPackage;
IObjectPoolModule objectPoolModule = ModuleSystem.GetModule<IObjectPoolModule>();
SetObjectPoolModule(objectPoolModule);
CreateAssetPool();
}
void IModule.Dispose()
protected override void OnInitialize()
{
}
protected override void OnDestroyService()
{
foreach (var loadingOperation in _assetLoadingOperations.Values)
{

View File

@ -7,7 +7,7 @@ using YooAsset;
namespace AlicizaX.Scene.Runtime
{
public interface ISceneModule : IModule,IModuleAwake
public interface ISceneService : IService
{
/// <summary>
/// 当前主场景名称。

View File

@ -10,7 +10,7 @@ namespace AlicizaX.Scene.Runtime
{
private void Awake()
{
ModuleSystem.RegisterModule<ISceneModule,SceneModule>();
AppServices.GetOrCreateScope<AppScope>().Register(new SceneService());
}
}
}

View File

@ -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
/// </summary>
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<IResourceModule>().ForceUnloadUnusedAssets(gcCollect);
Context.Require<IResourceService>().ForceUnloadUnusedAssets(gcCollect);
_handlingScene.Remove(location);
@ -191,7 +191,7 @@ namespace AlicizaX.Scene.Runtime
InvokeProgress(_currentMainScene, progressCallBack).Forget();
}
ModuleSystem.GetModule<IResourceModule>().ForceUnloadUnusedAssets(gcCollect);
Context.Require<IResourceService>().ForceUnloadUnusedAssets(gcCollect);
}
}

View File

@ -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);

Some files were not shown because too many files have changed in this diff Show More