wgl 6 месяцев назад
Родитель
Сommit
e4db0b88ef

+ 18 - 23
ActionTowerDefense/Assets/Scripts/Characters/AttributeStatus.cs

@@ -20,6 +20,7 @@ public class AttributeStatus : MonoBehaviour
     private MoveCharacter character;
     private Rigidbody rb;
     private Foot foot;
+    private HitFeedbackSystem hitFeedbackSystem;
 
     //behit参数
     [HideInInspector] public bool haveNewSpecialStates;
@@ -81,6 +82,7 @@ public class AttributeStatus : MonoBehaviour
         character = GetComponentInParent<MoveCharacter>();
         rb = character.rb;
         foot = character.foot;
+        hitFeedbackSystem = GetComponent<HitFeedbackSystem>();
     }
 
     public void Update()
@@ -97,8 +99,10 @@ public class AttributeStatus : MonoBehaviour
     {
         if (!haveNewSpecialStates)
         {
+            hitFeedbackSystem.EnterHitStun();
             return;
         }
+        hitFeedbackSystem.canHitStun = false;
         haveNewSpecialStates = false;
         switch (curSpecialStates)
         {
@@ -186,31 +190,22 @@ public class AttributeStatus : MonoBehaviour
             case SpecialState.BlownUp:
             //击落
             case SpecialState.ShotDown:
-                switch (hitState) 
+                switch (hitState)
                 {
                     case 0:
-                        if(rb.velocity.magnitude >= 0)
+                        Vector3 vel = rb.velocity;
+                        if (foot.TrigGround && vel.y <= 0.01f)
                         {
-                            Vector3 vel = rb.velocity;
-                            if (foot.TrigGround && vel.y <= 0.01f)
-                            {
-                                vel = Vector3.zero;
-                                character.ani.Play("weak", 0, 0);
-                                hitState = 1;
-                            }
-                            else
-                            {
-                                vel.x -= decelerationRatioX * Time.deltaTime;
-                                vel.y -= decelerationRatioY * Time.deltaTime;
-                            }
-                            rb.velocity = vel;
+                            vel = Vector3.zero;
+                            character.ani.Play("weak", 0, 0);
+                            hitState = 1;
                         }
                         else
                         {
-                            rb.velocity = Vector3.zero;
-                            character.ani.Play("weak", 0, 0);
-                            hitState = 1;
+                            vel.x -= decelerationRatioX * Time.deltaTime;
+                            vel.y -= decelerationRatioY * Time.deltaTime;
                         }
+                        rb.velocity = vel;
                         break;
                     case 1:
                         //眩晕状态
@@ -260,7 +255,7 @@ public class AttributeStatus : MonoBehaviour
     }
 
     //判断优先级,ture为优先级高于当前控制
-    public bool PriorityOrder(SpecialState specialState,AttackInfo attackInfo,Character attackFrom)
+    public bool PriorityOrder(SpecialState specialState, AttackInfo attackInfo, Character attackFrom)
     {
         if (curSpecialStates != SpecialState.Null && curSpecialStates >= specialState)
         {
@@ -270,7 +265,7 @@ public class AttributeStatus : MonoBehaviour
             haveNewSpecialStates = true;
             return true;
         }
-        if(curSpecialStates == SpecialState.Null)
+        if (curSpecialStates == SpecialState.Null)
         {
             curSpecialStates = specialState;
             this.attackInfo = attackInfo;
@@ -313,7 +308,7 @@ public class AttributeStatus : MonoBehaviour
             vec3.x = -vec3.x;
         }
         rb.AddForce(vec3 * blowUp.force * (1 - resistances.BlowUp), ForceMode.Impulse);
-        character.ani.Play("hitted",0,0);
+        character.ani.Play("hitted", 0, 0);
         hitState = 0;
         character.ChangeState(CharacterState.SpecialStatus_BlowUp);
         character.ChangeStateText(CharacterState.SpecialStatus_BlowUp);
@@ -347,7 +342,7 @@ public class AttributeStatus : MonoBehaviour
     }
 
     //受到穿甲
-    public int AddArmor(AttackInfo.Armor armor,int damage)
+    public int AddArmor(AttackInfo.Armor armor, int damage)
     {
         //计算护甲减免
         int am = resistances.armor;
@@ -373,4 +368,4 @@ public class AttributeStatus : MonoBehaviour
     }
 
 
-}
+}

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

@@ -261,6 +261,10 @@ public class Demonic : MoveCharacter
     public override void OnState()
     {
         base.OnState();
+        if (state == CharacterState.None)
+        {
+            return;
+        }
         //hurtKeepTime -= Time.deltaTime;
         dieKeepTime -= Time.deltaTime;
         invincibleTime -= Time.deltaTime;

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

@@ -201,6 +201,10 @@ public class Enemy : MoveCharacter
     public override void OnState()
     {
         base.OnState();
+        if (state == CharacterState.None)
+        {
+            return;
+        }
         //hurtKeepTime -= Time.deltaTime;
         dieKeepTime -= Time.deltaTime;
         invincibleTime -= Time.deltaTime;

+ 10 - 20
ActionTowerDefense/Assets/Scripts/Characters/HitFeedbackSystem.cs

@@ -13,12 +13,12 @@ public class HitFeedbackSystem : MonoBehaviour
     [TabGroup("¶ÙÖ¡")] [DisplayOnly] public bool isFreeze;
     [HideInInspector] public bool canFreeze;
     private RigidbodyConstraints origRC;
+    private Vector3 velocity;   //¶Ù֡ǰËÙ¶È
+    [HideInInspector] public CharacterState curCharacterState;  //¶Ù֡ǰ״̬
 
     [TabGroup("½©Ö±")] [DisplayOnly] public float hitStunTime;
     [HideInInspector] public bool canHitStun;
 
-    [DisplayOnly] public CharacterState characterState;  //½©Ö±Ç°×´Ì¬
-
     private void Awake()
     {
         character = GetComponentInParent<MoveCharacter>();
@@ -30,7 +30,7 @@ public class HitFeedbackSystem : MonoBehaviour
         
     }
 
-    void Update()
+    void FixedUpdate()
     {
         //¶ÙÖ¡
         if (isFreeze)
@@ -42,7 +42,10 @@ public class HitFeedbackSystem : MonoBehaviour
                 if (character.rb.constraints == RigidbodyConstraints.FreezeAll)
                 {
                     character.rb.constraints = origRC;
+                    character.rb.velocity = velocity;
+                    character.state = curCharacterState;
                 }
+                attributeStatus.AddSpecialState();
             }
             freezeFrame -= 1;
         }
@@ -52,15 +55,7 @@ public class HitFeedbackSystem : MonoBehaviour
     {
         if (hitStunTime <= 0)
         {
-            if (attributeStatus.haveNewSpecialStates)
-            {
-                characterState = CharacterState.Idle;
-                attributeStatus.AddSpecialState();
-            }
-            else
-            {
-                character.ChangeState(characterState);
-            }
+            character.ChangeState(CharacterState.Idle);
         }
         else
         {
@@ -78,6 +73,9 @@ public class HitFeedbackSystem : MonoBehaviour
             if (!isFreeze)
             {
                 origRC = character.rb.constraints;
+                velocity = character.rb.velocity;
+                curCharacterState = character.state;
+                character.state = CharacterState.None;
             }
             isFreeze = true;
             character.ani.speed = 0;
@@ -92,16 +90,8 @@ public class HitFeedbackSystem : MonoBehaviour
         {
             canHitStun = false;
             character.ani.Play("hitted", 0, 0);
-            if(character.state != CharacterState.HitStun)
-            {
-                characterState = character.state;
-            }
             character.ChangeState(CharacterState.HitStun);
             character.ChangeStateText(CharacterState.HitStun);
         }
-        else
-        {
-            attributeStatus.AddSpecialState();
-        }
     }
 }

+ 3 - 2
ActionTowerDefense/Assets/Scripts/Characters/MoveCharacter.cs

@@ -309,11 +309,12 @@ public class MoveCharacter : Character
         uiHp.Show(hp, totalHp);
         if (hp <= 0)
         {
+            hitFeedbackSystem.curCharacterState = CharacterState.Die;
             ChangeState(CharacterState.Die);
             return;
         }
-
-        hitFeedbackSystem.EnterHitStun();
+        
+        //¶ÙÖ¡
         hitFeedbackSystem.FreezeFrame();
     }
 

+ 4 - 0
ActionTowerDefense/Assets/Scripts/Characters/PlayerController.cs

@@ -940,6 +940,10 @@ public class PlayerController : MoveCharacter
     public override void OnState()
     {
         base.OnState();
+        if(state == CharacterState.None)
+        {
+            return;
+        }
         cacheJumpTime -= Time.deltaTime;
         cacheSummonTime -= Time.deltaTime;
         canJumpTime -= Time.deltaTime;