Example #1
0
    public void SelectTower(Tower tower)
    {
        // if there was a previously selected Tower, first reset it
        if (selectedTower != null)
        {
            selectedTower.SetSelected(false);
        }

        if (tower == null)
        {
            selectedTower = null;
            shopGO.GetComponent <ShopButtonManager>().HideShop();
        }
        else
        {
            // first deselect a possible selected TowerPoint
            if (selectedTowerPoint != null)
            {
                selectedTowerPoint.SetSelected(false);
                selectedTowerPoint = null;
            }

            tower.SetSelected(true);
            selectedTower = tower;
            shopGO.GetComponent <ShopButtonManager>().ShowShop(this);
        }
    }
    public void BuildTower(TowerBuildButton towerPrefabHolder)
    {
        int towerCost = towerPrefabHolder.towerPrefab.GetComponent <Tower>().cost;

        Controller.Instance.Money -= towerCost;
        SelectedPoint.Selected     = false; // Do not move
        StartCoroutine(TowerBuilding(towerPrefabHolder.towerPrefab, SelectedPoint));
        SelectedPoint = null;
    }
    public void PointPressed(TowerPoint point)
    {
        if (SelectedPoint != null)
        {
            if (SelectedPoint == point)
            {
                SelectedPoint = null;
                return;
            }
            else
            {
                SelectedPoint.Selected = false;
                SelectedPoint.SetHighlight(false);
            }
        }

        SelectedPoint = point;
    }
    private IEnumerator TowerBuilding(GameObject newTower, TowerPoint point)
    {
        // Point stuff
        point.gameObject.SetActive(false);
        point.SetHighlight(false);
        // Tower stuff
        var towerScript = newTower.GetComponent <Tower>();
        var buildTime   = towerScript.buildTime;

        if (!Controller.Instance.GameStarted)
        {
            buildTime = 1;
        }
        var progressBarOffset = towerScript.buildBarOffset;
        // Effect stuff
        var effect = Instantiate(buildEffect, point.transform.position, Quaternion.identity).GetComponent <EffectController>();

        effect.GetComponent <TimedDestruction>().StartDestruction(effect.SetDuration(buildTime));
        effect.SetParticleMaterial(towerScript.particleMaterial);
        effect.PlayEffect();
        // ProgressBar stuff
        var progressBar = Controller.Instance.PlaceHealthBar();

        progressBar.transform.position = point.transform.position + progressBarOffset;
        progressBar.SetValue(0);
        // Start
        float startTime = Time.time;

        for (float progress = 0; progress < 1;)
        {
            progress = Mathf.Lerp(0, 1, (Time.time - startTime) / buildTime);
            progressBar.SetValue(progress);
            yield return(null);
        }

        var tower          = Instantiate(newTower, point.transform.position, Quaternion.identity);
        var newTowerScript = tower.GetComponent <Tower>();

        newTowerScript.buildPoint = point;
        newTowerScript.Circle     = Instantiate(circlePrefab, tower.transform);
        Destroy(progressBar.gameObject);
    }
Example #5
0
    public void SellTower()
    {
        if (selectedTower == null)
        {
            return;
        }

        // reenable the TowerPoint below the tower's GameObject
        TowerPoint towerPoint = selectedTower.GetTowerPoint();

        towerPoint.gameObject.SetActive(true);

        // get currency back
        // TODO:

        // destroy the selected tower's game object
        Destroy(selectedTower.gameObject);

        ClearSelection();
    }
Example #6
0
 public void SetTowerPoint(TowerPoint _towerPoint)
 {
     this.towerPoint = _towerPoint;
 }
 public void SetTowerPointPosition(Vector3 pos, TowerPoint towerPoint)
 {
     _towerPointPosition = pos;
     _towerPoint         = towerPoint;
 }
    /// <summary>
    /// 创建单位
    /// </summary>
    /// <param name="unitType">单位类型</param>
    /// <param name="dataId">数据ID</param>
    /// <returns>地图单元类</returns>
    public T CreateUnit <T>(UnitType unitType, int dataId) where T : MapCellBase
    {
        // 地图单元与障碍物使用相同单元替换Image的方式进行服用, 来解决创建单位过多问题
        MapCellBase result = null;

        switch (unitType)
        {
        // ---------------------------加载数据进行替换模式----------------------------
        case UnitType.MapCell:     // 地图单元
        {
            result = new MapCell(null, dataId, MapManager.MapBaseLayer);
        }
        break;

        case UnitType.Obstacle:     // 障碍物
        {
            var go = GetGameObject(MapCellTableName,
                                   dataId,
                                   MapDrawer.Single.ItemParentList[MapManager.MapObstacleLayer]);

            result  = new Obstacle(go, dataId, MapManager.MapObstacleLayer);
            go.name = result.MapCellId.ToString();
            go.SetActive(true);
        }
        break;

        // ---------------------------------加载预设模式---------------------------------
        case UnitType.FightUnit:     // 战斗单位
        {
            var go = GetGameObject(MapCellTableName,
                                   dataId,
                                   MapDrawer.Single.ItemParentList[MapManager.MapPlayerLayer]);

            result  = new FightUnit(go, dataId, MapManager.MapPlayerLayer);
            go.name = result.MapCellId.ToString();
            go.SetActive(true);
        }
        break;

        case UnitType.NPC:     // NPC
        {
            var go = GetGameObject(MapCellTableName,
                                   dataId,
                                   MapDrawer.Single.ItemParentList[MapManager.MapNpcLayer]);

            // TODO 区分出兵点入兵点
            switch (dataId)
            {
            case 301:
                // 出兵点
                result = new OutMonsterPoint(go, dataId, MapManager.MapObstacleLayer);
                break;

            case 302:
                // 入兵点
                result = new InMonsterPoint(go, dataId, MapManager.MapObstacleLayer);
                break;

            case 401:
                // 塔基
                result = new TowerPoint(go, dataId, MapManager.MapObstacleLayer);
                break;

            default:
                result = new Npc(go, dataId, MapManager.MapNpcLayer);
                break;
            }
            go.name = result.MapCellId.ToString();
            go.SetActive(true);
        }
        break;

        case UnitType.Tower:
        {
            // 创建塔
            var go = GetGameObject(MapCellTableName,
                                   dataId,
                                   MapDrawer.Single.ItemParentList[MapManager.MapNpcLayer]);
            result = new Tower(go, dataId, MapManager.MapPlayerLayer);
            // 设置数据
            go.name = result.MapCellId.ToString();
            go.SetActive(true);
        }
        break;

        case UnitType.TowerCell:
        {
            // 创建塔单元
            var go = GetGameObject(MapCellTableName,
                                   dataId,
                                   MapDrawer.Single.ItemParentList[MapManager.MapPlayerLayer]);
            result = new TheFiveCellBase(go, dataId, MapManager.MapPlayerLayer);
            // 设置数据
            go.name = result.MapCellId.ToString();
            go.SetActive(true);
        }
        break;
        }



        return((T)result);
    }