项目实训(十一)

本篇介绍对植物卡牌的选择以及关卡功能的实现,主要为进入冒险模式后首先进入关卡的选择然后进行植物的卡牌选择。

首先在关卡进入后会镜头右移展示僵尸,之后在选择卡片之后进入僵尸的刷新。

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);
    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值