From 385d789c969b39c3972fc79a00f06be650b4b110 Mon Sep 17 00:00:00 2001 From: ALEXTANG <574809918@qq.com> Date: Thu, 20 Apr 2023 19:33:35 +0800 Subject: [PATCH 1/5] Create GameTickWatcher.meta --- Assets/GameScripts/HotFix/GameBase/GameTickWatcher.meta | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 Assets/GameScripts/HotFix/GameBase/GameTickWatcher.meta diff --git a/Assets/GameScripts/HotFix/GameBase/GameTickWatcher.meta b/Assets/GameScripts/HotFix/GameBase/GameTickWatcher.meta new file mode 100644 index 00000000..cdcc2e6b --- /dev/null +++ b/Assets/GameScripts/HotFix/GameBase/GameTickWatcher.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: b062b3e32edd4536a4308a3d180842e0 +timeCreated: 1681989133 \ No newline at end of file From 069c5b93e0b5aa29d55c4fa85fd1c3a3e6ff1690 Mon Sep 17 00:00:00 2001 From: ALEXTANG <574809918@qq.com> Date: Thu, 20 Apr 2023 19:34:01 +0800 Subject: [PATCH 2/5] [+] GameTickWacher [+] GameTickWacher --- .../GameTickWatcher/GameTickWatcher.cs | 40 +++++++++++++++++++ .../GameTickWatcher/GameTickWatcher.cs.meta | 3 ++ .../GameBase/{ => Singleton}/Singleton.cs | 9 ++++- .../{ => Singleton}/Singleton.cs.meta | 0 4 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 Assets/GameScripts/HotFix/GameBase/GameTickWatcher/GameTickWatcher.cs create mode 100644 Assets/GameScripts/HotFix/GameBase/GameTickWatcher/GameTickWatcher.cs.meta rename Assets/GameScripts/HotFix/GameBase/{ => Singleton}/Singleton.cs (70%) rename Assets/GameScripts/HotFix/GameBase/{ => Singleton}/Singleton.cs.meta (100%) diff --git a/Assets/GameScripts/HotFix/GameBase/GameTickWatcher/GameTickWatcher.cs b/Assets/GameScripts/HotFix/GameBase/GameTickWatcher/GameTickWatcher.cs new file mode 100644 index 00000000..b97f7cac --- /dev/null +++ b/Assets/GameScripts/HotFix/GameBase/GameTickWatcher/GameTickWatcher.cs @@ -0,0 +1,40 @@ +using TEngine; + +namespace GameBase +{ + /// + /// 用来在多线程下检测耗时。 + /// + public struct GameTickWatcher + { + private long _startTick; + + public GameTickWatcher() + { + _startTick = System.DateTime.Now.Ticks; + } + + public void Refresh() + { + _startTick = System.DateTime.Now.Ticks; + } + + /// + /// 获取用时。 + /// + /// + public float ElapseTime() + { + long endTick = System.DateTime.Now.Ticks; + return (float)((endTick - _startTick) / 10000) / 1000.0f; + } + + /// + /// 输出用时。 + /// + public void LogUsedTime() + { + Log.Info($"Used Time: {this.ElapseTime()}"); + } + } +} \ No newline at end of file diff --git a/Assets/GameScripts/HotFix/GameBase/GameTickWatcher/GameTickWatcher.cs.meta b/Assets/GameScripts/HotFix/GameBase/GameTickWatcher/GameTickWatcher.cs.meta new file mode 100644 index 00000000..e05fddec --- /dev/null +++ b/Assets/GameScripts/HotFix/GameBase/GameTickWatcher/GameTickWatcher.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 7320165f7aa147a998a30fe2f7a5a5c2 +timeCreated: 1681989139 \ No newline at end of file diff --git a/Assets/GameScripts/HotFix/GameBase/Singleton.cs b/Assets/GameScripts/HotFix/GameBase/Singleton/Singleton.cs similarity index 70% rename from Assets/GameScripts/HotFix/GameBase/Singleton.cs rename to Assets/GameScripts/HotFix/GameBase/Singleton/Singleton.cs index b8987757..2f14742f 100644 --- a/Assets/GameScripts/HotFix/GameBase/Singleton.cs +++ b/Assets/GameScripts/HotFix/GameBase/Singleton/Singleton.cs @@ -2,9 +2,14 @@ namespace GameBase { - public class Singleton where T:new() + /// + /// 通用单例。 + /// + /// 泛型T。 + public class Singleton where T : new() { private static T _instance; + public static T Instance { get @@ -19,4 +24,4 @@ namespace GameBase } } } -} +} \ No newline at end of file diff --git a/Assets/GameScripts/HotFix/GameBase/Singleton.cs.meta b/Assets/GameScripts/HotFix/GameBase/Singleton/Singleton.cs.meta similarity index 100% rename from Assets/GameScripts/HotFix/GameBase/Singleton.cs.meta rename to Assets/GameScripts/HotFix/GameBase/Singleton/Singleton.cs.meta From ec174377827b4544e56ca4730c1bb17747d6ff51 Mon Sep 17 00:00:00 2001 From: ALEXTANG <574809918@qq.com> Date: Thu, 20 Apr 2023 19:34:13 +0800 Subject: [PATCH 3/5] [+] Loom [+] Loom --- Assets/GameScripts/HotFix/GameBase/Loom.meta | 8 + .../GameScripts/HotFix/GameBase/Loom/Loom.cs | 190 ++++++++++++++++++ .../HotFix/GameBase/Loom/Loom.cs.meta | 11 + 3 files changed, 209 insertions(+) create mode 100644 Assets/GameScripts/HotFix/GameBase/Loom.meta create mode 100644 Assets/GameScripts/HotFix/GameBase/Loom/Loom.cs create mode 100644 Assets/GameScripts/HotFix/GameBase/Loom/Loom.cs.meta diff --git a/Assets/GameScripts/HotFix/GameBase/Loom.meta b/Assets/GameScripts/HotFix/GameBase/Loom.meta new file mode 100644 index 00000000..e104ca98 --- /dev/null +++ b/Assets/GameScripts/HotFix/GameBase/Loom.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: dab5f3e08b4367d41b801af29d381ca8 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/GameScripts/HotFix/GameBase/Loom/Loom.cs b/Assets/GameScripts/HotFix/GameBase/Loom/Loom.cs new file mode 100644 index 00000000..e020612e --- /dev/null +++ b/Assets/GameScripts/HotFix/GameBase/Loom/Loom.cs @@ -0,0 +1,190 @@ +using UnityEngine; +using System.Collections.Generic; +using System; +using System.Threading; +using System.Linq; + +/******************************************************************************* + //开启一个Loom进程 + Loom.RunAsync(() => + { + aucThread = new Thread(ReceiveMsg); + aucThread.Start(); + } + + //进程调用主线程方法 + MainPack pack = (MainPack)MainPack.Descriptor.Parser.ParseFrom(buffer, 0, len); + Loom.QueueOnMainThread((param) => + { + UdpHandleResponse(pack); + }, null); + + *******************************************************************************/ +namespace GameBase +{ + + /// + /// Loom多线程通信。 + /// + /// + public class Loom : MonoBehaviour + { + public Dictionary TokenSourcesDictionary = new Dictionary(); + private static readonly int MaxThreads = 8; + private static int _numThreads; + private static Loom _current; + + public static Loom Current + { + get + { + Initialize(); + return _current; + } + } + + public void Awake() + { + _current = this; + _initialized = true; + } + + protected void OnDestroy() + { + } + + private static bool _initialized; + + private static void Initialize() + { + if (!_initialized) + { + if (!Application.isPlaying) + { + return; + } + + _initialized = true; + + var obj = new GameObject("[Loom]"); + + _current = obj.AddComponent(); + + DontDestroyOnLoad(obj); + } + } + + public struct NoDelayedQueueItem + { + public Action Action; + public object Param; + } + + private readonly List _actions = new List(); + + public struct DelayedQueueItem + { + public float Time; + public Action Action; + public object Param; + } + + private readonly List _delayed = new List(); + + private readonly List _currentDelayed = new List(); + + public static void QueueOnMainThread(Action taction, object param, float time = 0f) + { + if (time != 0f) + { + lock (Current._delayed) + { + Current._delayed.Add(new DelayedQueueItem { Time = Time.time + time, Action = taction, Param = param }); + } + } + else + { + lock (Current._actions) + { + Current._actions.Add(new NoDelayedQueueItem { Action = taction, Param = param }); + } + } + } + + public static Thread RunAsync(Action action) + { + Initialize(); + while (_numThreads >= MaxThreads) + { + Thread.Sleep(100); + } + + Interlocked.Increment(ref _numThreads); + ThreadPool.QueueUserWorkItem(RunAction, action); + return null; + } + + private static void RunAction(object action) + { + try + { + ((Action)action)(); + } + catch + { + // ignored + } + finally + { + Interlocked.Decrement(ref _numThreads); + } + } + + + void OnDisable() + { + if (_current == this) + { + _current = null; + } + } + + private readonly List _currentActions = new List(); + + void Update() + { + if (_actions.Count > 0) + { + lock (_actions) + { + _currentActions.Clear(); + _currentActions.AddRange(_actions); + _actions.Clear(); + } + + for (int i = 0; i < _currentActions.Count; i++) + { + _currentActions[i].Action(_currentActions[i].Param); + } + } + + if (_delayed.Count > 0) + { + lock (_delayed) + { + _currentDelayed.Clear(); + _currentDelayed.AddRange(_delayed.Where(d => d.Time <= Time.time)); + for (int i = 0; i < _currentDelayed.Count; i++) + { + _delayed.Remove(_currentDelayed[i]); + } + } + + for (int i = 0; i < _currentDelayed.Count; i++) + { + _currentDelayed[i].Action(_currentDelayed[i].Param); + } + } + } + } +} \ No newline at end of file diff --git a/Assets/GameScripts/HotFix/GameBase/Loom/Loom.cs.meta b/Assets/GameScripts/HotFix/GameBase/Loom/Loom.cs.meta new file mode 100644 index 00000000..b89d6a2d --- /dev/null +++ b/Assets/GameScripts/HotFix/GameBase/Loom/Loom.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: eea4adc555e37f842abf5dd24c191d93 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From c850ec359c08457552d866a769b7bec2637d1da2 Mon Sep 17 00:00:00 2001 From: ALEXTANG <574809918@qq.com> Date: Thu, 20 Apr 2023 19:34:37 +0800 Subject: [PATCH 4/5] [+] SingletonSystem [+] SingletonSystem --- .../HotFix/GameBase/Singleton.meta | 3 + .../HotFix/GameBase/Singleton/TSingleton.cs | 214 ++++++++++++++++++ .../GameBase/Singleton/TSingleton.cs.meta | 3 + .../GameBase/Singleton/UnitySingleton.cs | 111 +++++++++ .../GameBase/Singleton/UnitySingleton.cs.meta | 3 + 5 files changed, 334 insertions(+) create mode 100644 Assets/GameScripts/HotFix/GameBase/Singleton.meta create mode 100644 Assets/GameScripts/HotFix/GameBase/Singleton/TSingleton.cs create mode 100644 Assets/GameScripts/HotFix/GameBase/Singleton/TSingleton.cs.meta create mode 100644 Assets/GameScripts/HotFix/GameBase/Singleton/UnitySingleton.cs create mode 100644 Assets/GameScripts/HotFix/GameBase/Singleton/UnitySingleton.cs.meta diff --git a/Assets/GameScripts/HotFix/GameBase/Singleton.meta b/Assets/GameScripts/HotFix/GameBase/Singleton.meta new file mode 100644 index 00000000..614abc11 --- /dev/null +++ b/Assets/GameScripts/HotFix/GameBase/Singleton.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 00565f0d362f4c36836804455e19c3df +timeCreated: 1681990210 \ No newline at end of file diff --git a/Assets/GameScripts/HotFix/GameBase/Singleton/TSingleton.cs b/Assets/GameScripts/HotFix/GameBase/Singleton/TSingleton.cs new file mode 100644 index 00000000..7a1f0fb0 --- /dev/null +++ b/Assets/GameScripts/HotFix/GameBase/Singleton/TSingleton.cs @@ -0,0 +1,214 @@ +using System.Collections.Generic; +using TEngine; +using UnityEngine; +using UnityEngine.SceneManagement; + +namespace GameBase +{ + /// + /// 单例接口。 + /// + public interface ISingleton + { + void Active(); + + void Release(); + } + + /// + /// 单例管理器(统一化持久和释放)。 + /// + public static class SingletonMgr + { + private static List _singletonList; + private static Dictionary _gameObjects; + private static GameObject _root; + + public static GameObject Root + { + get + { + if (_root == null) + { + _root = GameObject.Find("[SingletonMgr]"); + + if (_root == null) + { + _root = new GameObject("[SingletonMgr]") + { + transform = + { + position = Vector3.zero + } + }; + } + UnityEngine.Object.DontDestroyOnLoad(_root); + } + return _root; + } + } + + public static void Retain(ISingleton go) + { + if (_singletonList == null) + { + _singletonList = new List(); + } + + _singletonList.Add(go); + } + + public static void Retain(GameObject go) + { + if (_gameObjects == null) + { + _gameObjects = new Dictionary(); + } + + if (!_gameObjects.ContainsKey(go.name)) + { + _gameObjects.Add(go.name, go); + if (Application.isPlaying) + { + UnityEngine.Object.DontDestroyOnLoad(go); + } + } + } + + public static void Release(GameObject go) + { + if (_gameObjects != null && _gameObjects.ContainsKey(go.name)) + { + _gameObjects.Remove(go.name); + UnityEngine.Object.Destroy(go); + } + } + + public static void Release(ISingleton go) + { + if (_singletonList != null && _singletonList.Contains(go)) + { + _singletonList.Remove(go); + } + } + + public static void Release() + { + if (_gameObjects != null) + { + foreach (var item in _gameObjects) + { + UnityEngine.Object.Destroy(item.Value); + } + + _gameObjects.Clear(); + } + + if (_singletonList != null) + { + for (int i = 0; i < _singletonList.Count; ++i) + { + _singletonList[i].Release(); + } + + _singletonList.Clear(); + } + + Resources.UnloadUnusedAssets(); + } + + public static GameObject GetGameObject(string name) + { + GameObject go = null; + if (_gameObjects != null) + { + _gameObjects.TryGetValue(name, out go); + } + + return go; + } + + internal static bool ContainsKey(string name) + { + if (_gameObjects != null) + { + return _gameObjects.ContainsKey(name); + } + + return false; + } + + internal static ISingleton GetSingleton(string name) + { + for (int i = 0; i < _singletonList.Count; ++i) + { + if (_singletonList[i].ToString() == name) + { + return _singletonList[i]; + } + } + + return null; + } + + /// + /// 释放所有单例。 + /// + public static void ReStart() + { + Release(); + + SceneManager.LoadScene(0); + } + } + + /// + /// 全局单例对象(非线程安全)。 + /// + /// 泛型T。 + public abstract class TSingleton : ISingleton where T : TSingleton, new() + { + private static T _instance; + + public static T Instance + { + get + { + if (null == _instance) + { + _instance = new T(); + _instance.Init(); +#if UNITY_EDITOR + Log.Info($"TSingleton Instance:{typeof(T).Name}"); +#endif + SingletonMgr.Retain(_instance); + } + + return _instance; + } + } + + public static bool IsValid => _instance != null; + + protected TSingleton() + { + } + + protected virtual void Init() + { + } + + public virtual void Active() + { + } + + public virtual void Release() + { + if (_instance != null) + { + SingletonMgr.Release(_instance); + _instance = null; + } + } + } +} \ No newline at end of file diff --git a/Assets/GameScripts/HotFix/GameBase/Singleton/TSingleton.cs.meta b/Assets/GameScripts/HotFix/GameBase/Singleton/TSingleton.cs.meta new file mode 100644 index 00000000..70380313 --- /dev/null +++ b/Assets/GameScripts/HotFix/GameBase/Singleton/TSingleton.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: aa2cb5bb622045d7a6f2a4c4faea3ca6 +timeCreated: 1681989590 \ No newline at end of file diff --git a/Assets/GameScripts/HotFix/GameBase/Singleton/UnitySingleton.cs b/Assets/GameScripts/HotFix/GameBase/Singleton/UnitySingleton.cs new file mode 100644 index 00000000..db28b292 --- /dev/null +++ b/Assets/GameScripts/HotFix/GameBase/Singleton/UnitySingleton.cs @@ -0,0 +1,111 @@ +using TEngine; +using UnityEngine; + +namespace GameBase +{ + /// + /// 具备Unity完整生命周期的单例。 + /// + /// + public abstract class UnitySingleton : MonoBehaviour where T : MonoBehaviour + { + private static T _instance; + + public static T Instance + { + get + { + if (_instance == null) + { + var ins = UnityEngine.Object.FindObjectOfType(); + if (ins != null) + { + var obj = ins.gameObject; + obj.name = typeof(T).Name; + _instance = ins; + SingletonMgr.Retain(obj); + return Instance; + } + + System.Type thisType = typeof(T); + string instName = thisType.Name; + GameObject go = SingletonMgr.GetGameObject(instName); + if (go == null) + { + go = GameObject.Find($"{instName}"); + if (go == null) + { + go = new GameObject(instName); + go.transform.position = Vector3.zero; + } + } + + _instance = go.GetComponent(); + if (_instance == null) + { + _instance = go.AddComponent(); + } + + if (_instance == null) + { + Log.Error($"Can't create UnitySingleton<{typeof(T)}>"); + } + } + + return _instance; + } + } + + public static T Active() + { + return Instance; + } + + public static bool IsValid => _instance != null; + + private bool CheckInstance() + { + if (this == Instance) + { + return true; + } + + GameObject.Destroy(gameObject); + return false; + } + + protected virtual void OnLoad() + { + } + + public virtual void Awake() + { + if (CheckInstance()) + { + OnLoad(); + } +#if UNITY_EDITOR + Log.Debug($"UnitySingleton Instance:{typeof(T).Name}"); +#endif + GameObject tEngine = SingletonMgr.Root; + if (tEngine != null) + { + this.gameObject.transform.SetParent(tEngine.transform); + } + } + + protected virtual void OnDestroy() + { + Release(); + } + + public static void Release() + { + if (_instance != null) + { + SingletonMgr.Release(_instance.gameObject); + _instance = null; + } + } + } +} \ No newline at end of file diff --git a/Assets/GameScripts/HotFix/GameBase/Singleton/UnitySingleton.cs.meta b/Assets/GameScripts/HotFix/GameBase/Singleton/UnitySingleton.cs.meta new file mode 100644 index 00000000..c0330e3f --- /dev/null +++ b/Assets/GameScripts/HotFix/GameBase/Singleton/UnitySingleton.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 25c99243aa534df5870e36fdf9d36afd +timeCreated: 1681990223 \ No newline at end of file From ec25b314e079dabf79ccf7057eccc33f1a275694 Mon Sep 17 00:00:00 2001 From: ALEXTANG <574809918@qq.com> Date: Thu, 20 Apr 2023 19:40:25 +0800 Subject: [PATCH 5/5] [+] Utility.DevicePerformance [+] Utility.DevicePerformance --- .../Utility/Utility.DevicePerformance.cs | 175 ++++++++++++++++++ .../Utility/Utility.DevicePerformance.cs.meta | 3 + 2 files changed, 178 insertions(+) create mode 100644 Assets/TEngine/Runtime/GameFramework/Utility/Utility.DevicePerformance.cs create mode 100644 Assets/TEngine/Runtime/GameFramework/Utility/Utility.DevicePerformance.cs.meta diff --git a/Assets/TEngine/Runtime/GameFramework/Utility/Utility.DevicePerformance.cs b/Assets/TEngine/Runtime/GameFramework/Utility/Utility.DevicePerformance.cs new file mode 100644 index 00000000..81a4eb15 --- /dev/null +++ b/Assets/TEngine/Runtime/GameFramework/Utility/Utility.DevicePerformance.cs @@ -0,0 +1,175 @@ +using UnityEngine; + +namespace TEngine +{ + public static partial class Utility + { + /// + /// 硬件设备性能适配工具相关的实用函数。 + /// + public static class DevicePerformance + { + /// + /// 获取设备性能评级。 + /// + /// 性能评级 + public static DevicePerformanceLevel GetDevicePerformanceLevel() + { + if (SystemInfo.graphicsDeviceVendorID == 32902) + { + //集显 + return DevicePerformanceLevel.Low; + } + else //NVIDIA 系列显卡(N卡)和AMD系列显卡。 + { + //根据目前硬件配置三个平台设置了不一样的评判标准(仅个人意见)。 + //CPU核心数。 +#if UNITY_EDITOR || UNITY_STANDALONE_WIN + if (SystemInfo.processorCount <= 2) +#elif UNITY_STANDALONE_OSX || UNITY_IPHONE + if (SystemInfo.processorCount < 2) +#elif UNITY_ANDROID + if (SystemInfo.processorCount <= 4) +#endif + { + //CPU核心数<=2判定为低端。 + return DevicePerformanceLevel.Low; + } + else + { + //显存。 + int graphicsMemorySize = SystemInfo.graphicsMemorySize; + //内存。 + int systemMemorySize = SystemInfo.systemMemorySize; +#if UNITY_EDITOR || UNITY_STANDALONE_WIN + if (graphicsMemorySize >= 4000 && systemMemorySize >= 8000) + return DevicePerformanceLevel.High; + else if (graphicsMemorySize >= 2000 && systemMemorySize >= 4000) + return DevicePerformanceLevel.Mid; + else + return DevicePerformanceLevel.Low; +#elif UNITY_STANDALONE_OSX || UNITY_IPHONE + if (graphicsMemorySize >= 4000 && systemMemorySize >= 8000) + return DevicePerformanceLevel.High; + else if (graphicsMemorySize >= 2000 && systemMemorySize >= 4000) + return DevicePerformanceLevel.Mid; + else + return DevicePerformanceLevel.Low; +#elif UNITY_ANDROID + if (graphicsMemorySize >= 6000 && systemMemorySize >= 8000) + return DevicePerformanceLevel.High; + else if (graphicsMemorySize >= 2000 && systemMemorySize >= 4000) + return DevicePerformanceLevel.Mid; + else + return DevicePerformanceLevel.Low; +#endif + } + } + } + + /// + /// 根据手机性能修改项目设置。 + /// + /// QualitySettings中对应Low的等级。 + /// QualitySettings中对应Mid的等级。 + /// QualitySettings中对应High的等级。 + public static void ModifySettingsBasedOnPerformance(int lowQuality, int midQuality, int highQuality) + { + DevicePerformanceLevel level = GetDevicePerformanceLevel(); + switch (level) + { + case DevicePerformanceLevel.Low: + QualitySettings.SetQualityLevel(lowQuality, true); + break; + case DevicePerformanceLevel.Mid: + QualitySettings.SetQualityLevel(midQuality, true); + break; + case DevicePerformanceLevel.High: + QualitySettings.SetQualityLevel(highQuality, true); + break; + } + } + + /// + /// 根据机型配置自动设置质量。 + /// + public static void ModifySettingsBasedOnPerformance() + { + DevicePerformanceLevel level = GetDevicePerformanceLevel(); + switch (level) + { + case DevicePerformanceLevel.Low: + SetQualitySettings(QualityLevel.Low); + break; + case DevicePerformanceLevel.Mid: + SetQualitySettings(QualityLevel.Mid); + break; + case DevicePerformanceLevel.High: + SetQualitySettings(QualityLevel.High); + break; + } + } + + /// + /// 根据自身需要调整各级别需要修改的设置,可根据需求修改低中高三种方案某一项具体设置。 + /// + /// 质量等级。 + public static void SetQualitySettings(QualityLevel qualityLevel) + { + switch (qualityLevel) + { + case QualityLevel.Low: + //前向渲染使用的像素灯的最大数量,建议最少为1。 + QualitySettings.pixelLightCount = 2; + //你可以设置使用最大分辨率的纹理或者部分纹理(低分辨率纹理的处理开销低)。选项有 0_完整分辨率,1_1/2分辨率,2_1/4分辨率,3_1/8分辨率。 + QualitySettings.masterTextureLimit = 1; + //设置抗锯齿级别。选项有​​ 0_不开启抗锯齿,2_2倍,4_4倍和8_8倍采样。 + QualitySettings.antiAliasing = 0; + //是否使用粒子软融合 + QualitySettings.softParticles = false; + //启用实时反射探针,此设置需要用的时候再打开。 + QualitySettings.realtimeReflectionProbes = false; + //如果启用,公告牌将面向摄像机位置而不是摄像机方向。似乎与地形系统有关,此处没啥必要打开。 + QualitySettings.billboardsFaceCameraPosition = false; + //设置软硬阴影是否打开 + QualitySettings.shadows = ShadowQuality.Disable; + //设置垂直同步方案,VSyncs数值需要在每帧之间传递,使用0为不等待垂直同步。值必须是0,1或2。 + QualitySettings.vSyncCount = 0; + break; + case QualityLevel.Mid: + QualitySettings.pixelLightCount = 4; + QualitySettings.antiAliasing = 2; + QualitySettings.softParticles = false; + QualitySettings.realtimeReflectionProbes = true; + QualitySettings.billboardsFaceCameraPosition = true; + QualitySettings.shadows = ShadowQuality.HardOnly; + QualitySettings.vSyncCount = 2; + break; + case QualityLevel.High: + QualitySettings.pixelLightCount = 4; + QualitySettings.antiAliasing = 8; + QualitySettings.softParticles = true; + QualitySettings.realtimeReflectionProbes = true; + QualitySettings.billboardsFaceCameraPosition = true; + QualitySettings.shadows = ShadowQuality.All; + QualitySettings.vSyncCount = 2; + break; + } + } + } + + public enum DevicePerformanceLevel + { + Low, + Mid, + High + } + + public enum QualityLevel + { + Low, + Mid, + High + } + } +} \ No newline at end of file diff --git a/Assets/TEngine/Runtime/GameFramework/Utility/Utility.DevicePerformance.cs.meta b/Assets/TEngine/Runtime/GameFramework/Utility/Utility.DevicePerformance.cs.meta new file mode 100644 index 00000000..12dc3c44 --- /dev/null +++ b/Assets/TEngine/Runtime/GameFramework/Utility/Utility.DevicePerformance.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 464e226f0422412e89e9cd4012b6291c +timeCreated: 1681990596 \ No newline at end of file