Example #1
0
        IEnumerator Building(float duration, bool reverse = false)
        {       //reverse flag is set to true when selling (thus unbuilding) the tower
            construction = !reverse ? _Construction.Constructing : _Construction.Deconstructing;

            builtDuration = 0;
            buildDuration = duration;

            if (onConstructionStartE != null)
            {
                onConstructionStartE(this);
            }

            yield return(null);

            if (!reverse && playConstructAnimation != null)
            {
                playConstructAnimation();
            }
            else if (reverse && playDeconstructAnimation != null)
            {
                playDeconstructAnimation();
            }

            while (true)
            {
                yield return(null);

                builtDuration += Time.deltaTime;
                if (builtDuration > buildDuration)
                {
                    break;
                }
            }

            construction = _Construction.None;

            if (!reverse && onConstructionCompleteE != null)
            {
                onConstructionCompleteE(this);
            }

            if (reverse)
            {
                if (onSoldE != null)
                {
                    onSoldE(this);
                }

                if (occupiedPlatform != null)
                {
                    occupiedPlatform.UnbuildTower(occupiedNode);
                }
                ResourceManager.GainResource(GetValueSell());
                Dead();
            }
        }
Example #2
0
        IEnumerator Building(float duration, bool reverse=false)
        {
            //reverse flag is set to true when selling (thus unbuilding) the tower
            construction=!reverse ? _Construction.Constructing : _Construction.Deconstructing;

            builtDuration=0;
            buildDuration=duration;

            if(onConstructionStartE!=null) onConstructionStartE(this);

            yield return null;
            if(!reverse && playConstructAnimation!=null) playConstructAnimation();
            else if(reverse && playDeconstructAnimation!=null) playConstructAnimation();

            while(true){
                yield return null;
                builtDuration+=Time.deltaTime;
                if(builtDuration>buildDuration) break;
            }

            construction=_Construction.None;

            if(!reverse && onConstructionCompleteE!=null) onConstructionCompleteE(this);

            if(reverse){
                if(onSoldE!=null) onSoldE(this);

                ResourceManager.GainResource(GetValue());
                Dead();
            }
        }
Example #3
0
        IEnumerator Building(bool isUpgrade, float duration, bool reverse = false)                      //reverse flag is set to true when selling (thus unbuilding) the tower
        {
            construction = !reverse ? _Construction.Constructing : _Construction.Deconstructing;
            float builtTime = 0;      buildProgress = 0;

            if (hideWhenBuilding)
            {
                Utility.DisableAllChildRendererRecursively(thisT);
            }

            if (!isUpgrade)
            {
                TDTK.OnTowerConstructing(this);
            }
            else
            {
                TDTK.OnTowerUpgrading(this);
            }

            if (buildingEffect != null)
            {
                if (!destroyBuildingEffect)
                {
                    ObjectPoolManager.Spawn(buildingEffect, thisT.position, thisT.rotation);
                }
                else
                {
                    ObjectPoolManager.Spawn(buildingEffect, thisT.position, thisT.rotation, destroyBuildingDuration);
                }
            }

            yield return(null);

            if (!reverse)
            {
                PlayAnimConstruct();
            }
            else
            {
                PlayAnimDeconstruct();
            }
            //~ if(!reverse && playConstructAnimation!=null) playConstructAnimation();
            //~ else if(reverse && playDeconstructAnimation!=null) playDeconstructAnimation();

            while (true)
            {
                yield return(null);

                builtTime += Time.deltaTime;

                if (!reverse)
                {
                    buildProgress = builtTime / duration;
                }
                else
                {
                    buildProgress = (duration - builtTime) / duration;
                }

                if (builtTime > duration)
                {
                    break;
                }
            }

            construction = _Construction.None;        buildProgress = 1;

            if (!reverse)
            {
                Utility.EnbleAllChildRendererRecursively(thisT);

                if (!isUpgrade)
                {
                    TDTK.OnTowerConstructed(this);
                }
                else
                {
                    TDTK.OnTowerUpgraded(this);
                }

                if (builtEffect != null)
                {
                    if (!destroyBuiltEffect)
                    {
                        ObjectPoolManager.Spawn(builtEffect, thisT.position, thisT.rotation);
                    }
                    else
                    {
                        ObjectPoolManager.Spawn(builtEffect, thisT.position, thisT.rotation, destroyBuiltDuration);
                    }
                }
            }

            if (reverse)
            {
                ResourceManager.GainResource(GetValue());
                TDTK.OnTowerSold(this);
                RemoveFromGame();
            }
        }
Example #4
0
        IEnumerator Building(float duration, bool reverse = false)
        {   //reverse flag is set to true when selling (thus unbuilding) the tower
            bool possible = BuildManager.instance.UpdatePathMaps(this, reverse);

            if (!possible)
            {
                reverse = true;
            }


            construction = !reverse ? _Construction.Constructing : _Construction.Deconstructing;

            builtDuration = 0;
            buildDuration = duration;

            if (onConstructionStartE != null)
            {
                onConstructionStartE(this);
            }

            yield return(null);

            if (!reverse && playConstructAnimation != null)
            {
                playConstructAnimation();
            }
            else if (reverse && playDeconstructAnimation != null)
            {
                playConstructAnimation();
            }

            while (true)
            {
                yield return(null);

                builtDuration += Time.deltaTime;
                if (builtDuration > buildDuration)
                {
                    break;
                }
            }

            construction = _Construction.None;

            if (!reverse && onConstructionCompleteE != null)
            {
                onConstructionCompleteE(this);
            }

            buildFinished();

            if (reverse)
            {
                if (onSoldE != null)
                {
                    onSoldE(this);
                }

                if (possible)
                {
                    ResourceManager.GainResource(GetValue());
                }

                // if tower is destructed, destroy drone
                if (drone != null)
                {
                    Destroy(drone);
                }


                if (moveObjectHndl != null)
                {
                    StopCoroutine(moveObjectHndl);
                }
                Dead();
            }
        }
Example #5
0
        IEnumerator Building(float duration, bool reverse=false)
        {
            //reverse flag is set to true when selling (thus unbuilding) the tower
            construction=!reverse ? _Construction.Constructing : _Construction.Deconstructing;

            builtDuration=0;
            buildDuration=duration;

            if(onConstructionStartE!=null) onConstructionStartE(this);

            if(buildingEffect!=null) ObjectPoolManager.Spawn(buildingEffect, thisT.position, thisT.rotation);

            yield return null;
            if(!reverse && playConstructAnimation!=null) playConstructAnimation();
            else if(reverse && playDeconstructAnimation!=null) playDeconstructAnimation();

            while(true){
                yield return null;
                builtDuration+=Time.deltaTime;
                if(builtDuration>buildDuration) break;
            }

            construction=_Construction.None;

            if(!reverse) {
                if(onConstructionCompleteE != null) onConstructionCompleteE (this);
                if(builtEffect!=null) ObjectPoolManager.Spawn(builtEffect, thisT.position, thisT.rotation);
            }

            if(reverse){
                if(onSoldE!=null) onSoldE(this);

                if(occupiedPlatform!=null) occupiedPlatform.UnbuildTower(occupiedNode);
                ResourceManager.GainResource(GetValue());
                Dead();
            }
        }
Example #6
0
        IEnumerator Building(float duration, bool reverse = false)
        {       //reverse flag is set to true when selling (thus unbuilding) the tower
            construction = !reverse ? _Construction.Constructing : _Construction.Deconstructing;

            builtDuration = 0;
            buildDuration = duration;

            if (onConstructionStartE != null)
            {
                onConstructionStartE(this);
            }

            yield return(null);

            if (!reverse && playConstructAnimation != null)
            {
                playConstructAnimation();
            }
            else if (reverse && playDeconstructAnimation != null)
            {
                playDeconstructAnimation();
            }

            if (SpawnEffect)
            {
                SpawnEffect = ObjectPoolManager.Spawn(SpawnEffect, thisT.position, thisT.rotation);
                foreach (Renderer render in renderParent)
                {
                    render.enabled = false;
                }
            }
            while (true)
            {
                yield return(null);

                builtDuration += Time.deltaTime;
                if (builtDuration > buildDuration)
                {
                    break;
                }
            }
            if (SpawnEffect)
            {
                ObjectPoolManager.Unspawn(SpawnEffect);
                foreach (Renderer render in renderParent)
                {
                    render.enabled = true;
                }
            }
            construction = _Construction.None;

            if (!reverse && onConstructionCompleteE != null)
            {
                onConstructionCompleteE(this);
            }

            if (reverse)
            {
                if (onSoldE != null)
                {
                    onSoldE(this);
                }

                if (occupiedPlatform != null)
                {
                    occupiedPlatform.UnbuildTower(occupiedNode);
                }
                ResourceManager.GainResource(GetValue());
                Dead();
            }
        }
Example #7
0
        IEnumerator Building(float duration, bool reverse = false)
        {
            //reverse flag is set to true when selling (thus unbuilding) the tower
              bool possible = BuildManager.instance.UpdatePathMaps(this, reverse);
              if (!possible)
              {
            reverse = true;
              }

              construction = !reverse ? _Construction.Constructing : _Construction.Deconstructing;

              builtDuration = 0;
              buildDuration = duration;

              if (onConstructionStartE != null) onConstructionStartE(this);

              yield return null;
              if (!reverse && playConstructAnimation != null) playConstructAnimation();
              else if (reverse && playDeconstructAnimation != null) playConstructAnimation();

              while (true)
              {
            yield return null;
            builtDuration += Time.deltaTime;
            if (builtDuration > buildDuration) break;
              }

              construction = _Construction.None;

              if (!reverse && onConstructionCompleteE != null) onConstructionCompleteE(this);

              buildFinished();

              if (reverse)
              {

            if (onSoldE != null) onSoldE(this);

            if (possible)
              ResourceManager.GainResource(GetValue());

            // if tower is destructed, destroy drone
            if (drone != null) Destroy(drone);

            if (moveObjectHndl != null) StopCoroutine(moveObjectHndl);
            Dead();
              }
        }