结局存档

This commit is contained in:
yangjing 2022-02-09 20:07:40 +08:00
parent 061937275d
commit ca27e3d915
6 changed files with 55 additions and 13 deletions

View File

@ -23,20 +23,20 @@ public class LevelData
public int SlotCount; public int SlotCount;
public List<EndingData> Endings; public List<EndingData> 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++) for (int i = 0; i < Endings.Count; i++)
{ {
if (Endings[i].IsMatching(pEndingStr)) if (Endings[i].IsMatching(pEndingStr))
{ {
tData = Endings[i]; tEndingID = i;
break; break;
} }
} }
return tData; return tEndingID;
} }
} }

View File

@ -56,18 +56,21 @@ public class GameLogic : MonoBehaviour
{ {
//end //end
LevelData tLvData = GameConfig.Instance.GetLevelData(PlayerData.Instance.CurrentLevelID); LevelData tLvData = GameConfig.Instance.GetLevelData(PlayerData.Instance.CurrentLevelID);
EndingData tEdData = tLvData.GetMatchingEnding(mEndingStr.Replace("_","")); int tEndingID = tLvData.GetMatchingEndingID(mEndingStr.Replace("_",""));
UIManager.Instance.CloseUI<PanelGame>(); UIManager.Instance.CloseUI<PanelGame>();
PanelResult tUIResult = UIManager.Instance.OpenUI<PanelResult>(); PanelResult tUIResult = UIManager.Instance.OpenUI<PanelResult>();
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 else
{ {
tUIResult.Init("", false, false); tUIResult.Init(PlayerData.Instance.CurrentLevelID, "", false, false);
} }
tUIResult.DelAgain = PlayAgain; tUIResult.DelAgain = PlayAgain;

View File

@ -25,4 +25,40 @@ public class PlayerData : StorageBase<PlayerData>
return GameConfig.Instance.LevelSort[mCurrentLevel - 1]; return GameConfig.Instance.LevelSort[mCurrentLevel - 1];
} }
} }
[SerializeField] private Dictionary<int, List<int>> mEndingDic = new Dictionary<int, List<int>>();
public bool AddEnding(int pLevelID, int pEndingID)
{
if (!mEndingDic.ContainsKey(pLevelID))
{
mEndingDic[pLevelID] = new List<int>();
}
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;
}
} }

View File

@ -49,7 +49,7 @@ public class PanelGame : BasePanel
LevelData tLvData = GameConfig.Instance.GetLevelData(PlayerData.Instance.CurrentLevelID); LevelData tLvData = GameConfig.Instance.GetLevelData(PlayerData.Instance.CurrentLevelID);
mTxtTitle.text = tLvData.LevelName; 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; mTotalSlot = tLvData.SlotCount;
mCurSlotIndex = 0; mCurSlotIndex = 0;

View File

@ -36,7 +36,7 @@ public class PanelResult : BasePanel
mBtnEndings.DelClick = OnClickEndings; 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; mTxtEndingName.text = pEndingName;
@ -48,6 +48,9 @@ public class PanelResult : BasePanel
mGobWinBtns.SetActive(!pAllLevelClear && pIsWin); mGobWinBtns.SetActive(!pAllLevelClear && pIsWin);
mGobOtherBtns.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() private void OnClickAgain()

View File

@ -8,8 +8,8 @@ public class Hole : Mask
public override bool IsRaycastLocationValid(Vector2 sp, Camera eventCamera) public override bool IsRaycastLocationValid(Vector2 sp, Camera eventCamera)
{ {
return false; return false;
if (!isActiveAndEnabled) //if (!isActiveAndEnabled)
return true; // return true;
//return !RectTransformUtility.RectangleContainsScreenPoint(rectTransform, sp, eventCamera); //return !RectTransformUtility.RectangleContainsScreenPoint(rectTransform, sp, eventCamera);
} }