chenxin
2020-11-14 4a083f2f3d8baf1c2630b3717d62904edcc8e24a
Assets/Scripts/TowerDefense/Agents/Agent.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using ActionGameFramework.Health;
using Core.Health;
@@ -188,7 +189,9 @@
        /// <summary>
        /// 动画器.
        /// </summary>
        protected Animator mAnim;
        public Animator ActionAnimator;
        protected AnimationClip[] clips;
        protected bool bInDeathAct = false;
@@ -232,12 +235,10 @@
            get { return this.m_NavMeshAgent; }
        }
        /// <summary>
        /// 是否显示目标位置信息
        /// </summary>
        public bool bShowDebugNode = false;
        /// <summary>
        /// 持续寻路,起到寻路成功
@@ -248,6 +249,11 @@
        /// 代理的类型
        /// </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"/>
@@ -276,6 +282,12 @@
        /// </summary>
        public float originalMovementSpeed { get; protected set; }
        /// <summary>
        /// 小怪的动作状态
        /// </summary>
        public AgentActionState ActionState { get; protected set; }
        private string paramName = "AgentActionState";
        /// <summary>
        /// 更新怪物的移动速度。
@@ -296,6 +308,7 @@
        {
            this.configuration.maxHealth = health;
            this.configuration.startingHealth = health;
            this.configuration.SetMaxHealth(health);
            this.configuration.Init();
            this.configuration.SetHealth(health);
@@ -401,7 +414,7 @@
        /// 处理Agent的锁定Buf,播放特效,设置速度为零,并时间到达后重设数据。
        /// </summary>
        /// <param name="binfo"></param>
        protected void SetAgentStopBuff(buffinfo binfo)
        protected virtual void SetAgentStopBuff(buffinfo binfo)
        {
            MoveStopTime = binfo.last / 1000;
@@ -444,7 +457,7 @@
        {
            // 统一管理器内删除当前的Agent:
            AgentInsManager.instance.removeAgent(this);
            EventCenter.Ins.BroadCast((int)KTGMGemClient.EventType.EndlessAgentDead, this);
            base.Remove();
            if (m_LevelManager) m_LevelManager.DecrementNumberOfEnemies();
@@ -468,6 +481,8 @@
            timeToPoisonHurt = 0;
            bShieldBreak = false;
            bInDeathAct = false;
            ChangeState(AgentActionState.Move);
            configuration.ClearShieldWall();
            StopFrostParticle();
            //this.SetTargetableMatColor(Color.white);
@@ -813,39 +828,47 @@
            return;
        }
        float atime = 0;
        /// <summary>
        /// 更新动作信息.
        /// </summary>
        /// <returns></returns>
        protected void UpdateAction()
        {
            if (mAnim)
            {
                AnimatorStateInfo stateinfo = mAnim.GetCurrentAnimatorStateInfo(0);
            AnimatorStateInfo stateInfo = ActionAnimator.GetCurrentAnimatorStateInfo(0);
                if (stateinfo.IsName("Die") && (stateinfo.normalizedTime >= 0.7f))
                {
                    this.Remove();
                }
                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)
            switch (ActionState)
            {
                case AgentActionState.Move:
                    break;
                case AgentActionState.GetHit:
                    if (stateInfo.normalizedTime >= 1f)
                        ChangeState(AgentActionState.Move);
                    break;
                case AgentActionState.Attack:
                    if (stateInfo.normalizedTime >= 1f)
                    {
                        // 统一管理器内删除当前的Agent:
                        AgentInsManager.instance.removeAgent(this);
                        this.Remove();
                        Debug.Log("删除多余的攻击Agent.");
                        if (isDead)
                        {
                            AgentInsManager.instance.removeAgent(this);
                            Remove();
                        }
                    }
                }
                    break;
                case AgentActionState.Death:
                    if (stateInfo.normalizedTime >= 1f)
                        Remove();
                    break;
            }
            else if (changeMat)
            {
        }
            }
        private void ChangeState(AgentActionState state)
        {
            if (state == ActionState) return;
            ActionState = state;
            ActionAnimator.SetInteger(paramName, (int)state);
        }
        /// <summary>
@@ -873,9 +896,10 @@
        /// Reset destination when path is stale
        /// River: 更新的时候,加入离最终目标的距离数据.
        /// </summary>
        protected virtual void Update()
        protected virtual void LateUpdate()
        {
            this.UpdateAction();
            HandleShieldWall();
            // 处理死亡状态了,不必再移动:
            if (bInDeathAct || !CanMove) return;
@@ -889,6 +913,30 @@
            // 计算中毒相关.
            if ((poisonTimes > 0) && (poisonHurt > 0))
                updatePoison(Time.deltaTime);
        }
        protected virtual void Update()
        {
        }
        /// <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>
@@ -992,22 +1040,6 @@
            }
            if (!endlessLevelManager)
                endlessLevelManager = EndlessLevelManager.instance;
            if (mAnim == null)
            {
                foreach (Transform t in transform.GetComponentsInChildren<Transform>())
                {
                    if (t.name == "Model")
                        mAnim = t.GetComponent<Animator>();
                }
            }
            //使用三渲二的方式
            if (mAnim == null)
            {
                changeMat = GetComponent<ChangeMat>();
                changeMat?.SetSelf(this.opponentAgent, CheckHealth, Die);
            }
        }
        /// <summary>
@@ -1015,104 +1047,45 @@
        /// </summary>
        public void PlayOnHit()
        {
            if (mAnim)
                mAnim.SetBool("GetHit", true);
            else if (changeMat)
            {
                changeMat.SetGetHit();
            }
            ChangeState(AgentActionState.GetHit);
        }
        public void PlayAttack()
        {
            AudioSourceManager.Ins.Play(AudioEnum.AttackTower);
            if (mAnim)
                mAnim.SetBool("Attack", true);
            else if (changeMat)
            {
                changeMat.SetAttack();
            }
            ChangeState(AgentActionState.Attack);
        }
        public override void PlayDeath()
        {
            if (mAnim)
            if (isPoison)
            {
                if (isPoison)
                isPoison = false;
                // 移除Agent身上的中毒特效,并播放一个中毒效果消失的特效
                if (PoisonParticle != null)
                {
                    isPoison = false;
                    // 移除Agent身上的中毒特效,并播放一个中毒效果消失的特效
                    if (PoisonParticle != null)
                    {
                        PoisonParticle.Stop();
                        PoisonParticle.Clear();
                        if (PoisonEndParticle != null)
                            PoisonEndParticle.Play();
                    }
                    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 (isSlowDown)
            {
                if (isPoison)
                isSlowDown = false;
                if (SlowDownParticle != null)
                {
                    isPoison = false;
                    // 移除Agent身上的中毒特效,并播放一个中毒效果消失的特效
                    if (PoisonParticle != null)
                    {
                        PoisonParticle.Stop();
                        PoisonParticle.Clear();
                        if (PoisonEndParticle != null)
                            PoisonEndParticle.Play();
                    }
                    SlowDownParticle.Stop();
                    SlowDownParticle.Clear();
                }
                if (isSlowDown)
                {
                    isSlowDown = false;
                    if (SlowDownParticle != null)
                    {
                        SlowDownParticle.Stop();
                        SlowDownParticle.Clear();
                    }
                }
                changeMat.SetDie();
                // 统一管理器内删除当前的Agent:
                AgentInsManager.instance.removeAgent(this);
                bInDeathAct = true;
            }
            else
            {
                this.Remove();
            }
        }
        IEnumerator WaitDeathStop()
        {
            yield return null;
            AnimatorStateInfo stateinfo = mAnim.GetCurrentAnimatorStateInfo(0);
            if (stateinfo.IsName("Die") && (stateinfo.normalizedTime >= 1.0f))
            {
                Debug.Log("死亡动画播放完成,开始处理.");
                this.Remove();
            }
            ChangeState(AgentActionState.Death);
            // 统一管理器内删除当前的Agent:
            AgentInsManager.instance.removeAgent(this);
            bInDeathAct = true;
        }
        /// <summary>