From e36f2a3ac098d6e89d3882f3354ec69c07e71e16 Mon Sep 17 00:00:00 2001 From: chenxin <chenxin6991@163.com> Date: Tue, 01 Dec 2020 15:55:40 +0800 Subject: [PATCH] 代码结构修改 --- Assets/Scripts/TowerDefense/Towers/Tower.cs | 5 Assets/Scripts/TowerDefense/Agents/Agent.cs | 135 +++++++++++++++- Assets/Prefabs/Enemies/Wood.prefab | 0 Assets/Prefabs/Enemies/Wood.prefab.meta | 0 Assets/Prefabs/Enemies/Water.prefab | 0 Assets/Prefabs/Enemies/Fire.prefab.meta | 0 Assets/Scripts/ActionGameFramework/Health/Targetable.cs | 179 ---------------------- Assets/Scripts/TowerDefense/UI/HUD/GameUI.cs | 4 Assets/Scripts/TowerDefense/Level/AgentInsManager.cs | 42 +---- Assets/Prefabs/Enemies/Water.prefab.meta | 0 Assets/Scripts/TowerDefense/Towers/Projectiles/HitscanAttack.cs | 81 --------- Assets/Prefabs/Enemies/Fire.prefab | 0 Assets/Scripts/TowerDefense/Towers/Projectiles/BallisticAttack.cs | 6 13 files changed, 137 insertions(+), 315 deletions(-) diff --git a/Assets/Prefabs/Enemies/fire 2.prefab b/Assets/Prefabs/Enemies/Fire.prefab similarity index 100% rename from Assets/Prefabs/Enemies/fire 2.prefab rename to Assets/Prefabs/Enemies/Fire.prefab diff --git a/Assets/Prefabs/Enemies/fire 2.prefab.meta b/Assets/Prefabs/Enemies/Fire.prefab.meta similarity index 100% rename from Assets/Prefabs/Enemies/fire 2.prefab.meta rename to Assets/Prefabs/Enemies/Fire.prefab.meta diff --git a/Assets/Prefabs/Enemies/water 1.prefab b/Assets/Prefabs/Enemies/Water.prefab similarity index 100% rename from Assets/Prefabs/Enemies/water 1.prefab rename to Assets/Prefabs/Enemies/Water.prefab diff --git a/Assets/Prefabs/Enemies/water 1.prefab.meta b/Assets/Prefabs/Enemies/Water.prefab.meta similarity index 100% rename from Assets/Prefabs/Enemies/water 1.prefab.meta rename to Assets/Prefabs/Enemies/Water.prefab.meta diff --git a/Assets/Prefabs/Enemies/wood 2.prefab b/Assets/Prefabs/Enemies/Wood.prefab similarity index 100% rename from Assets/Prefabs/Enemies/wood 2.prefab rename to Assets/Prefabs/Enemies/Wood.prefab diff --git a/Assets/Prefabs/Enemies/wood 2.prefab.meta b/Assets/Prefabs/Enemies/Wood.prefab.meta similarity index 100% rename from Assets/Prefabs/Enemies/wood 2.prefab.meta rename to Assets/Prefabs/Enemies/Wood.prefab.meta diff --git a/Assets/Scripts/ActionGameFramework/Health/Targetable.cs b/Assets/Scripts/ActionGameFramework/Health/Targetable.cs index 1b3292d..40c196f 100644 --- a/Assets/Scripts/ActionGameFramework/Health/Targetable.cs +++ b/Assets/Scripts/ActionGameFramework/Health/Targetable.cs @@ -1,7 +1,4 @@ using Core.Health; -using System; -using System.Dynamic; -using TowerDefense.UI.HUD; using UnityEngine; namespace ActionGameFramework.Health @@ -17,85 +14,9 @@ public Transform targetTransform; /// <summary> - /// 是否精英怪 - /// </summary> - public bool bElit = false; - - /// <summary> - /// 是否Boss怪. - /// </summary> - public bool bBoss = false; - - /// <summary> - /// 分别对应三种不同的纹理. - /// </summary> - public Texture poisonTex; - public Texture frozenTex; - public Texture commonTex; - - /// <summary> /// The position of the object /// </summary> protected Vector3 m_CurrentPosition, m_PreviousPosition; - - - /// <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; - - protected Color mMatColor; - - /// <summary> - /// 是否处于破甲状态. - /// </summary> - public bool bShieldBreak { get; set; } /// <summary> /// The velocity of the rigidbody @@ -117,104 +38,6 @@ return targetTransform == null ? transform : targetTransform; } } - - /// <summary> - /// 设置当前目标的颜色数据 - /// </summary> - /// <param name="color"></param> - public void SetTargetableMatColor(Color color, bool force = false) - { - - if (!force) - { - if (color == mMatColor) return; - // 无敌状态,只接受白色原贴图: - if (this.configuration.bInvincible && (color != Color.white)) return; - } - - foreach (Transform t in transform.GetComponentsInChildren<Transform>()) - { - if (t.name == "Cube") - { - Material tMat = t.GetComponent<MeshRenderer>().material; - if ((color == Color.green) && (poisonTex != null)) - { - tMat.mainTexture = poisonTex; - } - if ((color == Color.blue) && (frozenTex != null)) - { - tMat.mainTexture = frozenTex; - } - if ((color == Color.white) && (commonTex != null)) - { - tMat.mainTexture = commonTex; - } - mMatColor = color; - } - - } - } - - - /// <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, false, true); - else if (EndlessGameUI.instanceExists) - EndlessGameUI.instance.generateBloodText(backPos, poisonHurt, false, false, true); - } - - if (poisonHurt > 0) - timeToPoisonHurt = 1.0f; - } - } - /// <summary> /// Returns our targetable's transform position @@ -244,8 +67,6 @@ { base.Awake(); ResetPositionData(); - bShieldBreak = false; - mMatColor = Color.white; } /// <summary> diff --git a/Assets/Scripts/TowerDefense/Agents/Agent.cs b/Assets/Scripts/TowerDefense/Agents/Agent.cs index 1eb7229..3dc7f94 100644 --- a/Assets/Scripts/TowerDefense/Agents/Agent.cs +++ b/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(); diff --git a/Assets/Scripts/TowerDefense/Level/AgentInsManager.cs b/Assets/Scripts/TowerDefense/Level/AgentInsManager.cs index 221492e..f452a8f 100644 --- a/Assets/Scripts/TowerDefense/Level/AgentInsManager.cs +++ b/Assets/Scripts/TowerDefense/Level/AgentInsManager.cs @@ -579,27 +579,6 @@ return; } - - - protected void releaseAllCenterAgent() - { - int cnt = this.agentInsList.Count; - for (int ti = cnt - 1; ti >= 0; ti--) - { - if (agentInsList[ti].bBoss) - continue; - agentInsList[ti].Remove(); - } - - cnt = this.oppoAgentInsList.Count; - for (int ti = cnt - 1; ti >= 0; ti--) - { - if (oppoAgentInsList[ti].bBoss) - continue; - oppoAgentInsList[ti].Remove(); - } - } - /// <summary> /// 获取WaveManager相关的中心点 /// </summary> @@ -609,7 +588,6 @@ Vector3 cpos = Vector3.zero; return cpos; } - protected void updateOpponentAgent() { @@ -739,9 +717,9 @@ if (!eag.opponentAgent) { if (GameUI.instanceExists) - GameUI.instance.generateBloodText(fpos, damage, false, false); + GameUI.instance.generateBloodText(fpos, damage); else if (EndlessGameUI.instanceExists) - EndlessGameUI.instance.generateBloodText(fpos, damage, false, false); + EndlessGameUI.instance.generateBloodText(fpos, damage); } if (!isDeath && eag.isDead) @@ -810,9 +788,9 @@ if (!eag.opponentAgent) { if (GameUI.instanceExists) - GameUI.instance.generateBloodText(fpos, damage, false, false); + GameUI.instance.generateBloodText(fpos, damage); else if (EndlessGameUI.instanceExists) - EndlessGameUI.instance.generateBloodText(fpos, damage, false, false); + EndlessGameUI.instance.generateBloodText(fpos, damage); } eag.PlayFireSkillHit(); @@ -890,9 +868,9 @@ if (!eag.opponentAgent) { if (GameUI.instanceExists) - GameUI.instance.generateBloodText(fpos, damage, false, false); + GameUI.instance.generateBloodText(fpos, damage); else if (EndlessGameUI.instanceExists) - EndlessGameUI.instance.generateBloodText(fpos, damage, false, false); + EndlessGameUI.instance.generateBloodText(fpos, damage); } eag.PlayFireSkillHit(); @@ -998,9 +976,9 @@ if (!eag.opponentAgent) { if (GameUI.instanceExists) - GameUI.instance.generateBloodText(fpos, damage, false, false); + GameUI.instance.generateBloodText(fpos, damage); else if (EndlessGameUI.instanceExists) - EndlessGameUI.instance.generateBloodText(fpos, damage, false, false); + EndlessGameUI.instance.generateBloodText(fpos, damage); } if (eag.isDead) ++deathCount; @@ -1073,9 +1051,9 @@ if ((ag.liveID == tid) && (!ag.opponentAgent)) { if (GameUI.instanceExists) - GameUI.instance.generateBloodText(ag.position, chainAttackHurt, false, false); + GameUI.instance.generateBloodText(ag.position, chainAttackHurt); else if (EndlessGameUI.instanceExists) - EndlessGameUI.instance.generateBloodText(ag.position, chainAttackHurt, false, false); + EndlessGameUI.instance.generateBloodText(ag.position, chainAttackHurt); } } listBlood.Clear(); diff --git a/Assets/Scripts/TowerDefense/Towers/Projectiles/BallisticAttack.cs b/Assets/Scripts/TowerDefense/Towers/Projectiles/BallisticAttack.cs index eee91c9..f017a43 100644 --- a/Assets/Scripts/TowerDefense/Towers/Projectiles/BallisticAttack.cs +++ b/Assets/Scripts/TowerDefense/Towers/Projectiles/BallisticAttack.cs @@ -209,15 +209,11 @@ { case 2: // 减速. SlowDown slowDown = (SlowDown)EndlessBuffManager.instance.GetBuffInstanceByType(EndlessBuffEffectType.SlowDown); - enemy.addSpeedSlowRate(0.15f + (slowDown != null ? slowDown.GetSlowDownAdd(TowerPtr.attributeId) : 0)); - enemy.SetTargetableMatColor(Color.blue); + (enemy as Agent).addSpeedSlowRate(0.15f + (slowDown != null ? slowDown.GetSlowDownAdd(TowerPtr.attributeId) : 0)); break; case 3: // 中毒 // enemy.poisonAgent(damage, attid); // enemy.SetTargetableMatColor(Color.green); - break; - case 5: // 破甲 - enemy.bShieldBreak = true; break; } return; diff --git a/Assets/Scripts/TowerDefense/Towers/Projectiles/HitscanAttack.cs b/Assets/Scripts/TowerDefense/Towers/Projectiles/HitscanAttack.cs index 334c95d..d12ccff 100644 --- a/Assets/Scripts/TowerDefense/Towers/Projectiles/HitscanAttack.cs +++ b/Assets/Scripts/TowerDefense/Towers/Projectiles/HitscanAttack.cs @@ -1,12 +1,9 @@ using ActionGameFramework.Health; using Core.Utilities; -using DG.Tweening; using System; -using System.Net.Http.Headers; using TowerDefense.Agents; using TowerDefense.UI.HUD; using UnityEngine; -using System.Collections; namespace TowerDefense.Towers.Projectiles { @@ -108,15 +105,10 @@ switch (id) { case 2: // 减速. - enemy.addSpeedSlowRate(0.15f); - enemy.SetTargetableMatColor(Color.blue); + (enemy as Agent).addSpeedSlowRate(0.15f); break; case 3: // 中毒 - enemy.poisonAgent(damage, attid); - enemy.SetTargetableMatColor(Color.green); - break; - case 5: // 破甲 - enemy.bShieldBreak = true; + (enemy as Agent).poisonAgent(damage, attid); break; } return; @@ -138,58 +130,17 @@ // 攻击目标已经经历过了Pool了,不能再攻击了。 if (mLiveID != m_Enemy.liveID) return; - // effects - // ParticleSystem pfxPrefab = m_Damager.collisionParticles; - // var attackEffect = Poolable.TryGetPoolable<ParticleSystem>(pfxPrefab.gameObject); - // attackEffect.transform.position = m_Enemy.position; - // attackEffect.Play(); - - // GameObject hitObj = Poolable.TryGetPoolable(m_Damager.collisionObj); - // ParticleSystem ps = hitObj.GetComponent<ParticleSystem>(); - // if (ps == null) - // ps = hitObj.transform.GetChild(0).GetComponent<ParticleSystem>(); - // ps.Play(); - // // StartCoroutine(RecycleParticle(hitObj, ps.main.duration)); - - // var hitVFX = Instantiate(m_Damager.collisionObj, m_Enemy.position, Quaternion.identity); - // var ps = hitVFX.GetComponent<ParticleSystem>(); - // if (ps == null) - // { - // var psChild = hitVFX.transform.GetChild(0).GetComponent<ParticleSystem>(); - // psChild.Play(); - // Destroy(hitVFX, psChild.main.duration); - // } - // else - // { - // ps.Play(); - // Destroy(hitVFX, ps.main.duration); - // } - float finalDamage = m_Damager.finalDamage; bool crit = m_Damager.isCrit; if (crit) { finalDamage += finalDamage; - - // 暂时去掉这个ShakePosition的功能: - //m_Enemy.transform.DOShakePosition(0.5f); - } - // 精英怪和Boss双倍攻击. - bool doubleHit = m_Damager.doubleHit && m_Enemy.bElit; - if (doubleHit) - { - finalDamage *= 2; } - // // 处理光塔对应的攻击增加: if (attackRise > 0) finalDamage += (finalDamage * attackRise); - // 破甲状态 - if (m_Enemy.bShieldBreak) - finalDamage += (finalDamage * 0.1f); - // // 提前处理非当前Enemy的爆炸攻击: if (chainAttackRate > 0) AgentInsManager.instance.StartExplodeAttack(m_Enemy as Agent, finalDamage); @@ -202,37 +153,11 @@ ProcessTowerAttributeAttack(m_Enemy, finalDamage, attributeId); if (!m_Enemy.opponentAgent) - GameUI.instance.generateBloodText(backPos, finalDamage, crit, doubleHit); + GameUI.instance.generateBloodText(backPos, finalDamage, crit); // 播放受击动画: if ((!m_Enemy.isDead) && (m_Enemy.liveID == tid)) (m_Enemy as Agent).PlayOnHit(); - - // 重设到开始位置的处理. liveID必须要等于tid. - /*if( (resetStartPosRate > 0)&&(!m_Enemy.isDead)&& (m_Enemy.liveID == tid)) - { - if (mRand.NextDouble() < resetStartPosRate) - { - Agent ag = m_Enemy as Agent; - if( ag.bBoss) - { - // 如果是Boss,更低的概率重设位置. - if (mRand.NextDouble() < resetStartPosRate / 20.0f) - ag.execAgentPosResetAction(); - } - else - ag.execAgentPosResetAction(); - } - - }*/ - - /*// 链式攻击的测试处理: 需要确保是同一个敌人,ID相同. - if( (chainAttackRate > 0)&& (!m_Enemy.isDead) && (m_Enemy.liveID == tid) ) - { - if (mRand.NextDouble() < chainAttackRate) - AgentInsManager.instance.StartChainAttack(m_Enemy as Agent,m_Damager.alignmentProvider,(float)Math.Floor(finalDamage/2.0f )); - - }*/ m_PauseTimer = true; } diff --git a/Assets/Scripts/TowerDefense/Towers/Tower.cs b/Assets/Scripts/TowerDefense/Towers/Tower.cs index ffee563..2462681 100644 --- a/Assets/Scripts/TowerDefense/Towers/Tower.cs +++ b/Assets/Scripts/TowerDefense/Towers/Tower.cs @@ -36,8 +36,6 @@ /// </summary> public class Tower : Targetable { - public readonly float INSCENE_TU_DAMAGE = 30f; - public static readonly int MAX_LEVEL = 4; /// <summary> @@ -443,8 +441,9 @@ { inSceneTowerLevel++; + // cx test // 设置攻击数据的加强,暂时是测试数据,后面需要读取表格数据处理: - float damageAdd = inSceneTowerLevel * INSCENE_TU_DAMAGE; + float damageAdd = inSceneTowerLevel; Debug.Log("Upgrade Tower name is:" + name); diff --git a/Assets/Scripts/TowerDefense/UI/HUD/GameUI.cs b/Assets/Scripts/TowerDefense/UI/HUD/GameUI.cs index 628e0c9..9ddc03f 100644 --- a/Assets/Scripts/TowerDefense/UI/HUD/GameUI.cs +++ b/Assets/Scripts/TowerDefense/UI/HUD/GameUI.cs @@ -1658,7 +1658,7 @@ /// <param name="x"></param> /// <param name="y"></param> /// <param name="val"></param> - public void generateBloodText(Vector3 wpos, float val, bool crit = false, bool doubleHit = false, bool poison = false) + public void generateBloodText(Vector3 wpos, float val, bool crit = false, bool poison = false) { if (Mathf.FloorToInt(val) == 0) return; @@ -1680,8 +1680,6 @@ { tm.GetComponent<Transform>().SetParent(GameObject.Find("BattleMainUI").GetComponent<Transform>(), true); string bloodStr = ""; - if (doubleHit) - bloodStr += "Dble!"; if (crit) bloodStr += "Crt!"; bloodStr += "-"; -- Gitblit v1.9.1