diff --git a/Client/Assets/Scripts/Base/Clock.cs b/Client/Assets/Scripts/Base/Clock.cs index 75e745f..e51a0d8 100644 --- a/Client/Assets/Scripts/Base/Clock.cs +++ b/Client/Assets/Scripts/Base/Clock.cs @@ -1,17 +1,36 @@ - - using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement; -namespace Cell +namespace Base { + public interface ITick + { + public void Tick() + { + } + } + + public interface ITickPhysics + { + public void TickPhysics() + { + } + } + + public interface ITickUI + { + public void TickUI() + { + } + } + public class Clock : MonoBehaviour { private static Clock _instance; - public bool pause = false; - public List ticks = new(); + public bool pause; public List tickPhysics = new(); + public List ticks = new(); public List tickUIs = new(); //float timer = 0; @@ -27,17 +46,17 @@ namespace Cell // 如果不存在,创建一个新的 if (_instance == null) { - GameObject clockObject = new GameObject("[Clock]"); + var clockObject = new GameObject("[Clock]"); _instance = clockObject.AddComponent(); DontDestroyOnLoad(clockObject); // 确保对象不被销毁 } } + return _instance; } } - private void Awake() { // 确保只有一个实例存在 @@ -51,6 +70,28 @@ namespace Cell SceneManager.sceneLoaded += OnSceneLoaded; // 注册场景加载事件 } + private void Update() + { + if (!pause) + foreach (var tick in ticks) + tick.Tick(); + + foreach (var uiTick in tickUIs) uiTick.TickUI(); + //if (timer > 1) + //{ + // timer -= 1; + // Debug.Log("滴答"); + //} + //timer += Time.deltaTime; + } + + private void FixedUpdate() + { + if (!pause) + foreach (var physicsTick in tickPhysics) + physicsTick.TickPhysics(); + } + private void OnDestroy() { // 移除事件监听 @@ -61,11 +102,10 @@ namespace Cell { // 场景加载完成后调用 Init 方法 Init(); - } /// - /// 初始化方法 + /// 初始化方法 /// public void Init() { @@ -73,52 +113,12 @@ namespace Cell tickPhysics.Clear(); tickUIs.Clear(); - foreach (var obj in UnityEngine.Object.FindObjectsByType(FindObjectsSortMode.None)) + foreach (var obj in FindObjectsByType(FindObjectsSortMode.None)) { - if (obj is ITick tickObj) - { - ticks.Add(tickObj); - } - if (obj is ITickPhysics physicsObj) - { - tickPhysics.Add(physicsObj); - } - if (obj is ITickUI uiObj) - { - tickUIs.Add(uiObj); - } - } - } - - private void Update() - { - if (!pause) - { - foreach (var tick in ticks) - { - tick.Tick(); - } - } - foreach (var uiTick in tickUIs) - { - uiTick.TickUI(); - } - //if (timer > 1) - //{ - // timer -= 1; - // Debug.Log("滴答"); - //} - //timer += Time.deltaTime; - } - void FixedUpdate() - { - if(!pause) - { - foreach (var physicsTick in tickPhysics) - { - physicsTick.TickPhysics(); - } + if (obj is ITick tickObj) ticks.Add(tickObj); + if (obj is ITickPhysics physicsObj) tickPhysics.Add(physicsObj); + if (obj is ITickUI uiObj) tickUIs.Add(uiObj); } } } -} +} \ No newline at end of file diff --git a/Client/Assets/Scripts/Interface.meta b/Client/Assets/Scripts/Interface.meta deleted file mode 100644 index 24f6ac9..0000000 --- a/Client/Assets/Scripts/Interface.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: e255bfd5da1971b47bd84828bf348d0c -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Client/Assets/Scripts/Interface/Tick.meta b/Client/Assets/Scripts/Interface/Tick.meta deleted file mode 100644 index 953535b..0000000 --- a/Client/Assets/Scripts/Interface/Tick.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: f07f237520336f549bf53af368893863 -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Client/Assets/Scripts/Interface/Tick/ITick.cs b/Client/Assets/Scripts/Interface/Tick/ITick.cs deleted file mode 100644 index 4e50016..0000000 --- a/Client/Assets/Scripts/Interface/Tick/ITick.cs +++ /dev/null @@ -1,11 +0,0 @@ - - -namespace Cell -{ - public interface ITick - { - public void Tick() - { - } - } -} diff --git a/Client/Assets/Scripts/Interface/Tick/ITick.cs.meta b/Client/Assets/Scripts/Interface/Tick/ITick.cs.meta deleted file mode 100644 index 7678188..0000000 --- a/Client/Assets/Scripts/Interface/Tick/ITick.cs.meta +++ /dev/null @@ -1,2 +0,0 @@ -fileFormatVersion: 2 -guid: 3897d32ba1dc53c4ca44915fd7372a99 \ No newline at end of file diff --git a/Client/Assets/Scripts/Interface/Tick/ITickPhysics.cs b/Client/Assets/Scripts/Interface/Tick/ITickPhysics.cs deleted file mode 100644 index 422333c..0000000 --- a/Client/Assets/Scripts/Interface/Tick/ITickPhysics.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace Cell -{ - public interface ITickPhysics - { - public void TickPhysics() - { - } - } -} diff --git a/Client/Assets/Scripts/Interface/Tick/ITickPhysics.cs.meta b/Client/Assets/Scripts/Interface/Tick/ITickPhysics.cs.meta deleted file mode 100644 index e4fbfe1..0000000 --- a/Client/Assets/Scripts/Interface/Tick/ITickPhysics.cs.meta +++ /dev/null @@ -1,2 +0,0 @@ -fileFormatVersion: 2 -guid: 13a5a7579420a2a43bdb17c2f7e586f5 \ No newline at end of file diff --git a/Client/Assets/Scripts/Interface/Tick/ITickUI.cs b/Client/Assets/Scripts/Interface/Tick/ITickUI.cs deleted file mode 100644 index 57ab47d..0000000 --- a/Client/Assets/Scripts/Interface/Tick/ITickUI.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace Cell -{ - public interface ITickUI - { - public void TickUI() - { - } - } -} \ No newline at end of file diff --git a/Client/Assets/Scripts/Interface/Tick/ITickUI.cs.meta b/Client/Assets/Scripts/Interface/Tick/ITickUI.cs.meta deleted file mode 100644 index 9268b24..0000000 --- a/Client/Assets/Scripts/Interface/Tick/ITickUI.cs.meta +++ /dev/null @@ -1,2 +0,0 @@ -fileFormatVersion: 2 -guid: db424d45aa0c9dd41b739434758b274a \ No newline at end of file diff --git a/Client/Assets/Scripts/Test/InitClock.cs b/Client/Assets/Scripts/Test/InitClock.cs index 62d968a..330b864 100644 --- a/Client/Assets/Scripts/Test/InitClock.cs +++ b/Client/Assets/Scripts/Test/InitClock.cs @@ -1,15 +1,16 @@ +using Base; using UnityEngine; -using UnityEngine.SceneManagement; -namespace Cell +namespace Test { public class InitClock : MonoBehaviour { - static float timer = 0; + private static float timer = 0; + // Start is called once before the first execution of Update after the MonoBehaviour is created - void Start() + private void Start() { - var clock= Clock.Instance; + var clock = Clock.Instance; } // Update is called once per frame @@ -22,9 +23,9 @@ namespace Cell // if (timer > 1) // { // timer -= 1; - // Debug.Log("ʱӳʼ"); + // Debug.Log("��������ʱ�ӳ�ʼ����"); // } // timer += Time.deltaTime; //} } -} +} \ No newline at end of file