Esempio n. 1
0
    /// <summary>
    /// 生成高级合成按钮
    /// </summary>
    /// <param name="tt"></param>
    /// <param name="action"></param>
    private void CheckAdvanceCombine(TowerManager.TowerType tt, UnityAction action)
    {
        Button b = GetEmptyButtom();

        b.image.color = Color.white;
        b.GetComponentInChildren <Text>().text = "合成" + TowerManager.GetTowerName(tt);
        CombineTarget = tt;
        b.onClick     = new Button.ButtonClickedEvent();
        b.onClick.AddListener(action);
    }
Esempio n. 2
0
    /// <summary>
    /// 在鼠标点击防御塔时触发
    /// </summary>
    /// <param name="_SelectedObject"></param>
    private void TowerClickedAction(GameObject _SelectedObject)
    {
        SelectedObject = _SelectedObject;
        if (EnabledAttackRange != null)
        {
            EnabledAttackRange.enabled = false;
        }
        EnabledAttackRange         = SelectedObject.transform.GetChild(0).GetComponent <SpriteRenderer>();
        EnabledAttackRange.enabled = true;

        ClearUI();
        ItemInfo1.text       = TowerManager.GetTowerName(TowerManager.GetTowerType(SelectedObject));
        ItemInfo2.text       = String.Format("攻击力:{0}", Mathf.Round(SelectedObject.GetComponent <TowerController>().PhysicalDamage));
        ItemInfo3.text       = String.Format("基础攻击间隔:{0}s", SelectedObject.GetComponent <TowerController>().BasicAttackTime);
        ItemInfo4.text       = String.Format("攻击速度:{0}", SelectedObject.GetComponent <TowerController>().AttackSpeed);
        ItemDescription.text = SelectedObject.GetComponent <TowerController>().TowerDescription;

        switch (CurrentPhase)
        {
        case Phase.SecetingTower:
            var updateTowers = TowerCombiningManager.GetCombinableTowers(OneTurnTowerList, true);
            if (OneTurnTowerList.Contains(SelectedObject))
            {
                Button1.image.color = Color.white;
                Button1.GetComponentInChildren <Text>().text = "保留这个";
                Button1.onClick = new Button.ButtonClickedEvent();
                Button1.onClick.AddListener(RemainSelectedTower);

                if (updateTowers.ContainsKey(SelectedObject))
                {
                    foreach (TowerManager.TowerType tt in updateTowers[SelectedObject])
                    {
                        if (TowerCombiningManager.CanUpgrade(SelectedObject, tt))
                        {
                            Button2.image.color = Color.white;
                            Button2.GetComponentInChildren <Text>().text = "升级";
                            Button2.onClick = new Button.ButtonClickedEvent();
                            Button2.onClick.AddListener(UpgradeSelectedTower);
                        }
                        else if (TowerCombiningManager.CanSuperUpgrade(SelectedObject, tt))
                        {
                            Button3.image.color = Color.white;
                            Button3.GetComponentInChildren <Text>().text = "超级升级";
                            Button3.onClick = new Button.ButtonClickedEvent();
                            Button3.onClick.AddListener(SuperUpgradeSelectedTower);
                        }
                        else
                        {
                            CheckAdvanceCombine(tt, LuckyCombine);
                        }
                    }
                }

                TowerManager.TowerType t = TowerManager.GetTowerType(SelectedObject);
                if ((int)t % 6 != 1 && PlayerGold >= 200)
                {
                    try
                    {
                        Button b = GetEmptyButtom();
                        b.image.color = Color.white;
                        b.GetComponentInChildren <Text>().text = "随机降级\n(200金币)";
                        b.onClick = new Button.ButtonClickedEvent();
                        b.onClick.AddListener(() =>
                        {
                            int downgradeValue = random.Next((int)t % 6 - 1);
                            SelectedObject.transform.localScale -= Vector3.one * 0.1f * (downgradeValue + 1);
                            TowerManager.SettingTower(SelectedObject.GetComponent <TowerController>(), (TowerManager.TowerType)((int)t - downgradeValue - 1));
                            PlayerGold -= 200;
                            RemainSelectedTower();
                        });
                    }
                    catch (Exception)
                    {
                    }
                }
            }
            break;

        case Phase.EnemySpawning:
            updateTowers = TowerCombiningManager.GetCombinableTowers(TowerList, false);
            if (updateTowers.ContainsKey(SelectedObject))
            {
                foreach (TowerManager.TowerType tt in updateTowers[SelectedObject])
                {
                    CheckAdvanceCombine(tt, Combine);
                }
            }
            break;

        default:
            break;
        }
    }
Esempio n. 3
0
    /// <summary>
    /// 生成初始地图
    /// </summary>
    private IEnumerator CreateWorld()
    {
        NavSet.Add(GameObject.Find("Plane").transform.GetComponent <NavMeshSurface>());
        NavSet.Add(GameObject.Find("LeftWall").transform.GetComponent <NavMeshSurface>());
        NavSet.Add(GameObject.Find("RightWall").transform.GetComponent <NavMeshSurface>());
        NavSet.Add(GameObject.Find("TopWall").transform.GetComponent <NavMeshSurface>());
        NavSet.Add(GameObject.Find("BottomWall").transform.GetComponent <NavMeshSurface>());

        int gap = 1;

        foreach (int posX in Enumerable.Range(0, WorldWidth))
        {
            FloorMap.Add(new List <GameObject>());
            foreach (int posY in Enumerable.Range(0, WorldHeight))
            {
                GameObject addedObject = null;

                //外墙
                if (posX == 0 || posY == 0 || posX == WorldWidth - 1 || posY == WorldHeight - 1)
                {
                    addedObject        = CreateOuterWall(new Vector3(posX, posY, -1f));
                    IntMap[posX, posY] = -1;
                }
                //入口
                else if (posX == Enter.x && posY == Enter.y)
                {
                    addedObject = Instantiate(ExitDown, transform.GetChild(1).GetChild(0).transform);
                    addedObject.transform.position = new Vector3(posX, posY, -1f);
                    addedObject.GetComponent <BoxCollider2D>().size = new Vector2(2.5f, 2.5f);
                    addedObject.GetComponent <ColliderEventHandler>().EnemyExitEvent += (go) =>
                    {
                        if (CurrentEnemyAcount < EnemyPerLevel)
                        {
                            SpawnEnemy();
                        }
                    };
                }
                //出口
                else if (posX == Exit.x && posY == Exit.y)
                {
                    addedObject = Instantiate(ExitRight, transform.GetChild(1).GetChild(0).transform);
                    addedObject.transform.position = new Vector3(posX, posY, -1f);
                    addedObject.GetComponent <ColliderEventHandler>().EnemyEnterEvent += (go) =>
                    {
                        var nav = EnemyDic[go].transform.GetComponent <NavMeshAgent>();
                        if (nav.destination.x == posX && nav.destination.z == posY)
                        {
                            var ec = go.GetComponent <EnemyController>();
                            Health     -= Mathf.RoundToInt((0f + ec.MaxDamageToPlayer) * ec.Health / ec.MaxHealth + 1);
                            PlayerGold -= ec.Experience;
                            PlayerExp  -= ec.Experience;
                            DestroyEnemy(go);
                        }
                    };
                }
                //第一个拐点
                else if (posX == TurningPoint1.x && posY == TurningPoint1.y)
                {
                    addedObject = Instantiate(ExitRight, transform.GetChild(1).GetChild(0).transform);
                    addedObject.transform.position = new Vector3(posX, posY, -1f);
                    addedObject.GetComponent <ColliderEventHandler>().EnemyEnterEvent += (go) =>
                    {
                        var nav = EnemyDic[go].transform.GetComponent <NavMeshAgent>();
                        if (nav.destination.x == posX && nav.destination.z == posY)
                        {
                            nav.SetDestination(new Vector3(TurningPoint2.x, 0.275f, TurningPoint2.y));
                        }
                    };
                }
                //第二个拐点
                else if (posX == TurningPoint2.x && posY == TurningPoint2.y)
                {
                    addedObject = Instantiate(ExitUp, transform.GetChild(1).GetChild(0).transform);
                    addedObject.transform.position = new Vector3(posX, posY, -1f);
                    addedObject.GetComponent <ColliderEventHandler>().EnemyEnterEvent += (go) =>
                    {
                        var nav = EnemyDic[go].transform.GetComponent <NavMeshAgent>();
                        if (nav.destination.x == posX && nav.destination.z == posY)
                        {
                            nav.SetDestination(new Vector3(TurningPoint3.x, 0.275f, TurningPoint3.y));
                        }
                    };
                }
                //第三个拐点
                else if (posX == TurningPoint3.x && posY == TurningPoint3.y)
                {
                    addedObject = Instantiate(ExitLeft, transform.GetChild(1).GetChild(0).transform);
                    addedObject.transform.position = new Vector3(posX, posY, -1f);
                    addedObject.GetComponent <ColliderEventHandler>().EnemyEnterEvent += (go) =>
                    {
                        var nav = EnemyDic[go].transform.GetComponent <NavMeshAgent>();
                        if (nav.destination.x == posX && nav.destination.z == posY)
                        {
                            nav.SetDestination(new Vector3(TurningPoint4.x, 0.275f, TurningPoint4.y));
                        }
                    };
                }
                //第四个拐点
                else if (posX == TurningPoint4.x && posY == TurningPoint4.y)
                {
                    addedObject = Instantiate(ExitDown, transform.GetChild(1).GetChild(0).transform);
                    addedObject.transform.position = new Vector3(posX, posY, -1f);
                    addedObject.GetComponent <ColliderEventHandler>().EnemyEnterEvent += (go) =>
                    {
                        var nav = EnemyDic[go].transform.GetComponent <NavMeshAgent>();
                        if (nav.destination.x == posX && nav.destination.z == posY)
                        {
                            nav.SetDestination(new Vector3(TurningPoint5.x, 0.275f, TurningPoint5.y));
                        }
                    };
                }
                //第五个拐点
                else if (posX == TurningPoint5.x && posY == TurningPoint5.y)
                {
                    addedObject = Instantiate(ExitRight, transform.GetChild(1).GetChild(0).transform);
                    addedObject.transform.position = new Vector3(posX, posY, -1f);
                    addedObject.GetComponent <ColliderEventHandler>().EnemyEnterEvent += (go) =>
                    {
                        var nav = EnemyDic[go].transform.GetComponent <NavMeshAgent>();
                        if (nav.destination.x == posX && nav.destination.z == posY)
                        {
                            nav.SetDestination(new Vector3(Exit.x, 0.275f, Exit.y));
                        }
                    };
                }
                //地板
                else
                {
                    addedObject = CreateFloor(new Vector3(posX, posY, -1f));
                }
                FloorMap[posX].Add(addedObject);

                if (posY % gap == 0)
                {
                    yield return(0);
                }
            }
            gap++;
        }


        //创建游戏开始时在固定位置生成的内墙
        foreach (int i in new int[] { 1, 2, 3, 4, 6, 7, 8, 9, 37, 36, 35, 34, 32, 31, 30, 29 })
        {
            CreateInnerWall(new Vector3(i, 19f, -1f));
            yield return(0);

            CreateInnerWall(new Vector3(19f, i, -1f));
            yield return(0);
        }
        UI.SetActive(true);

        yield return(0);

        InfoMessage.text       = "点击地板创建" + TowerPerTurn + "个随机防御塔";
        MazeLengthMessage.text = "迷宫长度:" + GetMazeLength();
        EnemyInfo.text         = "第1拨: 普通敌人";
        Health = 100;

        CombinePanelButton.onClick.AddListener(() =>
        {
            CombinePanel.SetActive(true);

            HashSet <TowerManager.TowerType> ConstructingTowerSet = new HashSet <TowerManager.TowerType>();

            foreach (GameObject tower in OneTurnTowerList)
            {
                TowerManager.TowerType tt = TowerManager.GetTowerType(tower);
                if (!ConstructingTowerSet.Contains(tt))
                {
                    ConstructingTowerSet.Add(tt);
                }
            }

            foreach (TowerManager.TowerType tt in ConstructingTowerSet)
            {
                if (TowerManager.GetTowerTag(tt) != "Untagged")
                {
                    foreach (var go in GameObject.FindGameObjectsWithTag(TowerManager.GetTowerTag(tt)))
                    {
                        go.GetComponent <Text>().color = new Color32(0xF1, 0xFF, 0x00, 0xFF);
                    }
                }
            }

            HashSet <TowerManager.TowerType> ConstructedTowerSet = new HashSet <TowerManager.TowerType>();

            foreach (GameObject tower in TowerList)
            {
                TowerManager.TowerType tt = TowerManager.GetTowerType(tower);
                if (!ConstructedTowerSet.Contains(tt))
                {
                    ConstructedTowerSet.Add(tt);
                }
            }

            foreach (TowerManager.TowerType tt in ConstructedTowerSet)
            {
                if (TowerManager.GetTowerTag(tt) != "Untagged")
                {
                    foreach (var go in GameObject.FindGameObjectsWithTag(TowerManager.GetTowerTag(tt)))
                    {
                        go.GetComponent <Text>().color = new Color32(0xFF, 0x00, 0x00, 0xFF);
                    }
                }
            }
        });

        ready = true;
        yield return(0);
    }