From 884368e612e84ab94abbb31ebb643d6e7cc20ca4 Mon Sep 17 00:00:00 2001 From: Tungdv Date: Wed, 13 May 2026 19:45:41 +0700 Subject: [PATCH 1/2] feat: add setting config. --- .../Config/Resources/GameRunConfig.asset | 61 +++++++++++++++- .../Scripts/GameData/GameRunConfig.cs | 28 ++++--- .../PerfectWorld/Scripts/MainFiles/EC_Game.cs | 73 ++++++++++++++++++- Assets/PerfectWorld/Scripts/NPC/CECNPC.cs | 5 +- .../Scripts/Players/EC_ElsePlayer.cs | 4 +- .../Scripts/UI/Dialogs/DlgSetting.cs | 10 +++ .../Scripts/UI/Dialogs/DlgSetting.cs.meta | 2 + .../Scripts/Utility/AddressResourceConfig.cs | 4 - .../Scripts/World/LitModelHolder.cs | 29 ++++---- .../Scripts/World/TerrainHolder.cs | 8 +- 10 files changed, 181 insertions(+), 43 deletions(-) create mode 100644 Assets/PerfectWorld/Scripts/UI/Dialogs/DlgSetting.cs create mode 100644 Assets/PerfectWorld/Scripts/UI/Dialogs/DlgSetting.cs.meta diff --git a/Assets/PerfectWorld/Config/Resources/GameRunConfig.asset b/Assets/PerfectWorld/Config/Resources/GameRunConfig.asset index 4332fc506c..bf11c4754c 100644 --- a/Assets/PerfectWorld/Config/Resources/GameRunConfig.asset +++ b/Assets/PerfectWorld/Config/Resources/GameRunConfig.asset @@ -12,7 +12,60 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 913f99a0553e9ec438c859c044d5c04b, type: 3} m_Name: GameRunConfig m_EditorClassIdentifier: - playerPrefab: {fileID: 6513559496054861882, guid: 1f80fef119a826b4a826baf52a8f92d7, type: 3} - monsterPrefab: {fileID: 6975799234359536760, guid: 244942d3fb9382846b82581ce24fbf4e, type: 3} - npcServerPrefab: {fileID: 2426933851766496167, guid: 9bd42cdc18b3d624db35707155fc50de, type: 3} - testVfxPrefab: {fileID: 2282869967233380084, guid: 88e840e5dac12ed4383d994c7fadfef1, type: 3} + viewDistanceCfg: + - title: Config 1 + show: 100 + hide: 300 + - title: Config 2 + show: 200 + hide: 400 + - title: Config 3 + show: 350 + hide: 550 + - title: Config 4 + show: 500 + hide: 700 + - title: Config 5 + show: 650 + hide: 850 + - title: Config 6 + show: 800 + hide: 1000 + viewDistanceNPCCfg: + - title: Config 1 + show: 10 + hide: 25 + - title: Config 2 + show: 25 + hide: 40 + - title: Config 3 + show: 40 + hide: 55 + - title: Config 4 + show: 55 + hide: 70 + - title: Config 5 + show: 70 + hide: 85 + - title: Config 6 + show: 85 + hide: 100 + viewDistanceEPCfg: + - title: Config 1 + show: 10 + hide: 25 + - title: Config 2 + show: 25 + hide: 40 + - title: Config 3 + show: 40 + hide: 55 + - title: Config 4 + show: 55 + hide: 70 + - title: Config 5 + show: 70 + hide: 85 + - title: Config 6 + show: 85 + hide: 100 diff --git a/Assets/PerfectWorld/Scripts/GameData/GameRunConfig.cs b/Assets/PerfectWorld/Scripts/GameData/GameRunConfig.cs index 48f97a5adc..39a1c234ee 100644 --- a/Assets/PerfectWorld/Scripts/GameData/GameRunConfig.cs +++ b/Assets/PerfectWorld/Scripts/GameData/GameRunConfig.cs @@ -1,4 +1,8 @@ +using System; +using System.Collections.Generic; +using System.Runtime.InteropServices; using UnityEngine; +using UnityEngine.Rendering; using UnityEngine.Serialization; namespace BrewMonster @@ -6,16 +10,20 @@ namespace BrewMonster [CreateAssetMenu(fileName = "GameRunConfig", menuName = "BrewMonster/Game Run Config")] public class GameRunConfig : ScriptableObject { - [FormerlySerializedAs("characterPrefab")] - [Header("Prefabs")] - [SerializeField] private GameObject playerPrefab; - [SerializeField] private GameObject monsterPrefab; - [SerializeField] private GameObject npcServerPrefab; - [SerializeField] private GameObject testVfxPrefab; + [SerializeField] private List viewDistanceCfg; + [SerializeField] private List viewDistanceNPCCfg; + [SerializeField] private List viewDistanceEPCfg; - public GameObject PlayerPrefab => playerPrefab; - public GameObject MonsterPrefab => monsterPrefab; - public GameObject NpcServerPrefab => npcServerPrefab.gameObject; - public GameObject TestVfxPrefab => testVfxPrefab; + public List GetViewDistanceCfg { get => viewDistanceCfg;} + public List GetViewDistanceNPCCfg { get => viewDistanceNPCCfg;} + public List GetViewDistanceEPCfg { get => viewDistanceEPCfg;} + } + + [Serializable] + public struct ViewDistance + { + public string title; + public float fShow; + public float fHide; } } diff --git a/Assets/PerfectWorld/Scripts/MainFiles/EC_Game.cs b/Assets/PerfectWorld/Scripts/MainFiles/EC_Game.cs index 61b287dcae..38e808ca9c 100644 --- a/Assets/PerfectWorld/Scripts/MainFiles/EC_Game.cs +++ b/Assets/PerfectWorld/Scripts/MainFiles/EC_Game.cs @@ -1,6 +1,7 @@ using BrewMonster; using BrewMonster.Scripts.Task; using CSNetwork; +using CSNetwork.GPDataType; using Cysharp.Threading.Tasks; using ModelRenderer.Scripts.GameData; using System; @@ -10,8 +11,9 @@ using System.IO; using System.Threading.Tasks; using UnityEngine; using UnityEngine.AddressableAssets; +using UnityEngine.Rendering; +using UnityEngine.Rendering.Universal; using UnityEngine.ResourceManagement.AsyncOperations; -using CSNetwork.GPDataType; namespace BrewMonster.Network { @@ -31,7 +33,7 @@ namespace BrewMonster.Network private static BrewMonster.CECStringTab m_ItemExtDesc; // Item extend description string table private static BrewMonster.CECStringTab m_ItemExtProp; // Item extend prop string table private static BrewMonster.CECStringTab ItemColTab; // Item color string table - private static Dictionary m_SuiteEquipTab; // Item suite string table + private static Dictionary m_SuiteEquipTab; // Item suite string table private static BrewMonster.CECStringTab m_SkillDesc = new CECStringTab(); // Skill description string table private static BrewMonster.CECStringTab m_BuffDesc; // Buff description string table @@ -40,6 +42,13 @@ namespace BrewMonster.Network private static int m_iCurCursor; // Current cursor private static List m_PetAutoSkills = new List(); + private static GameRunConfig gameRunConfigSO; + private readonly static string keySettingViewDistance = "_keySettingViewDistance"; + private readonly static string keySettingViewDistanceNPC = "_keySettingViewDistanceNPC"; + private readonly static string keySettingViewDistanceEP = "_keySettingViewDistanceEP"; + private readonly static string keySettingActiveShadow = "_keySettingActiveShadow"; + private readonly static string keySettingActiveFullResolution = "_keySettingActiveFullResolution"; + private readonly static string keySettingActiveFog = "_keySettingActiveFog"; #endregion #region Properties @@ -615,6 +624,64 @@ namespace BrewMonster.Network return null; } } + + public static GameRunConfig GameRunConfigSO + { + get + { + if(gameRunConfigSO == null) + { + gameRunConfigSO = Resources.Load("GameRunConfig"); + } + return gameRunConfigSO; + } + } + + public static ViewDistance GetSettingViewDistance() + { + int index = PlayerPrefs.GetInt(keySettingViewDistance, defaultValue: 1); + return gameRunConfigSO.GetViewDistanceCfg[index]; + } + + public static ViewDistance GetSettingViewDistanceNPC() + { + int index = PlayerPrefs.GetInt(keySettingViewDistanceNPC, defaultValue: 1); + return gameRunConfigSO.GetViewDistanceNPCCfg[index]; + } + + public static ViewDistance GetSettingViewDistanceEP() + { + int index = PlayerPrefs.GetInt(keySettingViewDistanceEP, defaultValue: 1); + return gameRunConfigSO.GetViewDistanceEPCfg[index]; + } + + public static bool GetSettingActiveShadow() + { + int index = PlayerPrefs.GetInt(keySettingActiveShadow, defaultValue: 1); + return index == 1; + } + + public static void SetSettingActiveShadow(bool value) + { + + } + + public static void SetSettingActiveFullResolution(bool value) + { + + } + + public static bool GetSettingActiveFullResolution() + { + int index = PlayerPrefs.GetInt(keySettingActiveFullResolution, defaultValue: 1); + return index == 1; + } + + public static bool GetSettingActiveFog() + { + int index = PlayerPrefs.GetInt(keySettingActiveFog, defaultValue: 1); + return index == 1; + } #endregion } -} \ No newline at end of file +} diff --git a/Assets/PerfectWorld/Scripts/NPC/CECNPC.cs b/Assets/PerfectWorld/Scripts/NPC/CECNPC.cs index 098711dff1..9f83a011a8 100644 --- a/Assets/PerfectWorld/Scripts/NPC/CECNPC.cs +++ b/Assets/PerfectWorld/Scripts/NPC/CECNPC.cs @@ -10,6 +10,7 @@ using BrewMonster.Scripts.Chat; using System.Collections.Generic; using UnityEngine; using BrewMonster.Scripts.Skills; +using BrewMonster.Network; public class CECNPC : CECObject { [SerializeField] protected INFO m_NPCInfo; @@ -636,11 +637,11 @@ public class CECNPC : CECObject if(m_modelVisual != null) { - if(m_fDistToHostH < AddressResourceConfig.m_fDistShowModelVisual) + if(m_fDistToHostH < EC_Game.GetSettingViewDistanceNPC().fShow) { m_modelVisual.SetActive(true); } - else if(m_fDistToHostH > AddressResourceConfig.m_fDistHideModelVisual) + else if(m_fDistToHostH > EC_Game.GetSettingViewDistanceNPC().fHide) { m_modelVisual.SetActive(false); } diff --git a/Assets/PerfectWorld/Scripts/Players/EC_ElsePlayer.cs b/Assets/PerfectWorld/Scripts/Players/EC_ElsePlayer.cs index c9cf45fca8..b7c546ae47 100644 --- a/Assets/PerfectWorld/Scripts/Players/EC_ElsePlayer.cs +++ b/Assets/PerfectWorld/Scripts/Players/EC_ElsePlayer.cs @@ -449,11 +449,11 @@ namespace BrewMonster m_fDistToHostH = CalcDist(pHost.GetPos(), false); if (m_pPlayerModel != null) { - if (m_fDistToHostH < AddressResourceConfig.m_fDistShowModelVisual) + if (m_fDistToHostH < EC_Game.GetSettingViewDistanceEP().fShow) { m_pPlayerModel.SetActive(true); } - else if (m_fDistToHostH > AddressResourceConfig.m_fDistHideModelVisual) + else if (m_fDistToHostH > EC_Game.GetSettingViewDistanceEP().fHide) { m_pPlayerModel.SetActive(false); } diff --git a/Assets/PerfectWorld/Scripts/UI/Dialogs/DlgSetting.cs b/Assets/PerfectWorld/Scripts/UI/Dialogs/DlgSetting.cs new file mode 100644 index 0000000000..70026d2269 --- /dev/null +++ b/Assets/PerfectWorld/Scripts/UI/Dialogs/DlgSetting.cs @@ -0,0 +1,10 @@ +using BrewMonster.UI; +using UnityEngine; + +namespace BrewMonster +{ + public class DlgSetting : AUIDialog + { + + } +} diff --git a/Assets/PerfectWorld/Scripts/UI/Dialogs/DlgSetting.cs.meta b/Assets/PerfectWorld/Scripts/UI/Dialogs/DlgSetting.cs.meta new file mode 100644 index 0000000000..9839e10315 --- /dev/null +++ b/Assets/PerfectWorld/Scripts/UI/Dialogs/DlgSetting.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: e89b514fe463eaf46b81527aff05751a \ No newline at end of file diff --git a/Assets/PerfectWorld/Scripts/Utility/AddressResourceConfig.cs b/Assets/PerfectWorld/Scripts/Utility/AddressResourceConfig.cs index cd58a08dea..62dd12ee72 100644 --- a/Assets/PerfectWorld/Scripts/Utility/AddressResourceConfig.cs +++ b/Assets/PerfectWorld/Scripts/Utility/AddressResourceConfig.cs @@ -9,9 +9,5 @@ namespace BrewMonster public static string TestVfxPrefab = "Prefabs/Vfx/TestVfx"; public static string PetServerPrefab = "Pet/PetPrefab"; public static string PetMountServerPrefab = "Pet/PetMount/PetMountPrefab"; - - - public static float m_fDistShowModelVisual = 25f; // Display distance model NPC - public static float m_fDistHideModelVisual = 40f; // Hide/display distance model NPC } } diff --git a/Assets/PerfectWorld/Scripts/World/LitModelHolder.cs b/Assets/PerfectWorld/Scripts/World/LitModelHolder.cs index 70038d877f..3b967f2252 100644 --- a/Assets/PerfectWorld/Scripts/World/LitModelHolder.cs +++ b/Assets/PerfectWorld/Scripts/World/LitModelHolder.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; using BrewMonster; +using BrewMonster.Network; using BrewMonster.Scripts; using Cysharp.Threading.Tasks; using UnityEngine; @@ -15,9 +16,9 @@ public class LitModelHolder : MonoSingleton [Header("Distance Streaming")] [Tooltip("The distance from the host player to the object to be loaded immediately.")] - [SerializeField] private float _loadImmediateDistance = 200f; + [SerializeField] private float _loadImmediateDistance => EC_Game.GetSettingViewDistance().fShow; // 200f [Tooltip("Objects need to go outside of this distance to be unloaded.")] - [SerializeField] private float _unloadDistance = 400f; + [SerializeField] private float _unloadDistance => EC_Game.GetSettingViewDistance().fHide; // 400f [Header("Performance")] [SerializeField] private float _checkIntervalSeconds = 0.25f; @@ -134,10 +135,10 @@ public class LitModelHolder : MonoSingleton /// private async UniTask LoadObjectBaseOnDistance(CancellationToken destroyToken) { - if (_unloadDistance < _loadImmediateDistance) - { - _unloadDistance = _loadImmediateDistance; - } + //if (_unloadDistance < _loadImmediateDistance) + //{ + // _unloadDistance = _loadImmediateDistance; + //} while (_hostPlayer == null) { @@ -174,10 +175,10 @@ public class LitModelHolder : MonoSingleton return; } - if (_unloadDistance < _loadImmediateDistance) - { - _unloadDistance = _loadImmediateDistance; - } + //if (_unloadDistance < _loadImmediateDistance) + //{ + // _unloadDistance = _loadImmediateDistance; + //} float immediateSqr = _loadImmediateDistance * _loadImmediateDistance; float paddingSqr = _unloadDistance * _unloadDistance; @@ -196,10 +197,10 @@ public class LitModelHolder : MonoSingleton /// private async UniTask StreamByDistanceLoop(CancellationToken destroyToken) { - if (_unloadDistance < _loadImmediateDistance) - { - _unloadDistance = _loadImmediateDistance; - } + //if (_unloadDistance < _loadImmediateDistance) + //{ + // _unloadDistance = _loadImmediateDistance; + //} float immediateSqr = _loadImmediateDistance * _loadImmediateDistance; float paddingSqr = _unloadDistance * _unloadDistance; diff --git a/Assets/PerfectWorld/Scripts/World/TerrainHolder.cs b/Assets/PerfectWorld/Scripts/World/TerrainHolder.cs index 8cfe0ed009..674a9c52cc 100644 --- a/Assets/PerfectWorld/Scripts/World/TerrainHolder.cs +++ b/Assets/PerfectWorld/Scripts/World/TerrainHolder.cs @@ -17,8 +17,8 @@ namespace BrewMonster public class TerrainHolder : MonoBehaviour { [SerializeField] private AddressableObject[] _addressableObjects; - [SerializeField] private float _loadImmediateDistance = 150f; - [SerializeField] private float _unloadDistance = 300f; + [SerializeField] private float _loadImmediateDistance => EC_Game.GetSettingViewDistance().fShow; // 150f + [SerializeField] private float _unloadDistance => EC_Game.GetSettingViewDistance().fHide; // 300f [SerializeField] private float _minHostMoveToUpdate = 5f; private List _candidatesForLoading = new List(); @@ -100,8 +100,8 @@ namespace BrewMonster if (_addressableObjects == null || _addressableObjects.Length == 0) return; - if (_unloadDistance < _loadImmediateDistance) - _unloadDistance = _loadImmediateDistance; + //if (_unloadDistance < _loadImmediateDistance) + // _unloadDistance = _loadImmediateDistance; float immediateSqr = _loadImmediateDistance * _loadImmediateDistance; float paddingSqr = _unloadDistance * _unloadDistance; From d8adcc82585a7e710f6efb6953ff1d12cf773666 Mon Sep 17 00:00:00 2001 From: Tungdv Date: Fri, 15 May 2026 11:36:23 +0700 Subject: [PATCH 2/2] fix: Update data view distance config. --- .../Config/Resources/GameRunConfig.asset | 72 +++++++++---------- .../PerfectWorld/Scripts/MainFiles/EC_Game.cs | 23 ++++-- .../Scripts/World/TerrainHolder.cs | 4 +- 3 files changed, 55 insertions(+), 44 deletions(-) diff --git a/Assets/PerfectWorld/Config/Resources/GameRunConfig.asset b/Assets/PerfectWorld/Config/Resources/GameRunConfig.asset index bf11c4754c..00b2e3516b 100644 --- a/Assets/PerfectWorld/Config/Resources/GameRunConfig.asset +++ b/Assets/PerfectWorld/Config/Resources/GameRunConfig.asset @@ -14,58 +14,58 @@ MonoBehaviour: m_EditorClassIdentifier: viewDistanceCfg: - title: Config 1 - show: 100 - hide: 300 + fShow: 200 + fHide: 400 - title: Config 2 - show: 200 - hide: 400 + fShow: 400 + fHide: 600 - title: Config 3 - show: 350 - hide: 550 + fShow: 600 + fHide: 800 - title: Config 4 - show: 500 - hide: 700 + fShow: 800 + fHide: 1000 - title: Config 5 - show: 650 - hide: 850 + fShow: 1000 + fHide: 1200 - title: Config 6 - show: 800 - hide: 1000 + fShow: 1200 + fHide: 1400 viewDistanceNPCCfg: - title: Config 1 - show: 10 - hide: 25 + fShow: 25 + fHide: 40 - title: Config 2 - show: 25 - hide: 40 + fShow: 40 + fHide: 55 - title: Config 3 - show: 40 - hide: 55 + fShow: 55 + fHide: 70 - title: Config 4 - show: 55 - hide: 70 + fShow: 70 + fHide: 85 - title: Config 5 - show: 70 - hide: 85 + fShow: 85 + fHide: 100 - title: Config 6 - show: 85 - hide: 100 + fShow: 100 + fHide: 115 viewDistanceEPCfg: - title: Config 1 - show: 10 - hide: 25 + fShow: 25 + fHide: 40 - title: Config 2 - show: 25 - hide: 40 + fShow: 40 + fHide: 55 - title: Config 3 - show: 40 - hide: 55 + fShow: 55 + fHide: 70 - title: Config 4 - show: 55 - hide: 70 + fShow: 70 + fHide: 85 - title: Config 5 - show: 70 - hide: 85 + fShow: 85 + fHide: 100 - title: Config 6 - show: 85 - hide: 100 + fShow: 100 + fHide: 115 diff --git a/Assets/PerfectWorld/Scripts/MainFiles/EC_Game.cs b/Assets/PerfectWorld/Scripts/MainFiles/EC_Game.cs index 38e808ca9c..824914f420 100644 --- a/Assets/PerfectWorld/Scripts/MainFiles/EC_Game.cs +++ b/Assets/PerfectWorld/Scripts/MainFiles/EC_Game.cs @@ -49,6 +49,9 @@ namespace BrewMonster.Network private readonly static string keySettingActiveShadow = "_keySettingActiveShadow"; private readonly static string keySettingActiveFullResolution = "_keySettingActiveFullResolution"; private readonly static string keySettingActiveFog = "_keySettingActiveFog"; + private static ViewDistance m_viewDistance; + private static ViewDistance m_viewDistanceNPC; + private static ViewDistance m_viewDistanceEP; #endregion #region Properties @@ -149,6 +152,7 @@ namespace BrewMonster.Network LoadPetAutoSkill(); GlobalDataManager.globaldata_load(); + InitSetting(); return true; } public static CECConfigs GetConfigs() { return m_pConfigs; } @@ -637,22 +641,29 @@ namespace BrewMonster.Network } } + public static void InitSetting() + { + int index = PlayerPrefs.GetInt(keySettingViewDistance, defaultValue: 5); + m_viewDistance = GameRunConfigSO.GetViewDistanceCfg[index]; + index = PlayerPrefs.GetInt(keySettingViewDistanceNPC, defaultValue: 5); + m_viewDistanceNPC = GameRunConfigSO.GetViewDistanceNPCCfg[index]; + index = PlayerPrefs.GetInt(keySettingViewDistanceEP, defaultValue: 5); + m_viewDistanceEP = GameRunConfigSO.GetViewDistanceEPCfg[index]; + } + public static ViewDistance GetSettingViewDistance() { - int index = PlayerPrefs.GetInt(keySettingViewDistance, defaultValue: 1); - return gameRunConfigSO.GetViewDistanceCfg[index]; + return m_viewDistance; } public static ViewDistance GetSettingViewDistanceNPC() { - int index = PlayerPrefs.GetInt(keySettingViewDistanceNPC, defaultValue: 1); - return gameRunConfigSO.GetViewDistanceNPCCfg[index]; + return m_viewDistanceNPC; } public static ViewDistance GetSettingViewDistanceEP() { - int index = PlayerPrefs.GetInt(keySettingViewDistanceEP, defaultValue: 1); - return gameRunConfigSO.GetViewDistanceEPCfg[index]; + return m_viewDistanceEP; } public static bool GetSettingActiveShadow() diff --git a/Assets/PerfectWorld/Scripts/World/TerrainHolder.cs b/Assets/PerfectWorld/Scripts/World/TerrainHolder.cs index 674a9c52cc..78942d4328 100644 --- a/Assets/PerfectWorld/Scripts/World/TerrainHolder.cs +++ b/Assets/PerfectWorld/Scripts/World/TerrainHolder.cs @@ -17,8 +17,8 @@ namespace BrewMonster public class TerrainHolder : MonoBehaviour { [SerializeField] private AddressableObject[] _addressableObjects; - [SerializeField] private float _loadImmediateDistance => EC_Game.GetSettingViewDistance().fShow; // 150f - [SerializeField] private float _unloadDistance => EC_Game.GetSettingViewDistance().fHide; // 300f + [SerializeField] private float _loadImmediateDistance => EC_Game.GetSettingViewDistance().fShow; //150f; + [SerializeField] private float _unloadDistance => EC_Game.GetSettingViewDistance().fHide; //300f; [SerializeField] private float _minHostMoveToUpdate = 5f; private List _candidatesForLoading = new List();