chicken_dy/Assets/Scripts/Config/GameConfig.cs

101 lines
2.4 KiB
C#
Raw Normal View History

2022-02-08 12:10:20 +00:00
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu(menuName = "GameConfig")]
public class GameConfig : ConfigBase<GameConfig>
{
public List<int> LevelSort;
public List<LevelData> Levels;
2022-02-09 08:35:01 +00:00
public LevelData GetLevelData(int pLevelID)
{
return pLevelID < Levels.Count ? Levels[pLevelID] : null;
}
2022-02-08 12:10:20 +00:00
}
[Serializable]
public class LevelData
{
public string LevelName;//only for editor display
public string LevelColorCode;
public int SlotCount;
public List<EndingData> Endings;
2022-02-09 11:36:47 +00:00
2022-02-09 12:07:40 +00:00
public int GetMatchingEndingID(string pEndingStr)
2022-02-09 11:36:47 +00:00
{
2022-02-09 12:07:40 +00:00
int tEndingID = -1;
2022-02-09 11:36:47 +00:00
2022-02-10 09:21:59 +00:00
//first check accurately
2022-02-09 11:36:47 +00:00
for (int i = 0; i < Endings.Count; i++)
{
if (Endings[i].IsMatching(pEndingStr))
{
2022-02-09 12:07:40 +00:00
tEndingID = i;
2022-02-09 11:36:47 +00:00
break;
}
}
2022-02-10 09:21:59 +00:00
//if no match,check with X
if (tEndingID == -1)
{
for (int i = 0; i < Endings.Count; i++)
{
if (Endings[i].IsMatching(pEndingStr, true))
{
tEndingID = i;
break;
}
}
}
2022-02-09 12:07:40 +00:00
return tEndingID;
2022-02-09 11:36:47 +00:00
}
2022-02-08 12:10:20 +00:00
}
[Serializable]
public class EndingData
{
public string EndingName;//only for editor display
public bool IsGoodEnding;
public string EndingCode;//eg: 12X;132;
2022-02-09 11:36:47 +00:00
2022-02-10 09:21:59 +00:00
public bool IsMatching(string pEndingStr, bool pWithX = false)
2022-02-09 11:36:47 +00:00
{
bool tMatching = false;
string[] tTemplateEndingStrs = EndingCode.Split(';');
for (int i = 0; i < tTemplateEndingStrs.Length; i++)
{
2022-02-10 09:21:59 +00:00
if ((pWithX && !tTemplateEndingStrs[i].Contains("X")) || (!pWithX && tTemplateEndingStrs[i].Contains("X")))
{
continue;
}
2022-02-09 11:36:47 +00:00
if (CompareEndingStr(pEndingStr, tTemplateEndingStrs[i]))
{
tMatching = true;
break;
}
}
return tMatching;
}
private bool CompareEndingStr(string pRefStr, string pTemplateStr)
{
bool tMatching = true;
for (int i = 0; i < pRefStr.Length; i++)
{
if (pTemplateStr[i] != 'X' && pRefStr[i] != pTemplateStr[i])
{
tMatching = false;
break;
}
}
return tMatching;
}
2022-02-08 12:10:20 +00:00
}