LabelGUI.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Animancer // https://kybernetik.com.au/animancer // Copyright 2018-2024 Kybernetik //
  2. #if UNITY_EDITOR
  3. using System;
  4. using UnityEditor;
  5. namespace Animancer.Editor
  6. {
  7. /// <summary>[Editor-Only]
  8. /// A default <see cref="ICustomGUI"/> which simply draws the <see cref="object.ToString"/>.
  9. /// </summary>
  10. /// https://kybernetik.com.au/animancer/api/Animancer.Editor/LabelGUI
  11. [CustomGUI(typeof(object))]
  12. public class LabelGUI : CustomGUI<object>
  13. {
  14. /************************************************************************************************************************/
  15. /// <inheritdoc/>
  16. public override void DoGUI()
  17. {
  18. string text;
  19. try
  20. {
  21. text = Value != null
  22. ? Value.ToString()
  23. : "Null";
  24. }
  25. catch (Exception exception)
  26. {
  27. text = exception.ToString();
  28. }
  29. using (var value = PooledGUIContent.Acquire(text))
  30. EditorGUILayout.LabelField(Label, value);
  31. }
  32. /************************************************************************************************************************/
  33. }
  34. }
  35. #endif