(client) chore:Rearrange source file structure
This commit is contained in:
@ -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<ITick> ticks = new();
|
||||
public bool pause;
|
||||
public List<ITickPhysics> tickPhysics = new();
|
||||
public List<ITick> ticks = new();
|
||||
public List<ITickUI> 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<Clock>();
|
||||
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();
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 初始化方法
|
||||
/// 初始化方法
|
||||
/// </summary>
|
||||
public void Init()
|
||||
{
|
||||
@ -73,52 +113,12 @@ namespace Cell
|
||||
tickPhysics.Clear();
|
||||
tickUIs.Clear();
|
||||
|
||||
foreach (var obj in UnityEngine.Object.FindObjectsByType<MonoBehaviour>(FindObjectsSortMode.None))
|
||||
foreach (var obj in FindObjectsByType<MonoBehaviour>(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e255bfd5da1971b47bd84828bf348d0c
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f07f237520336f549bf53af368893863
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -1,11 +0,0 @@
|
||||
|
||||
|
||||
namespace Cell
|
||||
{
|
||||
public interface ITick
|
||||
{
|
||||
public void Tick()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
@ -1,2 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3897d32ba1dc53c4ca44915fd7372a99
|
@ -1,9 +0,0 @@
|
||||
namespace Cell
|
||||
{
|
||||
public interface ITickPhysics
|
||||
{
|
||||
public void TickPhysics()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
@ -1,2 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 13a5a7579420a2a43bdb17c2f7e586f5
|
@ -1,9 +0,0 @@
|
||||
namespace Cell
|
||||
{
|
||||
public interface ITickUI
|
||||
{
|
||||
public void TickUI()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
@ -1,2 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: db424d45aa0c9dd41b739434758b274a
|
@ -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("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD>ӳ<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>");
|
||||
// Debug.Log("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD>ӳ<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>");
|
||||
// }
|
||||
// timer += Time.deltaTime;
|
||||
//}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user