Ejemplo n.º 1
0
    public void DestroyTowerShape(TowerShape pickTower)
    {
        if (towerShapes.Count > 0)
        {
            //int index = Random.Range(0, towerShapes.Count);
            int index = towerShapes.FindIndex(a => a.SerialId == pickTower.SerialId);
            //
            foreach (Enemy enemy in enemies)
            {
                if (pickTower.GetComponent <DefenceTowerEntity>() != null)
                {
                    enemy.isLock = false;
                }
            }
            //

            // release cell
            TowerEntity t = pickTower.gameObject.GetComponent <TowerEntity>();
            t.cell.available = true;
            if (t.linkTowers.Count > 0)
            {
                t.solidificationLinkCells[0].available = true;
                t.solidificationLinkCells[1].available = true;
            }

            towerShapeFactory.Reclaim(towerShapes[index]);
            //Switch the index of selected and last one
            int lastIndex = towerShapes.Count - 1;
            towerShapes[index] = towerShapes[lastIndex];
            towerShapes.RemoveAt(lastIndex);
            TestPack.TowerNum(towerShapes);

            //Disable selected outline
            //highLightObj.gameObject.SetActive(false);
            //selectedObject.GetComponent<MeshRenderer>().material = previousMaterial;
            //selectedObject = null;
            highLightObj.gameObject.SetActive(false);
            for (int i = 0; i < enemies.Count; i++)
            {
                SearchAndGo(enemies[i]);
            }
        }
        else
        {
            Debug.Log("No tower in pools to destroy!");
        }
    }
Ejemplo n.º 2
0
    void CreateTowerShape(int towerId, HexCell buildRegion, int initState, float healthFactor = 1)
    {
        TowerShape  instance = towerShapeFactory.Get(towerId, towerId);
        Transform   t        = instance.transform;
        TowerEntity e        = instance.gameObject.GetComponent <TowerEntity>();

        e.health = (int)(e.maxHealth * healthFactor);

        if (buildRegion == null)
        {
            Debug.LogError("No cell found?");
        }
        else
        {
            e.cell                = buildRegion;
            buildPosition         = HexCoordinates.FromCoordinate(buildRegion.coordinates);
            instance.coordinates  = buildRegion.coordinates;
            buildRegion.available = false;
        }

        //Care if move the root of prefabs to ground
        t.localPosition = buildPosition;
        if (t.localScale.y >= 6)
        {
            t.localScale /= data.factorScale;
        }

        //Create link if production tower
        //if(towerId == 2)
        //      mapManager.hexGrid.CreatePowerLinkToCell(
        //       instance.gameObject.GetComponent<ProductionTowerEntity>());

        towerShapes.Add(instance);
        TestPack.TowerNum(towerShapes);

        instance.GetComponent <TowerEntity>().state = initState;

        for (int i = 0; i < enemies.Count; i++)
        {
            SearchAndGo(enemies[i]);
        }
    }