chenxin
2020-11-04 80b4237334a773b29bf69f38532a90ca659b3bfe
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,10 @@
        /// </summary>
        protected bool nodeMoveUpdate = false;
        /// <summary>
        /// 代理的类型
        /// </summary>
        public SpawnAgentType AgentType { get; set; } = SpawnAgentType.Normal;
        /// <summary>
        /// Accessor to <see cref="m_NavMeshAgent"/>
@@ -314,6 +323,7 @@
            poisonTimes = 0;
            timeToPoisonHurt = 0;
            bShieldBreak = false;
            CanMove = true;
            /*// 如果对应的粒子不为空,则播放
         if( spawnParticle)
@@ -395,31 +405,12 @@
        {
            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();
            }
        }
@@ -477,26 +468,30 @@
            timeToPoisonHurt = 0;
            bShieldBreak = false;
            bInDeathAct = false;
            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 +692,7 @@
        /// </summary>
        protected override void Awake()
        {
            //Debug.Log("哪里生成的?");
            base.Awake();
            LazyLoad();
            m_NavMeshAgent.enabled = false;
@@ -719,12 +715,7 @@
                MoveStopTime -= Time.deltaTime;
                if (MoveStopTime <= 0)
                {
                    if (MoveStopEffect)
                    {
                        MoveStopEffect.Stop();
                        Destroy(MoveStopEffect);
                        MoveStopEffect = null;
                    }
                    StopFrostParticle();
                    MoveStopTime = 0;
                }
                else
@@ -738,6 +729,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 +819,53 @@
        /// <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();
                        Debug.Log("删除多余的攻击Agent.");
                    }
                }
            }
            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>
@@ -848,7 +878,7 @@
            this.UpdateAction();
            // 处理死亡状态了,不必再移动:
            if (bInDeathAct) return;
            if (bInDeathAct || !CanMove) return;
            m_Destination = initNode.GetNextNode();
            updateAgentPos(Time.deltaTime);
@@ -944,6 +974,7 @@
            return tmpDis;
        }
        protected ChangeMat changeMat;
        /// <summary>
        /// This is a lazy way of caching several components utilised by the Agent
        /// </summary>
@@ -970,6 +1001,13 @@
                        mAnim = t.GetComponent<Animator>();
                }
            }
            //使用三渲二的方式
            if (mAnim == null)
            {
                changeMat = GetComponent<ChangeMat>();
                changeMat?.SetSelf(this.opponentAgent, CheckHealth,Die);
            }
        }
        /// <summary>
@@ -979,12 +1017,20 @@
        {
            if (mAnim)
                mAnim.SetBool("GetHit", true);
            else if (changeMat)
            {
                changeMat.SetGetHit();
            }
        }
        public void PlayAttack()
        {
            if (mAnim)
                mAnim.SetBool("Attack", true);
            else if (changeMat)
            {
                changeMat.SetAttack();
            }
        }
        public override void PlayDeath()
@@ -998,16 +1044,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();