本篇介绍对植物卡牌的选择以及关卡功能的实现,主要为进入冒险模式后首先进入关卡的选择然后进行植物的卡牌选择。
首先在关卡进入后会镜头右移展示僵尸,之后在选择卡片之后进入僵尸的刷新。
public LVState CurrLVState { get => currLVState;
set {
currLVState = value;
switch (currLVState)
{
case LVState.Start:
// 隐藏UI主面板
UIManager.Instance.SetMainPanelActive(false);
// 刷新僵尸秀的僵尸
ZombieManager.Instance.UpdateZombie(5,ZombieType.Zombie);
// 摄像机移动到右侧观察关卡僵尸
Camera_C.Instance.StartMove(LVStartCameraBackAction);
break;
case LVState.Figth:
// 显示主面板
UIManager.Instance.SetMainPanelActive(true);
// 20秒以后刷一只僵尸
UpdateZombie(2, 1);
break;
case LVState.Over:
break;
}
}
}
无尽模式的逻辑为击杀完毕当前天数的僵尸后进入第二天。
public int StageInLV { get => stageInLV;
set {
stageInLV = value;
UIManager.Instance.UpdateStageNum(stageInLV - 1);
if (stageInLV>2)
{
// 杀掉当前关卡的全部僵尸,就进入下一天
ZombieManager.Instance.AddAllZombieDeadAction(OnAllZombieDeadAction);
CurrLVState = LVState.Over;
//根据当前天数选择场景关卡
if (CurrLV == 2)
{
StartSceneManager.Instance.GoAdventureR();
}
}
}
}
接下来是植物的卡牌选择功能实现
private void Awake(){
foreach (var item in mainPanleGroup.GetComponentsInChildren<UIPlantCard>())
{
if (!Dic_CardPrice.ContainsKey(item.CardPlantType))
{
Dic_CardPrice[item.CardPlantType] = item.WantSunNum;
}
}
foreach (var card in cardContainer.GetComponentsInChildren<UISelectCard>())
{
if (Dic_CardPrice.ContainsKey(card.PlantType))
{
card.GetComponentInChildren<Text>().text = Dic_CardPrice[card.PlantType] + "";
}
card.GetComponent<Button>().onClick.AddListener(()=>OnPlantClick(card));
}
bag = JsonUtility.FromJson<ShopData>(System.IO.File.ReadAllText(Application.streamingAssetsPath + "/shop.json"));
for (int i = 0; i < bagItemBtns.Length; i++)
{
bagItemBtns[i].interactable = ( bag.data[i].crrentCount > 0 );
}
}
public void OnPlantClick(UISelectCard card)
{
if (SelectPlants.Contains(card.PlantType))
{
SelectPlants.Remove(card.PlantType);
card.GetComponent<Image>().color = deselectedColor;
}
else
{
if (SelectPlants.Count < CardSelectDialog.maxSelectPlantNum)
{
SelectPlants.Add(card.PlantType);
card.GetComponent<Image>().color = selectedColor;
}
}
}
public void OnSubmitClick()
{
Show(false);
}
public void OnResetClick()
{
SelectPlants.Clear();
foreach (var card in cardContainer.GetComponentsInChildren<UISelectCard>())
{
card.GetComponent<Image>().color = deselectedColor;
}
}
public void Show(bool b=true)
{
Time.timeScale = b?0:1;
gameObject.SetActive(b);
if (b) OnResetClick();
}
public bool IsPlantBeSelected(PlantType plantType)
{
return SelectPlants.Contains(plantType);
}