StateMachineUtilities.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // Animancer // https://kybernetik.com.au/animancer // Copyright 2018-2024 Kybernetik //
  2. #if UNITY_EDITOR && UNITY_IMGUI
  3. using UnityEditor;
  4. using UnityEngine;
  5. using Object = UnityEngine.Object;
  6. namespace Animancer.FSM
  7. {
  8. /// <summary>[Editor-Only] Utilities used by the <see cref="FSM"/> system.</summary>
  9. /// <remarks>
  10. /// <strong>Documentation:</strong>
  11. /// <see href="https://kybernetik.com.au/animancer/docs/manual/fsm">
  12. /// Finite State Machines</see>
  13. /// </remarks>
  14. /// https://kybernetik.com.au/animancer/api/Animancer.FSM/StateMachineUtilities
  15. ///
  16. public static class StateMachineUtilities
  17. {
  18. /************************************************************************************************************************/
  19. /// <summary>Draws a GUI field for the `value`.</summary>
  20. public static T DoGenericField<T>(Rect area, string label, T value)
  21. {
  22. if (typeof(Object).IsAssignableFrom(typeof(T)))
  23. {
  24. return (T)(object)EditorGUI.ObjectField(
  25. area,
  26. label,
  27. value as Object,
  28. typeof(T),
  29. true);
  30. }
  31. var stateName = value != null ? value.ToString() : "Null";
  32. EditorGUI.LabelField(area, label, stateName);
  33. return value;
  34. }
  35. /************************************************************************************************************************/
  36. /// <summary>
  37. /// If the <see cref="Rect.height"/> is positive, this method moves the <see cref="Rect.y"/> by that amount and
  38. /// adds the <see cref="EditorGUIUtility.standardVerticalSpacing"/>.
  39. /// </summary>
  40. public static void NextVerticalArea(ref Rect area)
  41. {
  42. if (area.height > 0)
  43. area.y += area.height + EditorGUIUtility.standardVerticalSpacing;
  44. }
  45. /************************************************************************************************************************/
  46. }
  47. }
  48. #endif