From ca27e3d915831adbab354f0b9b36a788a9d7e654 Mon Sep 17 00:00:00 2001 From: yangjing Date: Wed, 9 Feb 2022 20:07:40 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=93=E5=B1=80=E5=AD=98=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Scripts/Game/GameConfig.cs | 8 ++--- Assets/Scripts/Game/GameLogic.cs | 13 ++++---- Assets/Scripts/Storage/PlayerData.cs | 36 +++++++++++++++++++++++ Assets/Scripts/UI/PanelGame.cs | 2 +- Assets/Scripts/UI/PanelResult.cs | 5 +++- Assets/Scripts/Utils/UITools/Hole/Hole.cs | 4 +-- 6 files changed, 55 insertions(+), 13 deletions(-) diff --git a/Assets/Scripts/Game/GameConfig.cs b/Assets/Scripts/Game/GameConfig.cs index 3a271bfd..a9e41fd6 100644 --- a/Assets/Scripts/Game/GameConfig.cs +++ b/Assets/Scripts/Game/GameConfig.cs @@ -23,20 +23,20 @@ public class LevelData public int SlotCount; public List Endings; - public EndingData GetMatchingEnding(string pEndingStr) + public int GetMatchingEndingID(string pEndingStr) { - EndingData tData = null; + int tEndingID = -1; for (int i = 0; i < Endings.Count; i++) { if (Endings[i].IsMatching(pEndingStr)) { - tData = Endings[i]; + tEndingID = i; break; } } - return tData; + return tEndingID; } } diff --git a/Assets/Scripts/Game/GameLogic.cs b/Assets/Scripts/Game/GameLogic.cs index 58859463..ba200fbd 100644 --- a/Assets/Scripts/Game/GameLogic.cs +++ b/Assets/Scripts/Game/GameLogic.cs @@ -56,18 +56,21 @@ public class GameLogic : MonoBehaviour { //end LevelData tLvData = GameConfig.Instance.GetLevelData(PlayerData.Instance.CurrentLevelID); - EndingData tEdData = tLvData.GetMatchingEnding(mEndingStr.Replace("_","")); - + int tEndingID = tLvData.GetMatchingEndingID(mEndingStr.Replace("_","")); + UIManager.Instance.CloseUI(); PanelResult tUIResult = UIManager.Instance.OpenUI(); - if (tEdData != null) + if (tEndingID >= 0) { - tUIResult.Init(tEdData.EndingName, tEdData.IsGoodEnding, false); + PlayerData.Instance.AddEnding(PlayerData.Instance.CurrentLevelID, tEndingID); + + EndingData tEdData = tLvData.Endings[tEndingID]; + tUIResult.Init(PlayerData.Instance.CurrentLevelID, tEdData.EndingName, tEdData.IsGoodEnding, false); } else { - tUIResult.Init("", false, false); + tUIResult.Init(PlayerData.Instance.CurrentLevelID, "", false, false); } tUIResult.DelAgain = PlayAgain; diff --git a/Assets/Scripts/Storage/PlayerData.cs b/Assets/Scripts/Storage/PlayerData.cs index 6738abac..52bb4ff0 100644 --- a/Assets/Scripts/Storage/PlayerData.cs +++ b/Assets/Scripts/Storage/PlayerData.cs @@ -25,4 +25,40 @@ public class PlayerData : StorageBase return GameConfig.Instance.LevelSort[mCurrentLevel - 1]; } } + + [SerializeField] private Dictionary> mEndingDic = new Dictionary>(); + + public bool AddEnding(int pLevelID, int pEndingID) + { + if (!mEndingDic.ContainsKey(pLevelID)) + { + mEndingDic[pLevelID] = new List(); + } + + if (!mEndingDic[pLevelID].Contains(pEndingID)) + { + mEndingDic[pLevelID].Add(pEndingID); + Save(); + return true; + } + + return false; + } + + public int EndingCountOfLevel(int pLevelID) + { + if (mEndingDic.ContainsKey(pLevelID)) + { + return mEndingDic[pLevelID].Count; + } + + return 0; + } + + public bool HasUnlockedEnding(int pLevelID, int pEndingID) + { + bool tUnlocked = mEndingDic.ContainsKey(pLevelID) && mEndingDic[pLevelID].Contains(pEndingID); + + return tUnlocked; + } } \ No newline at end of file diff --git a/Assets/Scripts/UI/PanelGame.cs b/Assets/Scripts/UI/PanelGame.cs index d4f33843..987b78dd 100644 --- a/Assets/Scripts/UI/PanelGame.cs +++ b/Assets/Scripts/UI/PanelGame.cs @@ -49,7 +49,7 @@ public class PanelGame : BasePanel LevelData tLvData = GameConfig.Instance.GetLevelData(PlayerData.Instance.CurrentLevelID); mTxtTitle.text = tLvData.LevelName; - mBtnEndings.Init(PlayerData.Instance.CurrentLevelID, 3, tLvData.Endings.Count); + mBtnEndings.Init(PlayerData.Instance.CurrentLevelID, PlayerData.Instance.EndingCountOfLevel(PlayerData.Instance.CurrentLevelID), tLvData.Endings.Count); mTotalSlot = tLvData.SlotCount; mCurSlotIndex = 0; diff --git a/Assets/Scripts/UI/PanelResult.cs b/Assets/Scripts/UI/PanelResult.cs index 3106ef95..8bfd5965 100644 --- a/Assets/Scripts/UI/PanelResult.cs +++ b/Assets/Scripts/UI/PanelResult.cs @@ -36,7 +36,7 @@ public class PanelResult : BasePanel mBtnEndings.DelClick = OnClickEndings; } - public void Init(string pEndingName,bool pIsWin, bool pAllLevelClear) + public void Init(int pLevelID, string pEndingName,bool pIsWin, bool pAllLevelClear) { mTxtEndingName.text = pEndingName; @@ -48,6 +48,9 @@ public class PanelResult : BasePanel mGobWinBtns.SetActive(!pAllLevelClear && pIsWin); mGobOtherBtns.SetActive(pAllLevelClear || !pIsWin); + + LevelData tLvData = GameConfig.Instance.GetLevelData(pLevelID); + mBtnEndings.Init(pLevelID, PlayerData.Instance.EndingCountOfLevel(pLevelID), tLvData.Endings.Count); } private void OnClickAgain() diff --git a/Assets/Scripts/Utils/UITools/Hole/Hole.cs b/Assets/Scripts/Utils/UITools/Hole/Hole.cs index 2beeb4ec..0a8ebf0e 100644 --- a/Assets/Scripts/Utils/UITools/Hole/Hole.cs +++ b/Assets/Scripts/Utils/UITools/Hole/Hole.cs @@ -8,8 +8,8 @@ public class Hole : Mask public override bool IsRaycastLocationValid(Vector2 sp, Camera eventCamera) { return false; - if (!isActiveAndEnabled) - return true; + //if (!isActiveAndEnabled) + // return true; //return !RectTransformUtility.RectangleContainsScreenPoint(rectTransform, sp, eventCamera); }