Bläddra i källkod

Sort of revert the last one but I'm having an issue with incorrect load order.

x89rt2 3 månader sedan
förälder
incheckning
c487858c39
2 ändrade filer med 34 tillägg och 4 borttagningar
  1. 1 1
      Assets/Scenes/Opening.unity
  2. 33 3
      Assets/Scripts/Script/AnimatorExtensions.cs

+ 1 - 1
Assets/Scenes/Opening.unity

@@ -64748,7 +64748,7 @@ Animator:
   m_GameObject: {fileID: 1576401444}
   m_Enabled: 1
   m_Avatar: {fileID: 0}
-  m_Controller: {fileID: 9100000, guid: 89b572d6698ea714097bf5420918e98c, type: 2}
+  m_Controller: {fileID: 0}
   m_CullingMode: 0
   m_UpdateMode: 0
   m_ApplyRootMotion: 0

+ 33 - 3
Assets/Scripts/Script/AnimatorExtensions.cs

@@ -2,12 +2,42 @@ using UnityEngine;
 
 public static class AnimatorExtensions
 {
+    // Toggle this if you want strict original behavior vs safe behavior
+    public static bool EnableSafetyChecks = true;
+
     public static void SafeSetInt(this Animator anim, int hash, int value)
     {
-        if (anim == null) return;
-        if (!anim.isActiveAndEnabled) return;
-        if (anim.runtimeAnimatorController == null) return;
+        if (EnableSafetyChecks)
+        {
+            if (anim == null) return;
+            if (!anim.isActiveAndEnabled) return;
+            if (anim.runtimeAnimatorController == null) return;
+        }
 
         anim.SetInteger(hash, value);
     }
+
+    public static void SafeSetTrigger(this Animator anim, int hash)
+    {
+        if (EnableSafetyChecks)
+        {
+            if (anim == null) return;
+            if (!anim.isActiveAndEnabled) return;
+            if (anim.runtimeAnimatorController == null) return;
+        }
+
+        anim.SetTrigger(hash);
+    }
+
+    public static void SafeSetBool(this Animator anim, int hash, bool value)
+    {
+        if (EnableSafetyChecks)
+        {
+            if (anim == null) return;
+            if (!anim.isActiveAndEnabled) return;
+            if (anim.runtimeAnimatorController == null) return;
+        }
+
+        anim.SetBool(hash, value);
+    }
 }