chenxin
2020-12-01 e36f2a3ac098d6e89d3882f3354ec69c07e71e16
Assets/Scripts/TowerDefense/Agents/Agent.cs
@@ -1,15 +1,10 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using ActionGameFramework.Health;
using Core.Health;
using Core.Utilities;
using DG.Tweening;
using KTGMGemClient;
using TMPro.Examples;
using TowerDefense.Affectors;
using TowerDefense.Agents.Data;
using TowerDefense.Economy;
using TowerDefense.Level;
using TowerDefense.Nodes;
@@ -107,11 +102,6 @@
        public AgentSetData mAgentData;
        //public Textur
        /// <summary>
        /// The NavMeshAgent component attached to this
        /// 这个,Unity内比较核心的类
@@ -201,6 +191,126 @@
        /// </summary>
        /// <param name="can"></param>
        public bool CanMove { get; set; } = true;
        /// <summary>
        /// 分别对应三种不同的纹理.
        /// </summary>
        public Texture poisonTex;
        public Texture frozenTex;
        public Texture commonTex;
        /// <summary>
        /// 速度降低值.
        /// </summary>
        protected float speedSlowRate = 0.0f;
        // 中毒相关的数据
        protected int poisonTimes = 0;
        protected float poisonHurt = 0.0f;
        protected int poisonAttid = 0;
        protected float timeToPoisonHurt = 0.0f;
        /// <summary>
        /// 是否处于 中毒状态
        /// </summary>
        protected bool isPoison;
        /// <summary>
        /// 是否处于减速状态
        /// </summary>
        protected bool isSlowDown;
        /// <summary>
        /// 是否处于冰冻状态
        /// </summary>
        protected bool isFrost;
        /// <summary>
        /// 中毒粒子特效
        /// </summary>
        public ParticleSystem PoisonParticle;
        /// <summary>
        /// 中毒结束播放的粒子特效
        /// </summary>
        public ParticleSystem PoisonEndParticle;
        /// <summary>
        /// 减速粒子特效
        /// </summary>
        public ParticleSystem SlowDownParticle;
        /// <summary>
        /// 冰冻特效
        /// </summary>
        public ParticleSystem FrostParticle;
        /// <summary>
        /// 被火技能攻击特效
        /// </summary>
        public ParticleSystem FireSkillParticle;
        /// <summary>
        /// 降低移动速度.
        /// </summary>
        /// <param name="rate"></param>
        public void addSpeedSlowRate(float rate)
        {
            speedSlowRate += rate;
            if (speedSlowRate >= 0.5f)
                speedSlowRate = 0.5f;
        }
        /// <summary>
        /// 怪物中毒.
        /// </summary>
        /// <param name="damage"></param>
        public void poisonAgent(float damage, int attid)
        {
            if (this.poisonTimes >= 1) return;
            if (!isPoison)
            {
                isPoison = true;
                if (PoisonParticle != null)
                    PoisonParticle.Play();
            }
            this.poisonTimes++;
            this.poisonAttid = attid;
            this.poisonHurt = (float)Math.Floor(this.configuration.maxHealth / 20.0f);
            this.timeToPoisonHurt = 1.0f;
        }
        public bool bInPoison { get { return this.poisonHurt > 0; } }
        /// <summary>
        /// 处理中毒相关的数据
        /// </summary>
        /// <param name="time"></param>
        protected void updatePoison(float time)
        {
            this.timeToPoisonHurt -= time;
            if (this.timeToPoisonHurt <= 0)
            {
                Vector3 backPos = this.transform.position;
                this.TakeDamage(poisonHurt, this.transform.position, null, poisonAttid);
                if ((poisonHurt > 0) && (!opponentAgent))
                {
                    if (GameUI.instanceExists)
                        GameUI.instance.generateBloodText(backPos, poisonHurt, false, true);
                    else if (EndlessGameUI.instanceExists)
                        EndlessGameUI.instance.generateBloodText(backPos, poisonHurt, false, true);
                }
                if (poisonHurt > 0)
                    timeToPoisonHurt = 1.0f;
            }
        }
        /// <summary>
        /// Gets the attached nav mesh agent velocity
@@ -358,15 +468,11 @@
            mStartYVal = this.transform.position.y;
            mStartZVal = this.transform.position.z;
            // 确保设置成默认白色纹理:
            this.SetTargetableMatColor(Color.white, true);
            speedSlowRate = 0.0f;
            poisonHurt = 0;
            poisonAttid = 0;
            poisonTimes = 0;
            timeToPoisonHurt = 0;
            bShieldBreak = false;
            CanMove = true;
            /*// 如果对应的粒子不为空,则播放
@@ -562,7 +668,6 @@
            poisonTimes = 0;
            timeToPoisonHurt = 0;
            isFrost = false;
            bShieldBreak = false;
            bInDeathAct = false;
            ChangeState(AgentActionState.Move);
            configuration.ClearShieldWall();