StateMachineUtilities.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // Animancer // https://kybernetik.com.au/animancer // Copyright 2022 Kybernetik //
  2. #if UNITY_EDITOR
  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. /// Documentation: <see href="https://kybernetik.com.au/animancer/docs/manual/fsm">Finite State Machines</see>
  11. /// </remarks>
  12. /// https://kybernetik.com.au/animancer/api/Animancer.FSM/StateMachineUtilities
  13. ///
  14. public static class StateMachineUtilities
  15. {
  16. /************************************************************************************************************************/
  17. /// <summary>Draws a GUI field for the `value`.</summary>
  18. public static T DoGenericField<T>(Rect area, string label, T value)
  19. {
  20. if (typeof(Object).IsAssignableFrom(typeof(T)))
  21. {
  22. return (T)(object)EditorGUI.ObjectField(
  23. area, label, value as Object, typeof(T), true);
  24. }
  25. var stateName = value != null ? value.ToString() : "Null";
  26. EditorGUI.LabelField(area, label, stateName);
  27. return value;
  28. }
  29. /************************************************************************************************************************/
  30. /// <summary>
  31. /// If the <see cref="Rect.height"/> is positive, this method moves the <see cref="Rect.y"/> by that amount and
  32. /// adds the <see cref="EditorGUIUtility.standardVerticalSpacing"/>.
  33. /// </summary>
  34. public static void NextVerticalArea(ref Rect area)
  35. {
  36. if (area.height > 0)
  37. area.y += area.height + EditorGUIUtility.standardVerticalSpacing;
  38. }
  39. /************************************************************************************************************************/
  40. }
  41. }
  42. #endif