chenxin
2020-11-11 f2f4e1e45981bb294a5221ade7b4646cc3e29d35
Assets/Scripts/TowerDefense/Agents/Agent.cs
@@ -193,6 +193,12 @@
        protected bool bInDeathAct = false;
        /// <summary>
        /// 原地罚站
        /// </summary>
        /// <param name="can"></param>
        public bool CanMove { get; set; } = true;
        /// <summary>
        /// Gets the attached nav mesh agent velocity
        /// </summary>
        public override Vector3 velocity
@@ -203,6 +209,7 @@
        public bool bInDeathState
        {
            get { return this.bInDeathAct; }
            set { bInDeathAct = value; }
        }
        /// <summary>
@@ -237,8 +244,15 @@
        /// </summary>
        protected bool nodeMoveUpdate = false;
        /// <summary>
        /// 代理的类型
        /// </summary>
        public SpawnAgentType AgentType { get; set; } = SpawnAgentType.Normal;
        /// <summary>
        /// 无尽模式小怪对应 endless_enemy表中数据
        /// </summary>
        public endless_enemy EnemyData { get; set; }
        /// <summary>
        /// Accessor to <see cref="m_NavMeshAgent"/>
@@ -287,6 +301,7 @@
        {
            this.configuration.maxHealth = health;
            this.configuration.startingHealth = health;
            this.configuration.SetMaxHealth(health);
            this.configuration.Init();
            this.configuration.SetHealth(health);
@@ -314,6 +329,7 @@
            poisonTimes = 0;
            timeToPoisonHurt = 0;
            bShieldBreak = false;
            CanMove = true;
            /*// 如果对应的粒子不为空,则播放
         if( spawnParticle)
@@ -391,35 +407,16 @@
        /// 处理Agent的锁定Buf,播放特效,设置速度为零,并时间到达后重设数据。
        /// </summary>
        /// <param name="binfo"></param>
        protected void SetAgentStopBuff(buffinfo binfo)
        protected virtual void SetAgentStopBuff(buffinfo binfo)
        {
            MoveStopTime = binfo.last / 1000;
            if (WaveLineSelMgr.instanceExists)
            if (!isFrost)
            {
                // 播放特效:
                if (WaveLineSelMgr.instance.bufStopMovePrefab == null) return;
                isFrost = true;
                // 正在播放的话,直接返回.
                if (MoveStopEffect)
                    return;
                MoveStopEffect = Instantiate(WaveLineSelMgr.instance.bufStopMovePrefab);
                MoveStopEffect.transform.position = this.position;
                MoveStopEffect.Play();
            }
            else if (EndlessWaveLineManager.instanceExists)
            {
                // 播放特效:
                if (EndlessWaveLineManager.instance.bufStopMovePrefab == null) return;
                // 正在播放的话,直接返回.
                if (MoveStopEffect)
                    return;
                MoveStopEffect = Instantiate(EndlessWaveLineManager.instance.bufStopMovePrefab);
                MoveStopEffect.transform.position = this.position;
                MoveStopEffect.Play();
                if (FrostParticle != null)
                    FrostParticle.Play();
            }
        }
@@ -453,7 +450,7 @@
        {
            // 统一管理器内删除当前的Agent:
            AgentInsManager.instance.removeAgent(this);
            EventCenter.Ins.BroadCast((int)KTGMGemClient.EventType.EndlessAgentDead, this);
            base.Remove();
            if (m_LevelManager) m_LevelManager.DecrementNumberOfEnemies();
@@ -477,26 +474,32 @@
            timeToPoisonHurt = 0;
            bShieldBreak = false;
            bInDeathAct = false;
            configuration.ClearShieldWall();
            StopFrostParticle();
            //this.SetTargetableMatColor(Color.white);
            // 删除当前停止特效和状态.
            if (MoveStopTime > 0)
            {
                if (MoveStopEffect)
                {
                    MoveStopEffect.Stop();
                    Destroy(MoveStopEffect);
                    MoveStopEffect = null;
                }
                MoveStopTime = 0.0f;
            }
            // 停止DoTween动画.
            this.transform.DOKill();
            Poolable.TryPool(gameObject);
        }
        private void StopFrostParticle()
        {
            if (isFrost)
            {
                isFrost = false;
                if (FrostParticle != null)
                    FrostParticle.Stop();
            }
        }
        /// <summary>   
@@ -697,6 +700,7 @@
        /// </summary>
        protected override void Awake()
        {
            //Debug.Log("哪里生成的?");
            base.Awake();
            LazyLoad();
            m_NavMeshAgent.enabled = false;
@@ -719,12 +723,7 @@
                MoveStopTime -= Time.deltaTime;
                if (MoveStopTime <= 0)
                {
                    if (MoveStopEffect)
                    {
                        MoveStopEffect.Stop();
                        Destroy(MoveStopEffect);
                        MoveStopEffect = null;
                    }
                    StopFrostParticle();
                    MoveStopTime = 0;
                }
                else
@@ -738,6 +737,24 @@
            }
            float finalSpeed = fMoveSpeed * (1 - speedSlowRate);
            if (speedSlowRate > 0 && !isSlowDown)
            {
                isSlowDown = true;
                if (SlowDownParticle != null)
                    SlowDownParticle.Play();
            }
            else if (speedSlowRate == 0 && isSlowDown)
            {
                isSlowDown = false;
                if (SlowDownParticle != null)
                {
                    SlowDownParticle.Stop();
                    SlowDownParticle.Clear();
                }
            }
            Vector3 curPos = m_NavMeshAgent.transform.position;
            bool swithNode = false;
@@ -810,32 +827,52 @@
        /// <returns></returns>
        protected void UpdateAction()
        {
            if (!mAnim) return;
            if (mAnim)
            {
                AnimatorStateInfo stateinfo = mAnim.GetCurrentAnimatorStateInfo(0);
            AnimatorStateInfo stateinfo = mAnim.GetCurrentAnimatorStateInfo(0);
            if (stateinfo.IsName("Die") && (stateinfo.normalizedTime >= 0.7f))
            {
                this.Remove();
                return;
            }
            else if (stateinfo.IsName("GetHit") && (stateinfo.normalizedTime >= 0.7f))
            {
                mAnim.SetBool("GetHit", false);
            }
            else if (stateinfo.IsName("Attack") && (stateinfo.normalizedTime >= 0.9f))
            {
                if (this.healthVal <= 0.1)
                if (stateinfo.IsName("Die") && (stateinfo.normalizedTime >= 0.7f))
                {
                    // 统一管理器内删除当前的Agent:
                    AgentInsManager.instance.removeAgent(this);
                    this.Remove();
                    Debug.Log("删除多余的攻击Agent.");
                    return;
                }
                else if (stateinfo.IsName("GetHit") && (stateinfo.normalizedTime >= 0.7f))
                {
                    mAnim.SetBool("GetHit", false);
                }
                else if (stateinfo.IsName("Attack") && (stateinfo.normalizedTime >= 0.9f))
                {
                    if (this.healthVal <= 0.1)
                    {
                        // 统一管理器内删除当前的Agent:
                        AgentInsManager.instance.removeAgent(this);
                        this.Remove();
                    }
                }
            }
            else if (changeMat)
            {
            return;
            }
        }
        /// <summary>
        /// 检查自身血量
        /// </summary>
        private void CheckHealth()
        {
            if (this.healthVal <= 0.1)
            {
                Die();
                //Debug.Log("删除多余的攻击Agent.");
            }
        }
        private void Die()
        {
            // 统一管理器内删除当前的Agent:
            AgentInsManager.instance.removeAgent(this);
            this.Remove();
        }
        /// <summary>
@@ -846,9 +883,10 @@
        protected virtual void Update()
        {
            this.UpdateAction();
            HandleShieldWall();
            // 处理死亡状态了,不必再移动:
            if (bInDeathAct) return;
            if (bInDeathAct || !CanMove) return;
            m_Destination = initNode.GetNextNode();
            updateAgentPos(Time.deltaTime);
@@ -859,6 +897,25 @@
            // 计算中毒相关.
            if ((poisonTimes > 0) && (poisonHurt > 0))
                updatePoison(Time.deltaTime);
        }
        /// <summary>
        /// 处理魔法护盾血量值
        /// </summary>
        protected void HandleShieldWall()
        {
            if (configuration.IsExistShieldWall)
            {
                if (configuration.ShieldWallCurrentHealth <= 0.00001f)
                    configuration.IsExistShieldWall = false;
                else if (configuration.ShieldWallEffectiveTime > 0.00001f)
                {
                    if (configuration.ShieldWallRemainTime <= 0.00001f)
                        configuration.IsExistShieldWall = false;
                    else
                        configuration.ShieldWallRemainTime -= Time.deltaTime;
                }
            }
        }
        /// <summary>
@@ -944,6 +1001,7 @@
            return tmpDis;
        }
        protected ChangeMat changeMat;
        /// <summary>
        /// This is a lazy way of caching several components utilised by the Agent
        /// </summary>
@@ -970,6 +1028,13 @@
                        mAnim = t.GetComponent<Animator>();
                }
            }
            //使用三渲二的方式
            if (mAnim == null)
            {
                changeMat = GetComponent<ChangeMat>();
                changeMat?.SetSelf(this.opponentAgent, CheckHealth, Die);
            }
        }
        /// <summary>
@@ -979,12 +1044,21 @@
        {
            if (mAnim)
                mAnim.SetBool("GetHit", true);
            else if (changeMat)
            {
                changeMat.SetGetHit();
            }
        }
        public void PlayAttack()
        {
            AudioSourceManager.Ins.Play(AudioEnum.AttackTower);
            if (mAnim)
                mAnim.SetBool("Attack", true);
            else if (changeMat)
            {
                changeMat.SetAttack();
            }
        }
        public override void PlayDeath()
@@ -998,16 +1072,58 @@
                    if (PoisonParticle != null)
                    {
                        PoisonParticle.Stop();
                        PoisonParticle.Clear();
                        if (PoisonEndParticle != null)
                            PoisonEndParticle.Play();
                    }
                }
                if (isSlowDown)
                {
                    isSlowDown = false;
                    if (SlowDownParticle != null)
                    {
                        SlowDownParticle.Stop();
                        SlowDownParticle.Clear();
                    }
                }
                mAnim.SetBool("Die", true);
                // 统一管理器内删除当前的Agent:
                AgentInsManager.instance.removeAgent(this);
                bInDeathAct = true;
            }
            else if (changeMat)
            {
                if (isPoison)
                {
                    isPoison = false;
                    // 移除Agent身上的中毒特效,并播放一个中毒效果消失的特效
                    if (PoisonParticle != null)
                    {
                        PoisonParticle.Stop();
                        PoisonParticle.Clear();
                        if (PoisonEndParticle != null)
                            PoisonEndParticle.Play();
                    }
                }
                if (isSlowDown)
                {
                    isSlowDown = false;
                    if (SlowDownParticle != null)
                    {
                        SlowDownParticle.Stop();
                        SlowDownParticle.Clear();
                    }
                }
                changeMat.SetDie();
                // 统一管理器内删除当前的Agent:
                AgentInsManager.instance.removeAgent(this);
                bInDeathAct = true;
            }
            else
            {
                this.Remove();