From c08be4c84a70073a83a560d080227ce1690da906 Mon Sep 17 00:00:00 2001 From: yurui <952870061@qq.com> Date: Thu, 5 Sep 2024 13:41:39 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=85=B3=E5=8D=A1=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E7=9B=B8=E5=85=B3API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Conditions/ConditionLevelPass.cs | 8 +- .../Conditions/ConditionLevelStar.cs | 10 +- .../Scripts/Gameplay/JumpTo/JumpToManager.cs | 6 +- .../Scripts/Gameplay/Level/ChapterInfo.cs | 51 --- .../Code/Scripts/Gameplay/Level/Level.cs | 2 +- .../Scripts/Gameplay/Level/LevelGroupInfo.cs | 14 +- .../Code/Scripts/Gameplay/Level/LevelInfo.cs | 25 +- .../Gameplay/Level/LevelManager.Action.cs | 10 +- .../Gameplay/Level/LevelManager.Data.cs | 352 +++++++++--------- .../Gameplay/Net/Actor/Part/PartLevel.cs | 13 +- .../Code/Scripts/Gameplay/PVP/PVPManager.cs | 8 +- .../FightReady/UIFightClockController.cs | 55 ++- .../FightReady/UIPauseController.cs | 4 +- .../UI/RedPoint/Node/RedPointNodeLevel.cs | 16 +- .../SelectLevel/UI_LevelSelectController.cs | 24 +- ProjectNLD/Assets/Editor/Tools/PVPTools.cs | 2 +- 16 files changed, 271 insertions(+), 329 deletions(-) diff --git a/ProjectNLD/Assets/Code/Scripts/Gameplay/Condition/Conditions/ConditionLevelPass.cs b/ProjectNLD/Assets/Code/Scripts/Gameplay/Condition/Conditions/ConditionLevelPass.cs index 963bb92e5e7..2c4275debc3 100644 --- a/ProjectNLD/Assets/Code/Scripts/Gameplay/Condition/Conditions/ConditionLevelPass.cs +++ b/ProjectNLD/Assets/Code/Scripts/Gameplay/Condition/Conditions/ConditionLevelPass.cs @@ -13,10 +13,12 @@ public class ConditionLevelPass : ICondition public bool Check(List args) { - var id = (int)args[0]; + int id = (int)args[0]; - var levelInfo = LevelManager.Instance.GetLevelInfoByID(id); - return levelInfo != null && levelInfo.IsPass; + if (!LevelManager.Instance.TryGetLevelInfoByID(id, out LevelInfo levelInfo)) + return false; + + return levelInfo.IsPass; } public string[] GetArgLocalizations(List args) diff --git a/ProjectNLD/Assets/Code/Scripts/Gameplay/Condition/Conditions/ConditionLevelStar.cs b/ProjectNLD/Assets/Code/Scripts/Gameplay/Condition/Conditions/ConditionLevelStar.cs index cc046353ca1..fdb849132da 100644 --- a/ProjectNLD/Assets/Code/Scripts/Gameplay/Condition/Conditions/ConditionLevelStar.cs +++ b/ProjectNLD/Assets/Code/Scripts/Gameplay/Condition/Conditions/ConditionLevelStar.cs @@ -12,11 +12,13 @@ public class ConditionLevelStar : ICondition public bool Check(List args) { - var id = (int)args[0]; - var star = (int)args[1]; + int id = (int)args[0]; + int star = (int)args[1]; - var levelInfo = LevelManager.Instance.GetLevelInfoByID(id); - return levelInfo != null && levelInfo.StarCount >= star; + if (!LevelManager.Instance.TryGetLevelInfoByID(id, out LevelInfo levelInfo)) + return false; + + return levelInfo.StarCount >= star; } public string[] GetArgLocalizations(List args) diff --git a/ProjectNLD/Assets/Code/Scripts/Gameplay/JumpTo/JumpToManager.cs b/ProjectNLD/Assets/Code/Scripts/Gameplay/JumpTo/JumpToManager.cs index 09eb6ac8071..4994781220a 100644 --- a/ProjectNLD/Assets/Code/Scripts/Gameplay/JumpTo/JumpToManager.cs +++ b/ProjectNLD/Assets/Code/Scripts/Gameplay/JumpTo/JumpToManager.cs @@ -69,7 +69,7 @@ namespace Gameplay return; } - LevelInfo levelInfo = LevelManager.Instance.GetLevelInfoByID(levelId); //new LevelInfo(data); + LevelManager.Instance.TryGetLevelInfoByID(levelId, out LevelInfo levelInfo); await UI_LevelSelectController.Open(levelInfo); } @@ -85,10 +85,10 @@ namespace Gameplay } - LevelInfo levelInfo = LevelManager.Instance.GetLevelInfoByID(levelId); //new LevelInfo(data); + LevelManager.Instance.TryGetLevelInfoByID(levelId, out LevelInfo levelInfo); await UI_LevelSelectController.Open(levelInfo); - UI_LevelDetailController.Open(levelInfo); + await UI_LevelDetailController.Open(levelInfo); } public static async void JumpToShopDetail(int shopID) diff --git a/ProjectNLD/Assets/Code/Scripts/Gameplay/Level/ChapterInfo.cs b/ProjectNLD/Assets/Code/Scripts/Gameplay/Level/ChapterInfo.cs index 4ef3f0f3bcf..700c395483e 100644 --- a/ProjectNLD/Assets/Code/Scripts/Gameplay/Level/ChapterInfo.cs +++ b/ProjectNLD/Assets/Code/Scripts/Gameplay/Level/ChapterInfo.cs @@ -39,40 +39,6 @@ public class ChapterInfo: IRedPointTreeNode get { return StringManager.Instance.GetLocalizeTextByKey(Cfg.Desc); } } - /// - /// 星星数量 - /// - public int StarCount - { - get - { - int count = 0; - foreach (LevelGroupInfo levelGroupInfo in dicLevelGroupInfoList.Values) - { - count += levelGroupInfo.StarCount; - } - - return count; - } - } - - /// - /// 最大星星数量 - /// - public int StarMax - { - get - { - int count = 0; - foreach (LevelGroupInfo levelGroupInfo in dicLevelGroupInfoList.Values) - { - count += levelGroupInfo.StarMax; - } - - return count; - } - } - /// /// 是否锁住 /// @@ -89,23 +55,6 @@ public class ChapterInfo: IRedPointTreeNode return true; } } - - /// - /// 所有关卡信息 - /// - public IEnumerable AllLevelInfo - { - get - { - foreach (LevelGroupInfo levelGroupInfo in dicLevelGroupInfoList.Values) - { - foreach (LevelInfo levelInfo in levelGroupInfo) - { - yield return levelInfo; - } - } - } - } #endregion public ChapterInfo(DataChapter config) diff --git a/ProjectNLD/Assets/Code/Scripts/Gameplay/Level/Level.cs b/ProjectNLD/Assets/Code/Scripts/Gameplay/Level/Level.cs index ed58a57b676..b649d24b675 100644 --- a/ProjectNLD/Assets/Code/Scripts/Gameplay/Level/Level.cs +++ b/ProjectNLD/Assets/Code/Scripts/Gameplay/Level/Level.cs @@ -61,7 +61,7 @@ namespace Gameplay.Level private void LoadConfigLevel() { - _currLevelInfo = LevelManager.Instance.GetLevelInfoByID(_id); + LevelManager.Instance.TryGetLevelInfoByID(_id, out _currLevelInfo); } private async UniTask LoadScene() diff --git a/ProjectNLD/Assets/Code/Scripts/Gameplay/Level/LevelGroupInfo.cs b/ProjectNLD/Assets/Code/Scripts/Gameplay/Level/LevelGroupInfo.cs index b3676f417fb..937916ad8c6 100644 --- a/ProjectNLD/Assets/Code/Scripts/Gameplay/Level/LevelGroupInfo.cs +++ b/ProjectNLD/Assets/Code/Scripts/Gameplay/Level/LevelGroupInfo.cs @@ -8,7 +8,7 @@ using Gameplay.Net; /// /// 关卡组信息 /// -public class LevelGroupInfo : IEnumerable, IRedPointTreeNode +public class LevelGroupInfo : IRedPointTreeNode { #region 属性 /// @@ -61,7 +61,7 @@ public class LevelGroupInfo : IEnumerable, IRedPointTreeNode /// public int StarMax { - get { return ListLevelInfo.Count * 3; } + get { return ListLevelInfo.Count * (int)NLDPB.GlobalDefine.MaxLevelStar; } } /// @@ -169,16 +169,6 @@ public class LevelGroupInfo : IEnumerable, IRedPointTreeNode } } - public IEnumerator GetEnumerator() - { - return ListLevelInfo.GetEnumerator(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } - public void ConstructRedPointTree(int parentID) { diff --git a/ProjectNLD/Assets/Code/Scripts/Gameplay/Level/LevelInfo.cs b/ProjectNLD/Assets/Code/Scripts/Gameplay/Level/LevelInfo.cs index 67cfbdff4d3..74b2a8adc8a 100644 --- a/ProjectNLD/Assets/Code/Scripts/Gameplay/Level/LevelInfo.cs +++ b/ProjectNLD/Assets/Code/Scripts/Gameplay/Level/LevelInfo.cs @@ -33,11 +33,11 @@ public class LevelInfo : IRedPointTreeNode /// /// 章节索引 /// - private int _chapterIndex = -1; + private int chapterIndex = -1; /// /// 关卡索引 /// - private int _levelIndex = -1; + private int levelIndex = -1; /// /// 解锁条件id /// @@ -73,7 +73,7 @@ public class LevelInfo : IRedPointTreeNode { get { - if (_chapterIndex == -1) + if (-1 == chapterIndex) { if (Cfg.Id < 100000) { @@ -81,11 +81,11 @@ public class LevelInfo : IRedPointTreeNode return 0; } - var resultStr = Cfg.Id.ToString().Substring(1, 2); - _chapterIndex = int.Parse(resultStr); + string resultStr = Cfg.Id.ToString().Substring(1, 2); + chapterIndex = int.Parse(resultStr); } - return _chapterIndex; + return chapterIndex; } } @@ -96,7 +96,7 @@ public class LevelInfo : IRedPointTreeNode { get { - if (_levelIndex == -1) + if (-1 == levelIndex) { if (Cfg.Id < 100000) { @@ -104,11 +104,11 @@ public class LevelInfo : IRedPointTreeNode return 0; } - var resultStr = Cfg.Id.ToString().Substring(3, 3); - _levelIndex = int.Parse(resultStr); + string resultStr = Cfg.Id.ToString().Substring(3, 3); + levelIndex = int.Parse(resultStr); } - return _levelIndex; + return levelIndex; } } #endregion @@ -130,7 +130,6 @@ public class LevelInfo : IRedPointTreeNode get { return GroupInfo?.ChapterInfo; } } - /// /// 环境类型 /// @@ -194,7 +193,7 @@ public class LevelInfo : IRedPointTreeNode } #endregion - #region Server Data + #region 服务器数据 /// /// 星级数量 /// @@ -331,7 +330,7 @@ public class LevelInfo : IRedPointTreeNode if (result) { IsLock = false; - DebugUtil.Log($"[Level] level unlock,id:{Cfg.Id}"); + DebugUtil.Log($"关卡未解锁,id:{Cfg.Id}"); EventManager.Instance.Send(EventManager.EventName.LevelUnlock, Cfg.Id); ConditionReactor.Instance.RemoveReaction(reactionID); } diff --git a/ProjectNLD/Assets/Code/Scripts/Gameplay/Level/LevelManager.Action.cs b/ProjectNLD/Assets/Code/Scripts/Gameplay/Level/LevelManager.Action.cs index 57c4b081afd..688c22d6ae8 100644 --- a/ProjectNLD/Assets/Code/Scripts/Gameplay/Level/LevelManager.Action.cs +++ b/ProjectNLD/Assets/Code/Scripts/Gameplay/Level/LevelManager.Action.cs @@ -128,8 +128,7 @@ namespace Gameplay.Level private void _EnterLevelDirectly(int levelID) { - var levelInfo = Instance.GetLevelInfoByID(levelID); - if (levelInfo == null) + if (!Instance.TryGetLevelInfoByID(levelID, out LevelInfo levelInfo)) { Debug.LogError($"关卡不存在,id:{levelID}"); return; @@ -210,8 +209,7 @@ namespace Gameplay.Level return; } - var levelInfo = GetLevelInfoByID(id); - if (levelInfo == null) + if(!TryGetLevelInfoByID(id, out LevelInfo levelInfo)) { Debug.LogError($"关卡不存在,id:{id}"); return; @@ -257,7 +255,9 @@ namespace Gameplay.Level _enterLevelFinishCallBack = enterLevelFinishCallBack; _levelParam = param; _EnterLevelDirectly(levelID); - var levelInfo = GetLevelInfoByID(levelID); + if (!TryGetLevelInfoByID(levelID, out LevelInfo levelInfo)) + return; + if (!levelInfo.IsStory && GuideManager.Instance.IsGuiding) PlayBGM(); } diff --git a/ProjectNLD/Assets/Code/Scripts/Gameplay/Level/LevelManager.Data.cs b/ProjectNLD/Assets/Code/Scripts/Gameplay/Level/LevelManager.Data.cs index 1508a01a596..4bafb465138 100644 --- a/ProjectNLD/Assets/Code/Scripts/Gameplay/Level/LevelManager.Data.cs +++ b/ProjectNLD/Assets/Code/Scripts/Gameplay/Level/LevelManager.Data.cs @@ -31,11 +31,6 @@ namespace Gameplay.Level /// private Dictionary> dicChapterType = new(); - public List ListLevelInfo - { - get { return dicLevelInfo.Values.ToList(); } - } - private void InitData() { EventManager.Instance.Register(EventManager.EventName.AllConfigLoad, OnAllConfigLoad); @@ -53,151 +48,10 @@ namespace Gameplay.Level dicLevelGroupInfo = null; } - /// - /// 加载配置 - /// - private void OnAllConfigLoad() - { - LoadAllLevelInfo(); - LoadAllLevelGroup(); - LoadAllChapter(); - ConstructRedPointTree(); - } - - /// - /// 加载所有关卡信息 - /// - private void LoadAllLevelInfo() - { - dicLevelInfo.Clear(); - List listAllLevelConfig = TableManager.Instance.Tables.Level.DataList; - - foreach (DataLevel config in listAllLevelConfig) - { - dicLevelInfo.Add(config.Id, new LevelInfo(config)); - } - } - - /// - /// 加载所有章节 - /// - private void LoadAllChapter() - { - dicChapterInfo.Clear(); - foreach (LevelGroupInfo levelGroupInfo in dicLevelGroupInfo.Values) - { - int chapterID = levelGroupInfo.Cfg.ChapterID; - if (!dicChapterInfo.TryGetValue(chapterID, out ChapterInfo chapterInfo)) - { - DataChapter config = TableManager.Instance.Tables.Chapter.Get(chapterID); - if (null != config) - { - chapterInfo = new ChapterInfo(config); - dicChapterInfo.Add(chapterID, chapterInfo); - } - else - DebugUtil.LogError($"找不到章节配置,id:{chapterID}"); - } - - chapterInfo?.AddLevelGroupInfo(levelGroupInfo); - } - - foreach (ChapterInfo chapterInfo in dicChapterInfo.Values) - { - E_ChapterType chapterType = chapterInfo.Cfg.Type; - if (!dicChapterType.TryGetValue(chapterType, out List list)) - { - list = new(); - dicChapterType.Add(chapterType, list); - } - - list.Add(chapterInfo); - } - } - - /// - /// 加载所有关卡组信息 - /// - private void LoadAllLevelGroup() - { - dicLevelGroupInfo.Clear(); - foreach (LevelInfo levelInfo in dicLevelInfo.Values) - { - int levelGroupID = levelInfo.Cfg.LevelGroupID; - if (!dicLevelGroupInfo.TryGetValue(levelGroupID, out LevelGroupInfo levelGroupInfo)) - { - DataLevelGroup config = TableManager.Instance.Tables.LevelGroupConfig.Get(levelGroupID); - if (null != config) - { - levelGroupInfo = new LevelGroupInfo(config); - dicLevelGroupInfo.Add(levelGroupID, levelGroupInfo); - } - else - DebugUtil.LogError($"找不到关卡组配置, id: {levelGroupID}"); - } - - levelGroupInfo?.AddLevel(levelInfo); - } - } - - private void ConstructRedPointTree() - { - foreach (ChapterInfo chapterInfo in dicChapterInfo.Values) - { - int index = (int)chapterInfo.Cfg.Type; - if (index < 0 || index > _levelGroupTypeRedPointIDArray.Length) - { - DebugUtil.LogError($"index is out of range!index:{index}"); - continue; - } - - int redPointParentID = _levelGroupTypeRedPointIDArray[index]; - chapterInfo.ConstructRedPointTree(redPointParentID); - } - } - - private void DisposeRedPointTree() - { - foreach (ChapterInfo chapterInfo in dicChapterInfo.Values) - { - if (null != chapterInfo.RedPoint) - RedPointManager.Instance.RemoveDynamicNode(chapterInfo.RedPoint); - } - } - - /// - /// 新的关卡服务器数据 - /// - /// - private void OnNewLevelServerData(int levelID) - { - LevelInfo levelInfo = GetLevelInfoByID(levelID); - levelInfo?.RefreshServerData(false); - } - - /// - /// 保存战斗关卡 - /// - /// - private void SaveFightLevel(LevelInfo levelInfo) - { - if(null == levelInfo) - return; - - LevelGroupInfo levelGroupInfo = levelInfo.GroupInfo; - if(null == levelGroupInfo) - return; - - ChapterInfo chapterInfo = levelGroupInfo.ChapterInfo; - if(null == chapterInfo) - return; - - PlayerPrefs.SetInt(GetChapterTypeSaveKey(chapterInfo.Cfg.Type), levelInfo.Cfg.Id); - } - - private string GetChapterTypeSaveKey(E_ChapterType chapterType) => LAST_FIGHT_LEVEL_PREFIX + chapterType; - #region API + /// + /// 刷新所有关卡信息 + /// public void RefreshAllLevelInfo() { foreach (LevelInfo levelInfo in dicLevelInfo.Values) @@ -206,14 +60,20 @@ namespace Gameplay.Level } } - public LevelInfo GetLevelInfoByID(int id) + /// + /// 通关关卡id获取关卡信息 + /// + /// + /// + public bool TryGetLevelInfoByID(int id, out LevelInfo levelInfo) { - if (!dicLevelInfo.TryGetValue(id, out var levelInfo)) + if (!dicLevelInfo.TryGetValue(id, out levelInfo)) { DebugUtil.LogError($"找不到levelInfo,id:{id}"); + return false; } - return levelInfo; + return true; } public LevelGroupInfo GetLevelGroupInfoByID(int id) @@ -264,28 +124,6 @@ namespace Gameplay.Level return dicLevelGroupInfo.Values.ToList(); } - /// - /// 获取某种关卡类型的最新进度 - /// - /// - /// - public LevelInfo GetLatestLevelInfo(E_ChapterType type) - { - if (dicChapterType.TryGetValue(type, out var list)) - { - ChapterInfo latestChapterInfo = list.Where(chapterInfo => !chapterInfo.IsLock).ToList()[^1]; - if (null == latestChapterInfo) - return null; - - List allUnlockLevels = latestChapterInfo.AllLevelInfo.Where(level => !level.IsLock).ToList(); - allUnlockLevels.Sort((a, b) => a.Cfg.Id.CompareTo(b.Cfg.Id)); - - return allUnlockLevels[^1]; - } - - return null; - } - //获取某种关卡类型上一次战斗的关卡 public LevelInfo GetLastFightLevelInfo(E_ChapterType type) { @@ -296,7 +134,8 @@ namespace Gameplay.Level } var levelID = PlayerPrefs.GetInt(key); - var levelInfo = GetLevelInfoByID(levelID); + TryGetLevelInfoByID(levelID, out LevelInfo levelInfo); + return levelInfo; } @@ -312,12 +151,16 @@ namespace Gameplay.Level DebugUtil.LogError("error level ID! "); return E_ChapterType.Main; } - var levelInfo = GetLevelInfoByID(levelID); + + if (!TryGetLevelInfoByID(levelID, out LevelInfo levelInfo)) + return E_ChapterType.Count; + int levelGroupID = levelInfo.Cfg.LevelGroupID; DataLevelGroup config = TableManager.Instance.Tables.LevelGroupConfig.Get(levelGroupID); DataChapter chapterCfg = TableManager.Instance.Tables.Chapter.Get(config.ChapterID); var chapterInfo = new ChapterInfo(chapterCfg); + return chapterInfo.Cfg.Type; } @@ -328,34 +171,34 @@ namespace Gameplay.Level /// public bool CheckLevelUnlock(int levelID) { - var levelInfo = GetLevelInfoByID(levelID); - if(levelInfo == null) + if(!TryGetLevelInfoByID(levelID, out LevelInfo levelInfo)) { DebugUtil.LogError($"cant find levelInfo,id:{levelID}"); return false; } + return !levelInfo.IsLock; } public string LevelIDToNum(int levelID) { - var levelInfo = GetLevelInfoByID(levelID); - if(levelInfo == null) + if(!TryGetLevelInfoByID(levelID, out LevelInfo levelInfo)) { DebugUtil.LogError($"cant find levelInfo,id:{levelID}"); return string.Empty; } + return levelInfo.ChapterIndex + "-" + levelInfo.LevelIndex; } public string LevelIDToName(int levelID) { - var levelInfo = GetLevelInfoByID(levelID); - if (levelInfo == null) + if(!TryGetLevelInfoByID(levelID, out LevelInfo levelInfo)) { DebugUtil.LogError($"cant find levelInfo,id:{levelID}"); return string.Empty; } + return levelInfo.Name; } @@ -378,7 +221,152 @@ namespace Gameplay.Level } return info.Name; } + #endregion + #region 私有方法 + /// + /// 加载配置 + /// + private void OnAllConfigLoad() + { + LoadAllLevelInfo(); + LoadAllLevelGroup(); + LoadAllChapter(); + ConstructRedPointTree(); + } + + /// + /// 加载所有关卡信息 + /// + private void LoadAllLevelInfo() + { + dicLevelInfo.Clear(); + List listAllLevelConfig = TableManager.Instance.Tables.Level.DataList; + + foreach (DataLevel config in listAllLevelConfig) + { + dicLevelInfo.Add(config.Id, new LevelInfo(config)); + } + } + + /// + /// 加载所有关卡组信息 + /// + private void LoadAllLevelGroup() + { + dicLevelGroupInfo.Clear(); + foreach (LevelInfo levelInfo in dicLevelInfo.Values) + { + int levelGroupID = levelInfo.Cfg.LevelGroupID; + if (!dicLevelGroupInfo.TryGetValue(levelGroupID, out LevelGroupInfo levelGroupInfo)) + { + DataLevelGroup config = TableManager.Instance.Tables.LevelGroupConfig.Get(levelGroupID); + if (null != config) + { + levelGroupInfo = new LevelGroupInfo(config); + dicLevelGroupInfo.Add(levelGroupID, levelGroupInfo); + } + else + DebugUtil.LogError($"找不到关卡组配置, id: {levelGroupID}"); + } + + levelGroupInfo?.AddLevel(levelInfo); + } + } + + /// + /// 加载所有章节 + /// + private void LoadAllChapter() + { + dicChapterInfo.Clear(); + foreach (LevelGroupInfo levelGroupInfo in dicLevelGroupInfo.Values) + { + int chapterID = levelGroupInfo.Cfg.ChapterID; + if (!dicChapterInfo.TryGetValue(chapterID, out ChapterInfo chapterInfo)) + { + DataChapter config = TableManager.Instance.Tables.Chapter.Get(chapterID); + if (null != config) + { + chapterInfo = new ChapterInfo(config); + dicChapterInfo.Add(chapterID, chapterInfo); + } + else + DebugUtil.LogError($"找不到章节配置,id:{chapterID}"); + } + + chapterInfo?.AddLevelGroupInfo(levelGroupInfo); + } + + foreach (ChapterInfo chapterInfo in dicChapterInfo.Values) + { + E_ChapterType chapterType = chapterInfo.Cfg.Type; + if (!dicChapterType.TryGetValue(chapterType, out List list)) + { + list = new(); + dicChapterType.Add(chapterType, list); + } + + list.Add(chapterInfo); + } + } + + private void ConstructRedPointTree() + { + foreach (ChapterInfo chapterInfo in dicChapterInfo.Values) + { + int index = (int)chapterInfo.Cfg.Type; + if (index < 0 || index > _levelGroupTypeRedPointIDArray.Length) + { + DebugUtil.LogError($"index is out of range!index:{index}"); + continue; + } + + int redPointParentID = _levelGroupTypeRedPointIDArray[index]; + chapterInfo.ConstructRedPointTree(redPointParentID); + } + } + + private void DisposeRedPointTree() + { + foreach (ChapterInfo chapterInfo in dicChapterInfo.Values) + { + if (null != chapterInfo.RedPoint) + RedPointManager.Instance.RemoveDynamicNode(chapterInfo.RedPoint); + } + } + + /// + /// 新的关卡服务器数据 + /// + /// + private void OnNewLevelServerData(int levelID) + { + if (TryGetLevelInfoByID(levelID, out LevelInfo levelInfo)) + levelInfo.RefreshServerData(false); + } + + /// + /// 保存战斗关卡 + /// + /// + private void SaveFightLevel(LevelInfo levelInfo) + { + if(null == levelInfo) + return; + + LevelGroupInfo levelGroupInfo = levelInfo.GroupInfo; + if(null == levelGroupInfo) + return; + + ChapterInfo chapterInfo = levelGroupInfo.ChapterInfo; + if(null == chapterInfo) + return; + + PlayerPrefs.SetInt(GetChapterTypeSaveKey(chapterInfo.Cfg.Type), levelInfo.Cfg.Id); + } + + private string GetChapterTypeSaveKey(E_ChapterType chapterType) => LAST_FIGHT_LEVEL_PREFIX + chapterType; #endregion } } \ No newline at end of file diff --git a/ProjectNLD/Assets/Code/Scripts/Gameplay/Net/Actor/Part/PartLevel.cs b/ProjectNLD/Assets/Code/Scripts/Gameplay/Net/Actor/Part/PartLevel.cs index 7f1680a3174..83b5532b271 100644 --- a/ProjectNLD/Assets/Code/Scripts/Gameplay/Net/Actor/Part/PartLevel.cs +++ b/ProjectNLD/Assets/Code/Scripts/Gameplay/Net/Actor/Part/PartLevel.cs @@ -19,23 +19,20 @@ namespace Gameplay.Net { public uint id; // 关卡ID public bool isPassed; // 关卡是否通关 - public uint []star; // 关卡获得的星 + public uint[] star; // 关卡获得的星 - public uint StarCount { + public uint StarCount + { get { uint c = 0; - for(int i = 0; i < star.Length; i ++) + for (int i = 0; i < star.Length; i++) { - if(star[i] > 0) - { - c ++; - } + c += star[i]; } return c; } - } public LevelInfo() diff --git a/ProjectNLD/Assets/Code/Scripts/Gameplay/PVP/PVPManager.cs b/ProjectNLD/Assets/Code/Scripts/Gameplay/PVP/PVPManager.cs index 2aaef006704..ce282d0adf7 100644 --- a/ProjectNLD/Assets/Code/Scripts/Gameplay/PVP/PVPManager.cs +++ b/ProjectNLD/Assets/Code/Scripts/Gameplay/PVP/PVPManager.cs @@ -146,13 +146,9 @@ public partial class PVPManager : Singlenton, IInitable, IUpdatable private void OnAllConfigLoad() { - var pvpLevelID = TableManager.Instance.Tables.GlobalConfig.PVPLevelID; - _pvpLevelInfo = LevelManager.Instance.GetLevelInfoByID(pvpLevelID); - if (_pvpLevelInfo == null) - { + int pvpLevelID = TableManager.Instance.Tables.GlobalConfig.PVPLevelID; + if (!LevelManager.Instance.TryGetLevelInfoByID(pvpLevelID, out _pvpLevelInfo)) DebugUtil.LogError($"找不到关卡配置,id:{pvpLevelID}"); - return; - } } public void Update(float dt) diff --git a/ProjectNLD/Assets/Code/Scripts/Gameplay/UI/LevelFight/FightReady/UIFightClockController.cs b/ProjectNLD/Assets/Code/Scripts/Gameplay/UI/LevelFight/FightReady/UIFightClockController.cs index f1bd78e8d12..39082ed228a 100644 --- a/ProjectNLD/Assets/Code/Scripts/Gameplay/UI/LevelFight/FightReady/UIFightClockController.cs +++ b/ProjectNLD/Assets/Code/Scripts/Gameplay/UI/LevelFight/FightReady/UIFightClockController.cs @@ -148,42 +148,39 @@ public class UIFightClockController : UIWindow{ _RefreshOnFightTxt(); } -#region LevelInfo + #region LevelInfo private async void _RefreshLevelInfo() { - var curLevelInfo = LevelManager.Instance.GetLevelInfoByID(LevelManager.Instance.CurrentLevel.ID); - if (curLevelInfo != null) - { - - var dayNightConfig = CommonUtils.GetDayNightConfig(curLevelInfo.Cfg.LevelTime); - var weatherConfig = CommonUtils.GetWeatherConfig(curLevelInfo.Cfg.LevelWeather); - var environmentConfig = CommonUtils.GetEnvironmentConfig(curLevelInfo.Environment); + if (!LevelManager.Instance.TryGetLevelInfoByID(LevelManager.Instance.CurrentLevel.ID, out LevelInfo curLevelInfo)) + return; - var imgDay = CommonUtils.GetComponent(_goTopLevelInfo, "Image_Weather/Image_DayOrNight"); - var txtDay = CommonUtils.GetComponent(_goTopLevelInfo, "Image_Weather/Image_DayOrNight/Text_DayOrNight"); - imgDay.sprite = await LoadAssetAsync(dayNightConfig.Icon); - txtDay.text = CommonUtils.GetLocalizeText(dayNightConfig.NameLocal); - - var imgWeather = CommonUtils.GetComponent(_goTopLevelInfo, "Image_Weather/Image_weather"); - var txtWeather = CommonUtils.GetComponent(_goTopLevelInfo, "Image_Weather/Image_weather/Text_WeatherAndLand01"); - imgWeather.sprite = await LoadAssetAsync(weatherConfig.Icon); - txtWeather.text = CommonUtils.GetLocalizeText(weatherConfig.NameLocal); - - var imgEnvironment = CommonUtils.GetComponent(_goTopLevelInfo, "Image_Weather/Image_environment"); - var txtEnvironment = CommonUtils.GetComponent(_goTopLevelInfo, "Image_Weather/Image_environment/Text_WeatherAndLand02"); - imgEnvironment.sprite = await LoadAssetAsync(environmentConfig.Icon); - txtEnvironment.text = CommonUtils.GetLocalizeText(environmentConfig.NameLocal); + var dayNightConfig = CommonUtils.GetDayNightConfig(curLevelInfo.Cfg.LevelTime); + var weatherConfig = CommonUtils.GetWeatherConfig(curLevelInfo.Cfg.LevelWeather); + var environmentConfig = CommonUtils.GetEnvironmentConfig(curLevelInfo.Environment); - var txtMissionName = CommonUtils.GetComponent(_goTopLevelInfo,"Text_MissionName"); - var txtLevelNum = CommonUtils.GetComponent(_goTopLevelInfo,"Text_LevelNum"); - var levelNum = CommonUtils.GetLevelLabel(curLevelInfo); - txtMissionName.text = curLevelInfo.Desc; - txtLevelNum.text = levelNum; - } + var imgDay = CommonUtils.GetComponent(_goTopLevelInfo, "Image_Weather/Image_DayOrNight"); + var txtDay = CommonUtils.GetComponent(_goTopLevelInfo, "Image_Weather/Image_DayOrNight/Text_DayOrNight"); + imgDay.sprite = await LoadAssetAsync(dayNightConfig.Icon); + txtDay.text = CommonUtils.GetLocalizeText(dayNightConfig.NameLocal); + + var imgWeather = CommonUtils.GetComponent(_goTopLevelInfo, "Image_Weather/Image_weather"); + var txtWeather = CommonUtils.GetComponent(_goTopLevelInfo, "Image_Weather/Image_weather/Text_WeatherAndLand01"); + imgWeather.sprite = await LoadAssetAsync(weatherConfig.Icon); + txtWeather.text = CommonUtils.GetLocalizeText(weatherConfig.NameLocal); + + var imgEnvironment = CommonUtils.GetComponent(_goTopLevelInfo, "Image_Weather/Image_environment"); + var txtEnvironment = CommonUtils.GetComponent(_goTopLevelInfo, "Image_Weather/Image_environment/Text_WeatherAndLand02"); + imgEnvironment.sprite = await LoadAssetAsync(environmentConfig.Icon); + txtEnvironment.text = CommonUtils.GetLocalizeText(environmentConfig.NameLocal); + + var txtMissionName = CommonUtils.GetComponent(_goTopLevelInfo, "Text_MissionName"); + var txtLevelNum = CommonUtils.GetComponent(_goTopLevelInfo, "Text_LevelNum"); + var levelNum = CommonUtils.GetLevelLabel(curLevelInfo); + txtMissionName.text = curLevelInfo.Desc; + txtLevelNum.text = levelNum; } - private void _OnPreEnterBattle() { if (_goTopLevelInfo.activeSelf) diff --git a/ProjectNLD/Assets/Code/Scripts/Gameplay/UI/LevelFight/FightReady/UIPauseController.cs b/ProjectNLD/Assets/Code/Scripts/Gameplay/UI/LevelFight/FightReady/UIPauseController.cs index 676ee1e3bd6..6b9620f11c0 100644 --- a/ProjectNLD/Assets/Code/Scripts/Gameplay/UI/LevelFight/FightReady/UIPauseController.cs +++ b/ProjectNLD/Assets/Code/Scripts/Gameplay/UI/LevelFight/FightReady/UIPauseController.cs @@ -106,8 +106,8 @@ public class UIPauseController : UIWindow private void Refresh() { - var levelData = LevelManager.Instance.CurrentLevel.GetLevelData(); - var levelInfo = LevelManager.Instance.GetLevelInfoByID(LevelManager.Instance.CurrentLevel.ID); + LevelData levelData = LevelManager.Instance.CurrentLevel.GetLevelData(); + LevelManager.Instance.TryGetLevelInfoByID(LevelManager.Instance.CurrentLevel.ID, out LevelInfo levelInfo); RefreshLevelInfo(levelData); RefreshFinish(levelData); RefreshWeather(levelInfo); diff --git a/ProjectNLD/Assets/Code/Scripts/Gameplay/UI/RedPoint/Node/RedPointNodeLevel.cs b/ProjectNLD/Assets/Code/Scripts/Gameplay/UI/RedPoint/Node/RedPointNodeLevel.cs index 1b665ff0acd..9fea54cec74 100644 --- a/ProjectNLD/Assets/Code/Scripts/Gameplay/UI/RedPoint/Node/RedPointNodeLevel.cs +++ b/ProjectNLD/Assets/Code/Scripts/Gameplay/UI/RedPoint/Node/RedPointNodeLevel.cs @@ -13,15 +13,15 @@ public class RedPointNodeLevel : RedPointNode protected override int GetCount() { - if (param == null) + if (null == param) throw new Exception($"param is null! id:{ID}"); - var levelID = (int)param; - var levelInfo = LevelManager.Instance.GetLevelInfoByID(levelID); - if (levelInfo != null) - { - if (!levelInfo.IsLock && !levelInfo.IsPass) - return 1; - } + + int levelID = (int)param; + if (!LevelManager.Instance.TryGetLevelInfoByID(levelID, out LevelInfo levelInfo)) + return 0; + + if (!levelInfo.IsLock && !levelInfo.IsPass) + return 1; return 0; } diff --git a/ProjectNLD/Assets/Code/Scripts/Gameplay/UI/SelectLevel/UI_LevelSelectController.cs b/ProjectNLD/Assets/Code/Scripts/Gameplay/UI/SelectLevel/UI_LevelSelectController.cs index e8f446fd495..e2d8485090f 100644 --- a/ProjectNLD/Assets/Code/Scripts/Gameplay/UI/SelectLevel/UI_LevelSelectController.cs +++ b/ProjectNLD/Assets/Code/Scripts/Gameplay/UI/SelectLevel/UI_LevelSelectController.cs @@ -7,6 +7,7 @@ using System.Threading; using cfg.FightCfg; using cfg.LevelCfg; using Cysharp.Threading.Tasks; +using DG.Tweening; using Framework; using Gameplay; using Gameplay.Common; @@ -69,6 +70,10 @@ public class UI_LevelSelectController : UIWindow /// 章节类型 /// private readonly E_ChapterType chapterType; + /// + /// 箭头旋转动画 + /// + private readonly Tweener tweener; public bool IsSelect { @@ -77,6 +82,10 @@ public class UI_LevelSelectController : UIWindow goSelect.IsScaleShow(value); goTriangle.IsScaleShow(value); goUnSelect.IsScaleShow(!value); + if (value) + tweener.Restart(); + else + tweener.Pause(); } } @@ -90,6 +99,8 @@ public class UI_LevelSelectController : UIWindow goUnSelect = FindObj("Image_Unselect"); goTriangle = FindObj("Image_Triangle"); + tweener = goTriangle.transform.DOLocalRotateQuaternion(Quaternion.Euler(0f, 180f, 0f), 1f).SetLoops(-1); + IsSelect = false; BindButton(button, OnClick); @@ -1150,6 +1161,10 @@ public class UI_LevelSelectController : UIWindow /// 不能领取奖励状态 /// private GameObject goGetRewardOff; + /// + /// 资源选择根节点 + /// + private GameObject goResourceRoot; #endregion /// @@ -1170,6 +1185,8 @@ public class UI_LevelSelectController : UIWindow textStarProgress = GetComponent("UI_StarProgress/Image_StarProgress/Text_Progress"); imageStarProgress = GetComponent("UI_StarProgress/Image_StarProgress/Image_ProgressBar"); goGetRewardOff = FindObj("UI_StarProgress/Button_GetRewardOff"); + goResourceRoot = FindObj("Image_ResourcesCollection"); + goResourceRoot.IsScaleShow(false); BindButton(buttonGetReward, OnStarReward); } @@ -1626,7 +1643,12 @@ public class UI_LevelSelectController : UIWindow public bool IsEnableRecycleView { - set { recycleView.ScrollRect.enabled = value; } + set + { + recycleView.ScrollRect.enabled = value; + if (value) + recycleView.ScrollRect.horizontalNormalizedPosition = 0f; + } } public LevelList(GameObject root, Action level) : base(root) diff --git a/ProjectNLD/Assets/Editor/Tools/PVPTools.cs b/ProjectNLD/Assets/Editor/Tools/PVPTools.cs index 97341d2bf6a..7472457b81b 100644 --- a/ProjectNLD/Assets/Editor/Tools/PVPTools.cs +++ b/ProjectNLD/Assets/Editor/Tools/PVPTools.cs @@ -8,7 +8,7 @@ public class PVPTools public static void PrintPvpDefendRegion() { var pvpLevelID = TableManager.Instance.Tables.GlobalConfig.PVPLevelID; - var pvpLevelInfo = LevelManager.Instance.GetLevelInfoByID(pvpLevelID); + LevelManager.Instance.TryGetLevelInfoByID(pvpLevelID, out LevelInfo pvpLevelInfo); var mapData = pvpLevelInfo.MapData; var levelData = pvpLevelInfo.LevelData; var region = mapData.GetRegion(levelData.pvpDefendRegionId);