diff options
Diffstat (limited to 'ActiveRagdoll/Assets/TABG/Scripts/Debug/GizmosHandle.cs')
-rw-r--r-- | ActiveRagdoll/Assets/TABG/Scripts/Debug/GizmosHandle.cs | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/ActiveRagdoll/Assets/TABG/Scripts/Debug/GizmosHandle.cs b/ActiveRagdoll/Assets/TABG/Scripts/Debug/GizmosHandle.cs new file mode 100644 index 0000000..2122912 --- /dev/null +++ b/ActiveRagdoll/Assets/TABG/Scripts/Debug/GizmosHandle.cs @@ -0,0 +1,59 @@ +using System.Collections; +using System.Collections.Generic; +using Unity.VisualScripting; +using UnityEngine; + +namespace Rigging.Debugging +{ + [DefaultExecutionOrder(-100)] + public class GizmosHandle : MonoBehaviour + { + private static GizmosHandle instance; + private static event System.Action onDrawGizmos; + private static event System.Action onDrawGizmosFixedUpdate; + + private void OnDrawGizmos() + { + onDrawGizmos?.Invoke(); + onDrawGizmos = null; + + onDrawGizmosFixedUpdate?.Invoke(); + } + + private void FixedUpdate() + { + onDrawGizmosFixedUpdate = null; + } + + public static void DrawCube(Vector3 position, Vector3 size) + { + Check(); + + if (Time.inFixedTimeStep) + { + onDrawGizmosFixedUpdate += () => + { + Gizmos.DrawCube(position, size); + }; + } + else + { + onDrawGizmos += () => + { + Gizmos.DrawCube(position, size); + }; + } + } + + static void Check() + { + if(instance == null) { + GameObject handle = new GameObject(); + handle.name = "GizmosHandle"; + instance = handle.AddComponent<GizmosHandle>(); + } + } + + } + +}
\ No newline at end of file |