Quellcode durchsuchen

修复击飞击落问题,暴露的参数改中文

wgl vor 6 Monaten
Ursprung
Commit
d7489920cd

+ 15 - 14
ActionTowerDefense/Assets/Scripts/Characters/AttackTrigger.cs

@@ -61,24 +61,25 @@ public class AttackTrigger : MonoBehaviour
                 {
                     return;
                 }
-                trigedObjs.Add(hitTrigger);
-                hitTrigger.BeHit(attackInfo, owner);
-                if (hitTrigger.owner.debugAttackFrom)
+                if(trigedObjs.Count == 0 && !trigedObjs.Exists(x => x== hitTrigger))
                 {
-                    hitTrigger.owner.DebugAttackFrom(owner.name, attackInfo.damage);
-                }
-                if (owner.GetComponent<Demonic>())
-                {
-                    hitTrigger.attackerID = owner.GetComponent<Demonic>().id;
-                }
-                if (isSingleAttack)
-                {
-                    cantSingleAttack = true;
+                    trigedObjs.Add(hitTrigger);
+                    hitTrigger.BeHit(attackInfo, owner);
+                    if (hitTrigger.owner.debugAttackFrom)
+                    {
+                        hitTrigger.owner.DebugAttackFrom(owner.name, attackInfo.damage);
+                    }
+                    if (owner.GetComponent<Demonic>())
+                    {
+                        hitTrigger.attackerID = owner.GetComponent<Demonic>().id;
+                    }
+                    if (isSingleAttack)
+                    {
+                        cantSingleAttack = true;
+                    }
                 }
             }
-
         }
-
     }
 
     private void OnEnable()

+ 19 - 45
ActionTowerDefense/Assets/Scripts/Characters/AttributeStatus.cs

@@ -9,8 +9,8 @@ public enum SpecialState
 {
     Null = -1,
     FloatState = 0,
-    ShotDown = 1,
-    BlownUp = 2,
+    BlownUp = 1,
+    ShotDown = 2,
     Weak = 3,
 }
 
@@ -116,8 +116,8 @@ public class AttributeStatus : MonoBehaviour
                         else if (foot.TrigGround || curHeight <= origPos.y + 0.05f)
                         {
                             floatingState = 0;
-                            character.ChangeState(CharacterState.Idle);
-                            curSpecialStates = SpecialState.Null;
+                            character.isAdjustHeight = 1;
+                            OutSpecialState();
                             return;
                         }
                         break;
@@ -146,41 +146,11 @@ public class AttributeStatus : MonoBehaviour
                 break;
             //击飞
             case SpecialState.BlownUp:
-                if (rb.velocity.magnitude > 0)
-                {
-                    //击飞中
-                    Vector3 vel = rb.velocity;
-                    if (foot.TrigGround && vel.y <= 0.01f)
-                    {
-                        vel = Vector3.zero;
-                    }
-                    else
-                    {
-                        vel.x -= decelerationRatioX * Time.deltaTime;
-                        vel.y -= decelerationRatioY * Time.deltaTime;
-                    }
-                    rb.velocity = vel;
-                }
-                else
-                {
-                    //眩晕状态
-                    if (attributeTime <= 0)
-                    {
-                        curSpecialStates = SpecialState.Null;
-                        character.ChangeState(CharacterState.Idle);
-                    }
-                    else
-                    {
-                        rb.velocity = Vector3.zero;
-                        attributeTime -= Time.deltaTime;
-                    }
-                }
-                break;
             //击落
             case SpecialState.ShotDown:
                 if (rb.velocity.magnitude > 0)
                 {
-                    //击
+                    //击飞中
                     Vector3 vel = rb.velocity;
                     if (foot.TrigGround && vel.y <= 0.01f)
                     {
@@ -198,14 +168,8 @@ public class AttributeStatus : MonoBehaviour
                     //眩晕状态
                     if (attributeTime <= 0)
                     {
-                        //被击晕后上升
-                        rb.constraints = RigidbodyConstraints.FreezeRotation | RigidbodyConstraints.FreezePositionZ | RigidbodyConstraints.FreezePositionY;
-                        rb.useGravity = false;
-                        if (character.AdjustHeight())
-                        {
-                            curSpecialStates = SpecialState.Null;
-                            character.ChangeState(CharacterState.Idle);
-                        }
+                        character.isAdjustHeight = 1;
+                        OutSpecialState();
                     }
                     else
                     {
@@ -218,8 +182,7 @@ public class AttributeStatus : MonoBehaviour
             case SpecialState.Weak:
                 if (attributeTime <= 0)
                 {
-                    curSpecialStates = SpecialState.Null;
-                    character.ChangeState(CharacterState.Idle);
+                    OutSpecialState();
                 }
                 else
                 {
@@ -230,6 +193,17 @@ public class AttributeStatus : MonoBehaviour
         }
     }
 
+    public void OutSpecialState()
+    {
+        curSpecialStates = SpecialState.Null;
+        if (character.canFly)
+        {
+            rb.useGravity = false;
+            rb.constraints = RigidbodyConstraints.FreezeRotation | RigidbodyConstraints.FreezePositionZ | RigidbodyConstraints.FreezePositionY;
+        }
+        character.ChangeState(CharacterState.Idle);
+    }
+
     public int DamageCalculation(int damage)
     {
         damage = (int)(damage * (1 + vulnerableRate) + 0.5f);

+ 11 - 10
ActionTowerDefense/Assets/Scripts/Characters/Character.cs

@@ -4,6 +4,7 @@ using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using TMPro;
+using Sirenix.OdinInspector;
 
 //角色状态
 public enum CharacterState
@@ -33,6 +34,15 @@ public enum CharacterState
 
 public class Character : MonoBehaviour
 {
+    [FoldoutGroup("组件")] public Rigidbody rb;
+    [FoldoutGroup("组件")] public Transform bodyTrans;
+    [FoldoutGroup("组件")] public BeSearchTrigger beSearchTrigger;
+    [FoldoutGroup("组件")] public SearchTrigger searchTrigger;
+    [FoldoutGroup("组件")] public GameObject bodyCollider;
+    [FoldoutGroup("组件")] public UIHP uiHp;
+    [FoldoutGroup("组件")] public BeHitTrigger beHitTrigger;
+    [FoldoutGroup("组件")] public AttackController attackController;
+
     [Header("骨骼")]
     public SkeletonMecanim mecanim;
     public Skeleton skeleton;
@@ -56,16 +66,6 @@ public class Character : MonoBehaviour
     [HideInInspector]
     public float attackDis;
 
-    [Header("组件")]
-    public Rigidbody rb;
-    public Transform bodyTrans;
-    public BeSearchTrigger beSearchTrigger;
-    public SearchTrigger searchTrigger;
-    public GameObject bodyCollider;
-    public UIHP uiHp;
-    public BeHitTrigger beHitTrigger;
-    public AttackController attackController;    
-
     [DisplayOnly]
     public Character targetCharacter;
     [HideInInspector]
@@ -106,6 +106,7 @@ public class Character : MonoBehaviour
 
     //调试开关
     [Header("debug攻击者")] public bool debugAttackFrom;
+
     public virtual void Init()
     {
         //确保组件不丢失

+ 2 - 0
ActionTowerDefense/Assets/Scripts/Characters/Demonic.cs

@@ -595,6 +595,8 @@ public class Demonic : MoveCharacter
                     attackController.effect.SetActive(false);
                 }
                 attackController.ChooseAttack(curAttackID);
+                attackController.isAttackTriggerOn = false;
+                attackController.attackTrigger.gameObject.SetActive(false);
                 break;
             case CharacterState.Die:
                 isDie = false;

+ 23 - 4
ActionTowerDefense/Assets/Scripts/Characters/Enemy.cs

@@ -209,6 +209,11 @@ public class Enemy : MoveCharacter
         switch (state)
         {
             case CharacterState.Idle:
+                if (isAdjustHeight == 1)
+                {
+                    ChangeState(CharacterState.Rise);
+                    break;
+                }
                 if (isAttack)
                 {
                     Attack_march();
@@ -327,12 +332,24 @@ public class Enemy : MoveCharacter
                 //AdjustHeight();
                 break;
             case CharacterState.Rise:
-                if (rb.velocity.y <= 0)
+                if (isAdjustHeight == 1)
                 {
-                    ChangeState(CharacterState.Fall);
-                    break;
+                    AdjustHeight();
+                }
+                else if (isAdjustHeight == 2)
+                {
+                    ChangeState(CharacterState.Idle);
+                    isAdjustHeight = 0;
+                }
+                else
+                {
+                    if (rb.velocity.y <= 0)
+                    {
+                        ChangeState(CharacterState.Fall);
+                        break;
+                    }
+                    rb.velocity += Vector3.up * extraRiseGravity * Time.deltaTime;
                 }
-                rb.velocity += Vector3.up * extraRiseGravity * Time.deltaTime;
                 break;
             case CharacterState.Fall:
                 if (foot.TrigGround || canFly)
@@ -422,6 +439,8 @@ public class Enemy : MoveCharacter
             //    break;
             case CharacterState.Attack:
                 attackController.ChooseAttack(curAttackID);
+                attackController.isAttackTriggerOn = false;
+                attackController.attackTrigger.gameObject.SetActive(false);
                 break;
             case CharacterState.Die:
                 isDie = false;

+ 13 - 9
ActionTowerDefense/Assets/Scripts/Characters/MoveCharacter.cs

@@ -4,9 +4,16 @@ using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using TMPro;
+using Sirenix.OdinInspector;
 
 public class MoveCharacter : Character
 {
+    [FoldoutGroup("组件")]
+    public Foot foot;
+    [HideInInspector] public AttributeStatus attributeStatus;
+    private ScreenReflectPresets screenReflectPresets;
+    private HitFeedbackSystem hitFeedbackSystem;
+
     [Header("角色抗击打值")]
     public int hitResistance;
 
@@ -18,10 +25,6 @@ public class MoveCharacter : Character
     public Material[] outlineMats;
     public Material[] outline1Mats;
 
-    [Header("组件")]
-    public Foot foot;
-    [HideInInspector]public AttributeStatus attributeStatus;
-
     [Header("额外重力")]
     public float extraRiseGravity = 0; //上升时额外重力加速度
     public float extraFallGravity = -10; //下落时额外重力加速度
@@ -29,12 +32,11 @@ public class MoveCharacter : Character
     [Header("属性")]
     public float moveSpeed = 5;
     public bool needToAdjustFlyHeight;
-    [DisplayOnly]
-    public float flyHeight;
-    public float maxFlyHeight;
-    public float minFlyHeight;
+    [FoldoutGroup("回升")][DisplayOnly] public float flyHeight;
+    [FoldoutGroup("回升")][LabelText("最大高度")] public float maxFlyHeight;
+    [FoldoutGroup("回升")][LabelText("最低高度")] public float minFlyHeight;
     float refspeed = 1;
-    public float flyUpTime;
+    [FoldoutGroup("回升")][LabelText("消耗时间")] public float flyUpTime;
     [HideInInspector]
     public int isAdjustHeight;
 
@@ -80,6 +82,7 @@ public class MoveCharacter : Character
         mesh = spinee.GetComponent<MeshRenderer>();
         mats = mesh.materials;
         attributeStatus = GetComponentInChildren<AttributeStatus>();
+        screenReflectPresets = Camera.main.GetComponentInParent<ScreenReflectPresets>();
     }
 
     private void Start()
@@ -214,6 +217,7 @@ public class MoveCharacter : Character
     //造成伤害附加其他效果
     public override void BeHit(AttackInfo attackInfo, Character attackFrom)
     {
+        screenReflectPresets.ScreenReflect(hitFeedbackSystem, attackFrom.attackController.attackValue - hitResistance);
         base.BeHit(attackInfo, attackFrom);
         int damage = attackInfo.damage;
         if (attackInfo.attackEffect.Length > 0)