Example #1
0
    void SolidificateTowerShape(TowerShape pickTower)
    {
        if (pickTower != null && pickTower.IsSolidificated == false)
        {
            bool allowance = false;

            if (pickTower.gameObject.GetComponent <AttackTowerEntity>() != null)
            {
                AttackTowerEntity tmp = pickTower.gameObject.GetComponent <AttackTowerEntity>();
                allowance = tmp.Solidification();
            }
            else if (pickTower.gameObject.GetComponent <DefenceTowerEntity>() != null)
            {
                DefenceTowerEntity tmp = pickTower.gameObject.GetComponent <DefenceTowerEntity>();
                allowance = tmp.Solidification();
            }
            else if (pickTower.gameObject.GetComponent <ProductionTowerEntity>() != null)
            {
                ProductionTowerEntity tmp = pickTower.gameObject.GetComponent <ProductionTowerEntity>();
                allowance = tmp.Solidification();
            }
            if (allowance)
            {
                TestPack.TowerChange(pickTower);
                pickTower.IsSolidificated = true;
                this.money -= data.solidificateCost;
            }
        }
        else
        {
            Debug.Log("Tower already solidificreate AttackTowered");
        }
    }
Example #2
0
 public void DT()
 {
     if (selectTypeHandler == 1 && pickTower != null)
     {
         TowerEntity t = pickTower.gameObject.GetComponent <TowerEntity>();
         if (t.SelfDestruction() == true)
         {
             if (this.money > data.deconstructionCost)
             {
                 if (pickTower != null)
                 {
                     TestPack.DestoryOwnTower(pickTower);
                 }
                 DestroyTowerShape(pickTower);
                 selectTypeHandler = 0;
                 this.money       -= data.deconstructionCost;
             }
             else
             {
                 Debug.Log("Not enough money to deconstruct!");
             }
         }
         else
         {
             Debug.Log("Not allowed to deconstruct!");
         }
     }
     else
     {
         Debug.Log("No tower selected.");
     }
 }
Example #3
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!");
        }
    }
Example #4
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]);
        }
    }
Example #5
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(createAttackTower))
        {
            CAT();
        }
        else if (Input.GetKeyDown(createDefenseTower))
        {
            CDT();
        }
        else if (Input.GetKeyDown(createProductionTower))
        {
            CPT();
        }
        else if (Input.GetKeyDown(solidificateTower))
        {
            SAT();
        }
        else if (Input.GetKeyDown(destroyTower))
        {
            DT();
        }
        else if (Input.GetKeyDown(antiClockwiseConvert))
        {
            ACC();
        }
        else if (Input.GetKeyDown(clockwiseConvert))
        {
            CC();
        }

        //游戏结束
        TestPack.GameOver();

        //if (Input.GetMouseButton(0))
        if ((Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began))
        {
            //if (!UnityEngine.EventSystems.EventSystem.current.IsPointerOverGameObject())
            if (!UnityEngine.EventSystems.EventSystem.current.IsPointerOverGameObject(Input.GetTouch(0).fingerId))
            {
                Debug.Log("1");
                MobilePick();
            }
        }

        if (Input.GetKeyDown(KeyCode.H))
        {
            SpawnDpsEnemy();
        }
        if (Input.GetKeyDown(KeyCode.J))
        {
            SpawnTEnemy();
        }
        TimeToSpawnAround();
        TimeToSpawn();
        GameUpdate();
        forceSlider.value = enemyTowerCount == 0?1:(float)towerShapes.Count / (towerShapes.Count + enemyTowerCount);
        costText.text     = "初光: " + money.ToString();

        if (inEnemyScene)
        {
            enemySceneTimer += Time.deltaTime;
            if (enemySceneTimer <= 1f)
            {
                camera.transform.position = new Vector3(-1200 * enemySceneTimer * enemySceneTimer + 2400 * enemySceneTimer + 100, ypos, zpos);
            }
            else if (enemySceneTimer >= 3f && enemySceneTimer < 4f)
            {
                camera.transform.position = new Vector3(-1200 * enemySceneTimer * enemySceneTimer + 7200 * enemySceneTimer - 9500, ypos, zpos);
            }
            else if (enemySceneTimer >= 4f)
            {
                camera.transform.position = new Vector3(100, ypos, zpos);
                inEnemyScene    = false;
                enemySceneTimer = 0f;
            }
        }
    }