From 73a916abba1618591fb01bc3ffbadd8ab7108d95 Mon Sep 17 00:00:00 2001 From: ALEXTANG <574809918@qq.com> Date: Mon, 23 May 2022 20:08:38 +0800 Subject: [PATCH] GameTime.StartFrame MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit GameTime.StartFrame 统一游戏内的时间帧数 --- Assets/TEngine/Runtime/Core/GameTime.cs | 37 +++++++++++++++++++ Assets/TEngine/Runtime/Core/TEngine.cs | 8 ++++ .../src/TEngineCore/Core/GameTime.cs | 6 +++ .../src/TEngineCore/Core/TEngine.cs | 8 ++++ .../src/TEngineCore/Net/GameClient.cs | 3 -- 5 files changed, 59 insertions(+), 3 deletions(-) create mode 100644 Assets/TEngine/Runtime/Core/GameTime.cs diff --git a/Assets/TEngine/Runtime/Core/GameTime.cs b/Assets/TEngine/Runtime/Core/GameTime.cs new file mode 100644 index 00000000..0aee6ff7 --- /dev/null +++ b/Assets/TEngine/Runtime/Core/GameTime.cs @@ -0,0 +1,37 @@ +using UnityEngine; + +namespace TEngine +{ + /// + /// 统一获取游戏内的时间处理,减少多处调用Unity的时间函数 + /// + public static class GameTime + { + /// + /// 这一帧的记录 + /// + public static void StartFrame() + { + time = Time.time; + deltaTime = Time.deltaTime; + quickRealTime = Time.realtimeSinceStartup; + frameCount = Time.frameCount; + unscaledTime = Time.unscaledTime; + } + + public static float time; + public static float deltaTime; + public static int frameCount; + public static float unscaledTime; + + public static float realtimeSinceStartup + { + get + { + return Time.realtimeSinceStartup; + } + } + + public static float quickRealTime; + } +} \ No newline at end of file diff --git a/Assets/TEngine/Runtime/Core/TEngine.cs b/Assets/TEngine/Runtime/Core/TEngine.cs index 43d3f067..acd4893e 100644 --- a/Assets/TEngine/Runtime/Core/TEngine.cs +++ b/Assets/TEngine/Runtime/Core/TEngine.cs @@ -19,6 +19,8 @@ namespace TEngine RegisterAllSystem(); AfterAwake(); + + GameTime.StartFrame(); } /// @@ -72,6 +74,7 @@ namespace TEngine #region 生命周期 public void Start() { + GameTime.StartFrame(); var listLogic = m_LogicMgrList; var logicCnt = listLogic.Count; for (int i = 0; i < logicCnt; i++) @@ -85,6 +88,7 @@ namespace TEngine public void Update() { + GameTime.StartFrame(); var listLogic = m_LogicMgrList; var logicCnt = listLogic.Count; for (int i = 0; i < logicCnt; i++) @@ -96,6 +100,7 @@ namespace TEngine public void LateUpdate() { + GameTime.StartFrame(); var listLogic = m_LogicMgrList; var logicCnt = listLogic.Count; for (int i = 0; i < logicCnt; i++) @@ -107,6 +112,7 @@ namespace TEngine public void OnPause() { + GameTime.StartFrame(); for (int i = 0; i < m_LogicMgrList.Count; i++) { var logicSys = m_LogicMgrList[i]; @@ -116,6 +122,7 @@ namespace TEngine public void OnResume() { + GameTime.StartFrame(); for (int i = 0; i < m_LogicMgrList.Count; i++) { var logicSys = m_LogicMgrList[i]; @@ -125,6 +132,7 @@ namespace TEngine protected override void OnDestroy() { + GameTime.StartFrame(); for (int i = 0; i < m_LogicMgrList.Count; i++) { var logicSys = m_LogicMgrList[i]; diff --git a/TEngineHotUpdate/src/TEngineCore/Core/GameTime.cs b/TEngineHotUpdate/src/TEngineCore/Core/GameTime.cs index 3c3eda80..a6c158d0 100644 --- a/TEngineHotUpdate/src/TEngineCore/Core/GameTime.cs +++ b/TEngineHotUpdate/src/TEngineCore/Core/GameTime.cs @@ -2,8 +2,14 @@ namespace TEngineCore { + /// + /// 统一获取游戏内的时间处理,减少多处调用Unity的时间函数 + /// public static class GameTime { + /// + /// 这一帧的记录 + /// public static void StartFrame() { time = Time.time; diff --git a/TEngineHotUpdate/src/TEngineCore/Core/TEngine.cs b/TEngineHotUpdate/src/TEngineCore/Core/TEngine.cs index 454c1615..be8545fe 100644 --- a/TEngineHotUpdate/src/TEngineCore/Core/TEngine.cs +++ b/TEngineHotUpdate/src/TEngineCore/Core/TEngine.cs @@ -19,6 +19,8 @@ namespace TEngineCore RegisterAllSystem(); AfterAwake(); + + GameTime.StartFrame(); } /// @@ -72,6 +74,7 @@ namespace TEngineCore #region 生命周期 public void Start() { + GameTime.StartFrame(); var listLogic = m_LogicMgrList; var logicCnt = listLogic.Count; for (int i = 0; i < logicCnt; i++) @@ -85,6 +88,7 @@ namespace TEngineCore public void Update() { + GameTime.StartFrame(); var listLogic = m_LogicMgrList; var logicCnt = listLogic.Count; for (int i = 0; i < logicCnt; i++) @@ -96,6 +100,7 @@ namespace TEngineCore public void LateUpdate() { + GameTime.StartFrame(); var listLogic = m_LogicMgrList; var logicCnt = listLogic.Count; for (int i = 0; i < logicCnt; i++) @@ -107,6 +112,7 @@ namespace TEngineCore public void OnPause() { + GameTime.StartFrame(); for (int i = 0; i < m_LogicMgrList.Count; i++) { var logicSys = m_LogicMgrList[i]; @@ -116,6 +122,7 @@ namespace TEngineCore public void OnResume() { + GameTime.StartFrame(); for (int i = 0; i < m_LogicMgrList.Count; i++) { var logicSys = m_LogicMgrList[i]; @@ -125,6 +132,7 @@ namespace TEngineCore protected override void OnDestroy() { + GameTime.StartFrame(); for (int i = 0; i < m_LogicMgrList.Count; i++) { var logicSys = m_LogicMgrList[i]; diff --git a/TEngineHotUpdate/src/TEngineCore/Net/GameClient.cs b/TEngineHotUpdate/src/TEngineCore/Net/GameClient.cs index c068cf84..170231fc 100644 --- a/TEngineHotUpdate/src/TEngineCore/Net/GameClient.cs +++ b/TEngineHotUpdate/src/TEngineCore/Net/GameClient.cs @@ -1,8 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using TEngineProto; using UnityEngine;