WGL hai 2 meses
pai
achega
36f8ba6866

+ 45 - 0
ActionTowerDefense/Assets/Animations/ui/player_is_dying.anim

@@ -165,6 +165,25 @@ AnimationClip:
     path: red
     classID: 114
     script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3}
+  - curve:
+      serializedVersion: 2
+      m_Curve:
+      - serializedVersion: 3
+        time: 0
+        value: 1
+        inSlope: Infinity
+        outSlope: Infinity
+        tangentMode: 103
+        weightedMode: 0
+        inWeight: 0
+        outWeight: 0
+      m_PreInfinity: 2
+      m_PostInfinity: 2
+      m_RotationOrder: 4
+    attribute: m_IsActive
+    path: red
+    classID: 1
+    script: {fileID: 0}
   m_PPtrCurves: []
   m_SampleRate: 60
   m_WrapMode: 0
@@ -201,6 +220,13 @@ AnimationClip:
       typeID: 114
       customType: 0
       isPPtrCurve: 0
+    - serializedVersion: 2
+      path: 4200685455
+      attribute: 2086281974
+      script: {fileID: 0}
+      typeID: 1
+      customType: 0
+      isPPtrCurve: 0
     pptrCurveMapping: []
   m_AnimationClipSettings:
     serializedVersion: 2
@@ -371,6 +397,25 @@ AnimationClip:
     path: red
     classID: 114
     script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3}
+  - curve:
+      serializedVersion: 2
+      m_Curve:
+      - serializedVersion: 3
+        time: 0
+        value: 1
+        inSlope: Infinity
+        outSlope: Infinity
+        tangentMode: 103
+        weightedMode: 0
+        inWeight: 0
+        outWeight: 0
+      m_PreInfinity: 2
+      m_PostInfinity: 2
+      m_RotationOrder: 4
+    attribute: m_IsActive
+    path: red
+    classID: 1
+    script: {fileID: 0}
   m_EulerEditorCurves: []
   m_HasGenericRootTransform: 0
   m_HasMotionFloatCurves: 0

+ 1 - 1
ActionTowerDefense/Assets/Animations/ui/player_is_hurt.anim

@@ -220,7 +220,7 @@ AnimationClip:
     m_Level: 0
     m_CycleOffset: 0
     m_HasAdditiveReferencePose: 0
-    m_LoopTime: 1
+    m_LoopTime: 0
     m_LoopBlend: 0
     m_LoopBlendOrientation: 0
     m_LoopBlendPositionY: 0

+ 9 - 3
ActionTowerDefense/Assets/Animations/ui/player_is_hurt.controller

@@ -37,10 +37,10 @@ AnimatorStateMachine:
   m_ChildStates:
   - serializedVersion: 1
     m_State: {fileID: -7036804217895200180}
-    m_Position: {x: 300, y: 0, z: 0}
+    m_Position: {x: 310, y: -40, z: 0}
   - serializedVersion: 1
     m_State: {fileID: 2585246643610584744}
-    m_Position: {x: 235, y: 65, z: 0}
+    m_Position: {x: 240, y: 40, z: 0}
   - serializedVersion: 1
     m_State: {fileID: 7087961896813838754}
     m_Position: {x: 270, y: 130, z: 0}
@@ -62,7 +62,13 @@ AnimatorController:
   m_PrefabAsset: {fileID: 0}
   m_Name: player_is_hurt
   serializedVersion: 5
-  m_AnimatorParameters: []
+  m_AnimatorParameters:
+  - m_Name: hp
+    m_Type: 1
+    m_DefaultFloat: 0
+    m_DefaultInt: 0
+    m_DefaultBool: 0
+    m_Controller: {fileID: 0}
   m_AnimatorLayers:
   - serializedVersion: 5
     m_Name: Base Layer

+ 19 - 3
ActionTowerDefense/Assets/Resources/Prefab/GameUI/Game_UI.prefab

@@ -59,7 +59,7 @@ MonoBehaviour:
   m_Name: 
   m_EditorClassIdentifier: 
   m_Material: {fileID: 0}
-  m_Color: {r: 0, g: 0, b: 0, a: 0.5882353}
+  m_Color: {r: 0, g: 0, b: 0, a: 0}
   m_RaycastTarget: 1
   m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
   m_Maskable: 1
@@ -93,7 +93,7 @@ GameObject:
   m_Icon: {fileID: 0}
   m_NavMeshLayer: 0
   m_StaticEditorFlags: 0
-  m_IsActive: 1
+  m_IsActive: 0
 --- !u!224 &6165425494587171142
 RectTransform:
   m_ObjectHideFlags: 0
@@ -553,6 +553,7 @@ GameObject:
   - component: {fileID: 4641053790322432084}
   - component: {fileID: 4641053790322432085}
   - component: {fileID: 4641053790322432086}
+  - component: {fileID: 3283310685643410726}
   m_Layer: 5
   m_Name: Game_UI
   m_TagString: Untagged
@@ -655,6 +656,21 @@ MonoBehaviour:
   m_BlockingMask:
     serializedVersion: 2
     m_Bits: 6291455
+--- !u!114 &3283310685643410726
+MonoBehaviour:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 4641053790322432087}
+  m_Enabled: 1
+  m_EditorHideFlags: 0
+  m_Script: {fileID: 11500000, guid: b706dd9ace3b193409ab22f79ae600e5, type: 3}
+  m_Name: 
+  m_EditorClassIdentifier: 
+  player_is_hurt: {fileID: 8934630985529627371}
+  half_hp: {fileID: 4732896275965495917}
+  player_is_hurt_animaton: {fileID: 7400000, guid: 286624e7857163f4aa8de03ec7dc11dc, type: 2}
 --- !u!1 &4641053790667657259
 GameObject:
   m_ObjectHideFlags: 0
@@ -5571,7 +5587,7 @@ GameObject:
   m_Icon: {fileID: 0}
   m_NavMeshLayer: 0
   m_StaticEditorFlags: 0
-  m_IsActive: 0
+  m_IsActive: 1
 --- !u!224 &2208544280579479012
 RectTransform:
   m_ObjectHideFlags: 0

+ 7 - 0
ActionTowerDefense/Assets/Scripts/Characters/AnimatorHash.cs

@@ -8,8 +8,12 @@ public class AnimatorHash
     public static int ANIMATOR_fall;
     public static int ANIMATOR_idle;
     public static int ANIMATOR_jump;
+    public static int ANIMATOR_player_is_dying;
+    public static int ANIMATOR_player_is_hurt;
+    public static int ANIMATOR_player_is_ok;
     public static int ANIMATOR_rush;
     public static int ANIMATOR_walk;
+    
 
     static AnimatorHash()
     {
@@ -17,6 +21,9 @@ public class AnimatorHash
         ANIMATOR_fall = Animator.StringToHash("fall");
         ANIMATOR_idle = Animator.StringToHash("idle");
         ANIMATOR_jump = Animator.StringToHash("jump");
+        ANIMATOR_player_is_dying = Animator.StringToHash("player_is_dying");
+        ANIMATOR_player_is_hurt = Animator.StringToHash("player_is_hurt");
+        ANIMATOR_player_is_ok = Animator.StringToHash("player_is_ok");
         ANIMATOR_rush = Animator.StringToHash("rush");
         ANIMATOR_walk = Animator.StringToHash("walk");
     }

+ 2 - 1
ActionTowerDefense/Assets/Scripts/Characters/PlayerController.cs

@@ -1683,7 +1683,7 @@ public class PlayerController : MoveCharacter
             return;
         }
         base.BeHit(attackMethod, attackFrom);
-        //ÆÁÄ»ºìÉÁ+¶¶¶¯
+        //ÆÁÄ»¶¶¶¯
         if (ss == null)
         {
             ss = Camera.main.GetComponentInParent<ScreenShake>();
@@ -1693,5 +1693,6 @@ public class PlayerController : MoveCharacter
         {
             ss.ShakeScreen(1);
         }
+        GameUI.instance.HurtMask((hp *1f)/totalHp);
     }
 }

+ 61 - 0
ActionTowerDefense/Assets/Scripts/UI/GameUI.cs

@@ -0,0 +1,61 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+using UnityEngine.UI;
+
+public class GameUI : MonoBehaviour
+{
+    public static GameUI instance;
+
+    public Animator player_is_hurt;
+    public Image half_hp;
+    public AnimationClip player_is_hurt_animaton;
+
+    private float hurtClipTime;
+    private float hurtTime;
+    private bool isHurt;
+    private float hpRate;
+    private float lastDyingTime;
+    private void Awake()
+    {
+        if (!instance)
+        {
+            instance = this;
+        }
+        hurtClipTime = player_is_hurt_animaton.length;
+    }
+    private void Update()
+    {
+        if (isHurt)
+        {
+            hurtTime += Time.deltaTime;
+            if(hurtTime >= hurtClipTime)
+            {
+                isHurt = false;
+                if (hpRate >= 0.2f)
+                {
+                    player_is_hurt.Play(AnimatorHash.ANIMATOR_player_is_ok, 0, 0);
+                }
+                else
+                {
+
+                    player_is_hurt.Play(AnimatorHash.ANIMATOR_player_is_dying, 0, lastDyingTime);
+                }
+            }
+        }
+    }
+    public void HurtMask(float hpRate)
+    {
+        AnimatorStateInfo stateInfo = player_is_hurt.GetCurrentAnimatorStateInfo(0);
+        if(stateInfo.shortNameHash != AnimatorHash.ANIMATOR_player_is_hurt)
+        {
+            lastDyingTime = player_is_hurt.GetCurrentAnimatorStateInfo(0).normalizedTime;
+        }
+        player_is_hurt.Play(AnimatorHash.ANIMATOR_player_is_hurt, 0, 0);
+        half_hp.color = new Color(0, 0, 0, (0.6f - hpRate) * 2);
+        this.hpRate = hpRate;
+        hurtTime = 0;
+        isHurt = true;
+
+    }
+}

+ 11 - 0
ActionTowerDefense/Assets/Scripts/UI/GameUI.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: b706dd9ace3b193409ab22f79ae600e5
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: