chenxin
2020-11-16 181cd73136a98d45cf8751f8fee0bdb45a78db77
Assets/Scripts/TowerDefense/Towers/Tower.cs
@@ -27,6 +27,7 @@
        NULL,
        BULLET,   // 子弹塔
        ENERGY,   // 能量充能.
        FREEZE, // 水精灵充能
        END
    }
@@ -79,6 +80,8 @@
        public BulletUICtl bulletCtl = null;
        public EnergyUICtl energyCtl = null;
        public FreezeBreath FreezeBreathCtrl = null;
        /// <summary>
        /// The tower levels associated with this tower
        /// </summary>
@@ -126,6 +129,8 @@
        /// </summary>
        protected int progressOffset = 0;
        public int FreezeBreathProgressOffset { get; set; }
        public bool PlayWaveLineFlash { get; set; } = true;
        /// <summary>
@@ -138,10 +143,9 @@
        public int uiProOffset
        {
            get { return this.progressOffset; }
            set { this.progressOffset = value; }
            get { return progressOffset; }
            set { progressOffset = value; }
        }
        /// <summary>
        /// Gets whether the tower can level up anymore
@@ -157,30 +161,30 @@
            if (opponentSide)
            {
                if (attack && (this.curActionState != 2))
                if (attack && (curActionState != 2))
                {
                    currentTowerLevel.SetTowerMonsterMat(materialTowerAttackOppo, true);
                    this.curActionState = 2;
                    curActionState = 2;
                }
                if ((!attack) && (this.curActionState != 1))
                if ((!attack) && (curActionState != 1))
                {
                    currentTowerLevel.SetTowerMonsterMat(materialTowerWaitOppo, false);
                    this.curActionState = 1;
                    curActionState = 1;
                }
            }
            else
            {
                if (attack && (this.curActionState != 2))
                if (attack && (curActionState != 2))
                {
                    currentTowerLevel.SetTowerMonsterMat(materialTowerAttackSelf, true);
                    this.curActionState = 2;
                    curActionState = 2;
                }
                if ((!attack) && (this.curActionState != 1))
                if ((!attack) && (curActionState != 1))
                {
                    currentTowerLevel.SetTowerMonsterMat(materialTowerWaitSelf, false);
                    this.curActionState = 1;
                    curActionState = 1;
                }
            }
        }
@@ -196,7 +200,7 @@
        /// <param name="play"></param>
        public void PlayEnergyEffect(bool play, bool isClose = true)
        {
            if (this.energyCtl && isClose)
            if (energyCtl && isClose)
                energyCtl.gameObject.SetActive(!play);
            else if (!isClose)
            {
@@ -215,11 +219,28 @@
        }
        /// <summary>
        /// 播放水精灵充能满了特效
        /// </summary>
        /// <param name="play"></param>
        /// <param name="isClose"></param>
        public void PlayFreezeBreathEffect(bool play, bool isClose = true)
        {
            if (FreezeBreathCtrl && isClose)
                FreezeBreathCtrl.gameObject.SetActive(!play);
            if (!opponentSide)
            {
                if (EndlessGameUI.instanceExists)
                    ((TowerPlacementGridEndless)EndlessGameUI.instance.selfTowerPlaceArea).PlayFreezeBreathEffect(gridPosition.x, gridPosition.y, play);
            }
        }
        /// <summary>
        /// 当前是否处于攻击模式
        /// </summary>
        public bool bInAttackMode
        {
            get { return this.m_bInAttackMode; }
            get { return m_bInAttackMode; }
            // 设置是否处于攻击状态:
            set
@@ -232,18 +253,18 @@
                {
                    if (opponentSide)
                    {
                        OpponentMgr.instance.SetTowerAttID(gridPosition.x, attributeId, this.currentLevel);
                        OpponentMgr.instance.SetTowerAttID(gridPosition.x, attributeId, currentLevel);
                    }
                    else
                    {
                        if (LevelManager.instanceExists)
                        {
                            LevelManager.instance.SetTowerAttID(gridPosition.x, attributeId, this.currentLevel);
                            LevelManager.instance.SetTowerAttID(gridPosition.x, attributeId, currentLevel);
                            WaveLineSelMgr.instance.attackTowerFixed(gridPosition.x);
                        }
                        else if (EndlessLevelManager.instanceExists)
                        {
                            EndlessLevelManager.instance.SetTowerAttID(gridPosition.x, attributeId, this.currentLevel);
                            EndlessLevelManager.instance.SetTowerAttID(gridPosition.x, attributeId, currentLevel);
                            EndlessWaveLineManager.instance.AttackTowerFixed(gridPosition.x, PlayWaveLineFlash);
                        }
                    }
@@ -260,12 +281,12 @@
        public void DisableTowerUICtrl()
        {
            // 根据是否是子弹塔防来决定是否显示相应的界面
            BulletUICtl buc = this.placementArea.GetBulletUICtl(gridPosition.x, gridPosition.y);
            BulletUICtl buc = placementArea.GetBulletUICtl(gridPosition.x, gridPosition.y);
            if ((this.eTowerFuntion == ETowerFuntion.BULLET) && (buc != null))
            if ((eTowerFuntion == ETowerFuntion.BULLET) && (buc != null))
            {
                buc.gameObject.SetActive(false);
                this.bulletCtl = null;
                bulletCtl = null;
            }
            EnergyUICtl euc = placementArea.GetEnergyUICtl(gridPosition.x, gridPosition.y);
@@ -273,23 +294,33 @@
            {
                // 设置数据
                euc.gameObject.SetActive(false);
                this.energyCtl = null;
                energyCtl = null;
            }
            return;
            FreezeBreath ctrl = placementArea.GetFreezeBreath(gridPosition.x, gridPosition.y);
            if (eTowerFuntion == ETowerFuntion.FREEZE && ctrl != null)
            {
                ctrl.gameObject.SetActive(false);
                ctrl = null;
            }
        }
        public int GetTowerUICtrlProgress()
        {
            // 根据是否是子弹塔防来决定是否显示相应的界面
            BulletUICtl buc = this.placementArea.GetBulletUICtl(gridPosition.x, gridPosition.y);
            BulletUICtl buc = placementArea.GetBulletUICtl(gridPosition.x, gridPosition.y);
            if ((this.eTowerFuntion == ETowerFuntion.BULLET) && (buc != null))
            if ((eTowerFuntion == ETowerFuntion.BULLET) && (buc != null))
                return buc.GetCtlProgress();
            EnergyUICtl euc = placementArea.GetEnergyUICtl(gridPosition.x, gridPosition.y);
            if ((eTowerFuntion == ETowerFuntion.ENERGY) && (euc != null))
                return euc.GetCtlProgress();
            FreezeBreath ctrl = placementArea.GetFreezeBreath(gridPosition.x, gridPosition.y);
            if (eTowerFuntion == ETowerFuntion.FREEZE && ctrl != null)
                return ctrl.CurrentProgress;
            return 0;
        }
@@ -297,12 +328,13 @@
        public void SetTowerUICtlProcess(int pro)
        {
            // 根据是否是子弹塔防来决定是否显示相应的界面
            BulletUICtl buc = this.placementArea.GetBulletUICtl(gridPosition.x, gridPosition.y);
            BulletUICtl buc = placementArea.GetBulletUICtl(gridPosition.x, gridPosition.y);
            if ((this.eTowerFuntion == ETowerFuntion.BULLET) && (buc != null))
            if ((eTowerFuntion == ETowerFuntion.BULLET) && (buc != null))
            {
                buc.SetCtlProcess(pro);
                progressOffset = pro;
                return;
            }
            EnergyUICtl euc = placementArea.GetEnergyUICtl(gridPosition.x, gridPosition.y);
@@ -312,53 +344,85 @@
                progressOffset = pro;
                if (progressOffset == 10)
                    progressOffset = 0;
                return;
            }
            FreezeBreath ctrl = placementArea.GetFreezeBreath(gridPosition.x, gridPosition.y);
            return;
            if (eTowerFuntion == ETowerFuntion.FREEZE && ctrl != null)
            {
                ctrl.SetCtrlProgress(pro);
                FreezeBreathProgressOffset = pro;
                if (FreezeBreathProgressOffset == 10)
                    FreezeBreathProgressOffset = 0;
            }
        }
        /// <summary>
        /// 充能技能相关的代码开关。包括子弹充能和时间充能
        /// </summary>
        protected void OnTowerUICtrl()
        {
            HandleBulletUICtrl();
            HandleEnergyUICtrl();
            HandleFreezeBreathCtrl();
        }
        private void HandleBulletUICtrl()
        {
            // 根据是否是子弹塔防来决定是否显示相应的界面
            BulletUICtl buc = this.placementArea.GetBulletUICtl(gridPosition.x, gridPosition.y);
            BulletUICtl buc = placementArea.GetBulletUICtl(gridPosition.x, gridPosition.y);
            if (buc == null) return;
            if ((this.eTowerFuntion == ETowerFuntion.BULLET) && (buc != null))
            if ((eTowerFuntion == ETowerFuntion.BULLET) && (buc != null))
            {
                // 设置数据
                buc.gameObject.SetActive(true);
                this.bulletCtl = buc;
                bulletCtl = buc;
                buc.resetToMaxBullet();
            }
            else
            {
                // 清空数据
                buc.gameObject.SetActive(false);
                this.bulletCtl = null;
                bulletCtl = null;
            }
        }
        private void HandleEnergyUICtrl()
        {
            // 根据是否是能量充能来决定是否显示相应的界面.
            EnergyUICtl euc = placementArea.GetEnergyUICtl(gridPosition.x, gridPosition.y);
            if ((eTowerFuntion == ETowerFuntion.ENERGY) && (euc != null))
            {
                // 设置数据
                euc.gameObject.SetActive(true);
                this.energyCtl = euc;
                energyCtl = euc;
                euc.SetEnergyProgress(0);
            }
            else
            {
                // 清空数据
                euc.gameObject.SetActive(false);
                this.energyCtl = null;
                energyCtl = null;
            }
        }
        private void HandleFreezeBreathCtrl()
        {
            FreezeBreath ctrl = placementArea.GetFreezeBreath(gridPosition.x, gridPosition.y);
            if (eTowerFuntion == ETowerFuntion.FREEZE && ctrl != null)
            {
                ctrl.gameObject.SetActive(true);
                FreezeBreathCtrl = ctrl;
                ctrl.SetProgress(0);
            }
            else
            {
                ctrl.gameObject.SetActive(false);
                FreezeBreathCtrl = null;
            }
        }
@@ -396,6 +460,9 @@
            {
                energyCtl.gameObject.SetActive(false);
            }
            if (FreezeBreathCtrl != null)
                FreezeBreathCtrl.gameObject.SetActive(false);
        }
        /// <summary>
@@ -412,8 +479,8 @@
            }
            // 设置攻击数据的加强,暂时是测试数据,后面需要读取表格数据处理:
            float damageAdd = 0;
            // float damageAdd = (inSceneTowerLevel - 1) * this.INSCENE_TU_DAMAGE;
            for (int ti = 0; ti < this.levels.Length; ti++)
            // float damageAdd = (inSceneTowerLevel - 1) * INSCENE_TU_DAMAGE;
            for (int ti = 0; ti < levels.Length; ti++)
            {
                if (levels[ti].levelDamager)
                {
@@ -425,7 +492,7 @@
        protected void ResetInSceneTowerLevel()
        {
            for (int ti = 0; ti < this.levels.Length; ti++)
            for (int ti = 0; ti < levels.Length; ti++)
            {
                if (levels[ti].levelDamager)
                {
@@ -444,9 +511,9 @@
            inSceneTowerLevel++;
            // 设置攻击数据的加强,暂时是测试数据,后面需要读取表格数据处理:
            float damageAdd = inSceneTowerLevel * this.INSCENE_TU_DAMAGE;
            float damageAdd = inSceneTowerLevel * INSCENE_TU_DAMAGE;
            for (int ti = 0; ti < this.levels.Length; ti++)
            for (int ti = 0; ti < levels.Length; ti++)
            {
                if (levels[ti].levelDamager)
                {
@@ -534,17 +601,17 @@
                EndlessLevelManager.instance.LevelStateChanged += OnLevelStateChanged;
            // 查找Targetter:
            Targetter target = this.GetComponentInChildren<Targetter>();
            Targetter target = GetComponentInChildren<Targetter>();
            if (target)
            {
                target.bOpponent = this.opponentSide;
                target.bOpponent = opponentSide;
            }
            else
                Debug.Log("在当前的Tower中找不到Targetter.");
            // 
            // 初始化当前的局内Tower等级数据
            this.initInSceneTowerLevel(SceneTowerLvl.getInSceneTowerLvl(this.towerName));
            initInSceneTowerLevel(SceneTowerLvl.getInSceneTowerLvl(towerName));
            StartCoroutine(ResetScale());
        }
@@ -583,11 +650,11 @@
        {
            if (vis)
            {
                this.gameObject.SetActive(true);
                gameObject.SetActive(true);
            }
            else
            {
                this.gameObject.SetActive(false);
                gameObject.SetActive(false);
            }
        }