update samples

This commit is contained in:
hevinci
2022-11-26 17:39:52 +08:00
parent f31e5e0d22
commit f6f326119c
17 changed files with 169 additions and 108 deletions
@@ -22,6 +22,7 @@ namespace UniFramework.Event
}
private static bool _isInitialize = false;
private static GameObject _driver = null;
private static readonly Dictionary<int, LinkedList<Action<IEventMessage>>> _listeners = new Dictionary<int, LinkedList<Action<IEventMessage>>>(1000);
private static readonly List<PostWrapper> _postingList = new List<PostWrapper>(1000);
@@ -37,9 +38,26 @@ namespace UniFramework.Event
{
// 创建驱动器
_isInitialize = true;
GameObject driver = new UnityEngine.GameObject($"[{nameof(UniEvent)}]");
driver.AddComponent<UniEventDriver>();
UnityEngine.Object.DontDestroyOnLoad(driver);
_driver = new UnityEngine.GameObject($"[{nameof(UniEvent)}]");
_driver.AddComponent<UniEventDriver>();
UnityEngine.Object.DontDestroyOnLoad(_driver);
UniLogger.Log($"{nameof(UniEvent)} initalize !");
}
}
/// <summary>
/// 销毁事件系统
/// </summary>
public static void Destroy()
{
if (_isInitialize)
{
ClearAll();
_isInitialize = false;
if (_driver != null)
GameObject.Destroy(_driver);
UniLogger.Log($"{nameof(UniEvent)} destroy all !");
}
}
@@ -59,21 +77,6 @@ namespace UniFramework.Event
}
}
/// <summary>
/// 销毁事件系统
/// </summary>
internal static void Destroy()
{
if (_isInitialize)
{
_isInitialize = false;
ClearAll();
UniLogger.Log($"{nameof(UniEvent)} destroy all !");
}
}
/// <summary>
/// 清空所有监听
/// </summary>
@@ -8,10 +8,5 @@ namespace UniFramework.Event
{
UniEvent.Update();
}
void OnDestroy()
{
UniEvent.Destroy();
}
}
}
@@ -1,3 +1,3 @@
# UniFramework.Event
# UniFramework.Machine
一个轻量级的状态机。
@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 19d466eecc32f6a478d64f6a78748b23
guid: 40fe73297598be84fb8dadedd4dd17e6
MonoImporter:
externalObjects: {}
serializedVersion: 2
@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 5999045dd15678e4bbaca21f460ea0e6
guid: bcbf86a86eb115a41b6aa61fb0945d43
MonoImporter:
externalObjects: {}
serializedVersion: 2
@@ -20,6 +20,7 @@ namespace UniFramework.Module
}
private static bool _isInitialize = false;
private static GameObject _driver = null;
private static readonly List<Wrapper> _wrappers = new List<Wrapper>(100);
private static MonoBehaviour _behaviour;
private static bool _isDirty = false;
@@ -36,9 +37,26 @@ namespace UniFramework.Module
{
// 创建驱动器
_isInitialize = true;
GameObject driver = new UnityEngine.GameObject($"[{nameof(UniModule)}]");
_behaviour = driver.AddComponent<UniModuleDriver>();
UnityEngine.Object.DontDestroyOnLoad(driver);
_driver = new UnityEngine.GameObject($"[{nameof(UniModule)}]");
_behaviour = _driver.AddComponent<UniModuleDriver>();
UnityEngine.Object.DontDestroyOnLoad(_driver);
UniLogger.Log($"{nameof(UniModule)} initalize !");
}
}
/// <summary>
/// 销毁模块系统
/// </summary>
public static void Destroy()
{
if (_isInitialize)
{
DestroyAll();
_isInitialize = false;
if (_driver != null)
GameObject.Destroy(_driver);
UniLogger.Log($"{nameof(UniModule)} destroy all !");
}
}
@@ -69,20 +87,6 @@ namespace UniFramework.Module
}
}
/// <summary>
/// 销毁模块系统
/// </summary>
internal static void Destroy()
{
if (_isInitialize)
{
_isInitialize = false;
DestroyAll();
UniLogger.Log($"{nameof(UniModule)} destroy all !");
}
}
/// <summary>
/// 获取模块
/// </summary>
@@ -8,10 +8,5 @@ namespace UniFramework.Module
{
UniModule.Update();
}
void OnDestroy()
{
UniModule.Destroy();
}
}
}
@@ -12,8 +12,8 @@ namespace UniFramework.Pooling
public static class UniPooling
{
private static bool _isInitialize = false;
private static GameObject _driver = null;
private static readonly List<Spawner> _spawners = new List<Spawner>();
private static GameObject _poolingRoot;
/// <summary>
@@ -28,9 +28,30 @@ namespace UniFramework.Pooling
{
// 创建驱动器
_isInitialize = true;
_poolingRoot = new UnityEngine.GameObject($"[{nameof(UniPooling)}]");
_poolingRoot.AddComponent<UniPoolingDriver>();
UnityEngine.Object.DontDestroyOnLoad(_poolingRoot);
_driver = new UnityEngine.GameObject($"[{nameof(UniPooling)}]");
_driver.AddComponent<UniPoolingDriver>();
UnityEngine.Object.DontDestroyOnLoad(_driver);
UniLogger.Log($"{nameof(UniPooling)} initalize !");
}
}
/// <summary>
/// 销毁游戏对象池系统
/// </summary>
public static void Destroy()
{
if (_isInitialize)
{
foreach (var spawner in _spawners)
{
spawner.Destroy();
}
_spawners.Clear();
_isInitialize = false;
if (_driver != null)
GameObject.Destroy(_driver);
UniLogger.Log($"{nameof(UniPooling)} destroy all !");
}
}
@@ -48,25 +69,6 @@ namespace UniFramework.Pooling
}
}
/// <summary>
/// 销毁游戏对象池系统
/// </summary>
internal static void Destroy()
{
if (_isInitialize)
{
foreach (var spawner in _spawners)
{
spawner.Destroy();
}
_spawners.Clear();
_isInitialize = false;
UniLogger.Log($"{nameof(UniPooling)} destroy all !");
}
}
/// <summary>
/// 创建游戏对象生成器
/// </summary>
@@ -87,7 +89,7 @@ namespace UniFramework.Pooling
if (HasSpawner(packageName))
return GetSpawner(packageName);
Spawner spawner = new Spawner(_poolingRoot, assetPackage);
Spawner spawner = new Spawner(_driver, assetPackage);
_spawners.Add(spawner);
return spawner;
}
@@ -8,10 +8,5 @@ namespace UniFramework.Pooling
{
UniPooling.Update();
}
void OnDestroy()
{
UniPooling.Destroy();
}
}
}
@@ -17,6 +17,7 @@ namespace UniFramework.Window
}
private static bool _isInitialize = false;
private static GameObject _driver = null;
private static readonly List<UIWindow> _stack = new List<UIWindow>(100);
internal static GameObject Desktop { private set; get; }
@@ -35,14 +36,31 @@ namespace UniFramework.Window
{
// 创建驱动器
_isInitialize = true;
GameObject driver = new UnityEngine.GameObject($"[{nameof(UniWindow)}]");
driver.AddComponent<UniWindowDriver>();
UnityEngine.Object.DontDestroyOnLoad(driver);
_driver = new UnityEngine.GameObject($"[{nameof(UniWindow)}]");
_driver.AddComponent<UniWindowDriver>();
UnityEngine.Object.DontDestroyOnLoad(_driver);
UniLogger.Log($"{nameof(UniWindow)} initalize !");
Desktop = desktop;
}
}
/// <summary>
/// 销毁界面系统
/// </summary>
public static void Destroy()
{
if (_isInitialize)
{
CloseAll();
_isInitialize = false;
if (_driver != null)
GameObject.Destroy(_driver);
UniLogger.Log($"{nameof(UniWindow)} destroy all !");
}
}
/// <summary>
/// 更新界面系统
/// </summary>
@@ -61,20 +79,6 @@ namespace UniFramework.Window
}
}
/// <summary>
/// 销毁界面系统
/// </summary>
internal static void Destroy()
{
if (_isInitialize)
{
_isInitialize = false;
CloseAll();
UniLogger.Log($"{nameof(UniWindow)} destroy all !");
}
}
/// <summary>
/// 设置屏幕安全区域(异形屏支持)
/// </summary>
@@ -8,10 +8,5 @@ namespace UniFramework.Window
{
UniWindow.Update();
}
void OnDestroy()
{
UniWindow.Destroy();
}
}
}