Exemplo n.º 1
0
    public GameObject CreateTurret(Vector3 pos)
    {
        GameObject newTurret = null;

        int price = TurretInfo.GetTurretInfo(selectableTurrets[selectedTurret]).price[0];

        if (stageController.gold >= price)
        {
            newTurret = Instantiate(selectablePrefabs[selectedTurret]);

            TurretScript ts = newTurret.GetComponent <TurretScript>();
            ts.SetPosition(pos);

            list_turret.Add(ts);

            if (ts.turretID == TurretInfo.TURRET_MINORIKO)
            {
                MinorikoScript ms = newTurret.GetComponent <MinorikoScript>();
                if (ms != null)
                {
                    list_minoriko.Add(ms);
                }
            }

            stageController.gold -= price;
        }

        return(newTurret);
    }
Exemplo n.º 2
0
    //public void SelectTurret(int index)
    //{
    //    if (index < 0 || index >= turretCount) return;
    //    selectedTurret = index;
    //    for(int i = 0; i < turretCount; i++)
    //    {
    //        if (i == index) buttons[i].SetSelected(true);
    //        else buttons[i].SetSelected(false);
    //    }

    //}

    //public void SelectTurret(TurretSelectButton tsb)
    //{
    //    SelectTurret(tsb.index);
    //}

    //public void CancelSelect()
    //{
    //    selectedTurret = -1;
    //    for (int i = 0; i < turretCount; i++)
    //    {
    //        buttons[i].SetSelected(false);
    //    }
    //}

    public bool CanCreateTurret(Vector3 wPos)
    {
        Vector3Int cPos = mapController.WorldToCell(wPos);
        Vector3    aPos = mapController.CellToArray(cPos);

        if (stageController.gold < TurretInfo.GetTurretInfo(selectableTurrets[selectedTurret]).price [0])
        {
            //AudioManager.instance.PlaySound("se_invalid");
            return(false);
        }

        if (mapController.CellOutOfBound(cPos))
        {
            return(false);
        }

        int i = mapController.GetMapArray()[(int)aPos.x, (int)aPos.y];//地块的标记

        if (i == Utils.GROUND || i == Utils.PLATFORM)
        {
            if (!mapController.gameObject.GetComponent <PathFinder>().CanPlaceTurret(new Vector2Int((int)aPos.x, (int)aPos.y)))
            {
                Debug.Log("不能把路堵死");
                //AudioManager.instance.PlaySound("se_invalid");
                return(false);
            }


            return(true);
        }

        return(false);
    }
Exemplo n.º 3
0
 public void ShowTurretInfo(int id)
 {
     show_image.sprite = TurretInfo.GetTurretInfo(id).buttonImage;
     show_name.text    = TurretInfo.GetTurretInfo(id).name;
     show_intro.text   = TurretInfo.GetTurretInfo(id).intro;
     show_msg1.text    = "价格:" + TurretInfo.GetTurretInfo(id).price[0];
     show_msg2.text    = "";
 }
Exemplo n.º 4
0
    public void CreateUIObjects()
    {
        HorizontalLayoutGroup layout = GetComponent <HorizontalLayoutGroup>();

        layout.spacing = turretCount;
        RectTransform rt = GetComponent <RectTransform>();

        rt.sizeDelta = new Vector2((turretCount) * 150 + 100, 150);

        buttons = new TurretSelectButton[turretCount];


        for (int i = 0; i < turretCount; i++)
        {
            GameObject         newButton = Instantiate(buttonPrefab, this.gameObject.transform);
            TurretSelectButton tsb       = newButton.GetComponent <TurretSelectButton>();
            //tsb.image.sprite = images[i];
            tsb.SetID(selectableTurrets[i]);
            tsb.index = i;

            Text price   = newButton.transform.Find("Price").GetComponent <Text>();
            Text keycode = newButton.transform.Find("Keycode").GetComponent <Text>();

            price.text   = ("$" + TurretInfo.GetTurretInfo(tsb.turretID).price [0]);
            keycode.text = i + 1 + "";

            tsb.button.onClick.AddListener(

                delegate {
                updateUI.HideTurretInfo();
                SelectTurret(tsb);
            }

                );

            tsb.SetSelected(false);

            buttons[i] = tsb;
        }
    }
Exemplo n.º 5
0
    void Start()
    {
        images    = new Sprite[8];
        images[0] = s0; images[1] = s1; images[2] = s2; images[3] = s3; images[4] = s4; images[5] = s5; images[6] = s6; images[7] = s7;

        enemyList = GameObject.Find("Map").GetComponent <EnemyController>().enemyList;

        shootCountdown = fireRate / 2;

        stage = GameObject.Find("Map").GetComponent <StageController>();

        //加载塔的信息
        info = TurretInfo.GetTurretInfo(this.turretID);
        //Debug.Log("info is loaded");
        maxLevel = info.maxLevel;

        price = TurretInfo.GetTurretInfo(this.turretID).price[0];
        //Debug.Log("name: " + info.name);
        SetLevelData(0);

        //Debug.Log(TextEffectManager.instance);
        //GameObject g = TextEffectManager.instance.ShowTurretLevel(this);
    }
Exemplo n.º 6
0
    // Update is called once per frame
    void Update()
    {
        if (stageController.pausing)
        {
            return;
        }


        Vector3    lPos   = Input.mousePosition;
        Vector3Int cPos   = mapController.WorldToCell(Camera.main.ScreenToWorldPoint(lPos));
        Vector3    newPos = mapController.CellToWorld(cPos);

        //如果所选地点不在场景内,不管
        if (mapController.CellOutOfBound(cPos))
        {
            mouseMark.GetComponent <RectTransform>().anchoredPosition = new Vector2(5000, 5000);
            return;
        }
        //如果在场景内
        else
        {
            //获取所选塔
            selectedTurret = ui.selectedTurret;
            //如果已经选取了塔
            if (selectedTurret != -1)
            {
                mouseMark.GetComponent <RectTransform>().anchoredPosition = Utils.GetUIPosition(newPos);
                float r     = TurretInfo.GetTurretInfo(selectableTurrets[selectedTurret]).range[0];
                float range = Utils.LengthLocalToUI(r * 2 * GameObject.Find("Map").GetComponent <MapController>().cellLocalSize);

                rangeMark.GetComponent <RectTransform>().sizeDelta = new Vector2(range, range);

                //能够造塔
                if (CanCreateTurret(newPos))
                {
                    mouseMark.GetComponent <Image>().color = Color.green;
                    //单击左键建造
                    if (Input.GetMouseButtonDown(0))
                    {
                        CreateTurret(newPos);

                        Vector3Int aPos = mapController.CellToArray(cPos);
                        mapController.mapArray[aPos.x, aPos.y] = Utils.TURRET;    //地图中此位置标记为TURRET

                        //敌人改变默认路径
                        GameObject.Find("Map").GetComponent <PathFinder>().RefreshDefaultPath();
                    }
                }
                //不能造塔
                else
                {
                    mouseMark.GetComponent <Image>().color = Color.red;

                    if (Input.GetMouseButtonDown(0))
                    {
                        AudioManager.instance.PlaySound("se_invalid");
                    }
                }
            }
            //没选中塔
            else
            {
                mouseMark.GetComponent <RectTransform>().anchoredPosition = new Vector2(5000, 5000);
                if (Input.GetMouseButtonDown(0))
                {
                    Vector3      wPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
                    TurretScript ts   = GetTurret(wPos);

                    if (ts != null && !GameObject.Find("TurretUpdateUI").GetComponent <TurretUpdateUIController>().Selected())
                    {
                        GameObject.Find("TurretUpdateUI").GetComponent <TurretUpdateUIController>().ShowTurretInfo(ts);
                    }
                }
            }
        }


        /*
         * //单机左键:摆放新炮塔或查看已摆放炮塔升级界面
         * if (Input.GetMouseButtonDown(0))
         * {
         *  selectedTurret = ui.selectedTurret;
         *
         *  //若已经选中炮塔:放置炮塔
         *  if(selectedTurret != -1)
         *  {
         *      //获得鼠标点击位置
         *      Vector3 lPos = Input.mousePosition;
         *      Vector3Int cPos = mapController.WorldToCell(Camera.main.ScreenToWorldPoint(lPos));
         *      Vector3 newPos = mapController.CellToWorld(cPos);
         *
         *      //如果所选地点不在场景内,不管
         *      if (mapController.CellOutOfBound(cPos)) return;
         *
         *
         *      //如果能放置,则根据选取的角色放置炮塔
         *      if (CanCreateTurret(newPos))
         *      {
         *          CreateTurret(newPos);
         *
         *          Vector3Int aPos = mapController.CellToArray(cPos);
         *          mapController.mapArray[aPos.x, aPos.y] = Utils.TURRET;    //地图中此位置标记为TURRET
         *
         *          //敌人改变默认路径
         *          GameObject.Find("Map").GetComponent<PathFinder>().RefreshDefaultPath();
         *          //Debug.Log("place a turret");
         *      }
         *      else
         *      {
         *          //AudioSource.PlayClipAtPoint(AudioManager.se_invalid,new Vector3(0,0,0));
         *          //AudioManager.instance.PlaySound("se_invalid");
         *      }
         *
         *      return;
         *  }
         *  //否则查看升级界面
         *  else
         *  {
         *
         *
         *  }
         *
         *
         * }*/

        //右键取消选择
        //if(Input.GetMouseButtonDown(1))
        //{
        //    CancelSelect();
        //}
    }