HybridAnimancerComponentEditor.cs 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // Animancer // https://kybernetik.com.au/animancer // Copyright 2018-2024 Kybernetik //
  2. #if UNITY_EDITOR
  3. using System.Collections.Generic;
  4. using UnityEditor;
  5. using UnityEditorInternal;
  6. using UnityEngine;
  7. using Object = UnityEngine.Object;
  8. namespace Animancer.Editor
  9. {
  10. /// <summary>[Editor-Only] A custom Inspector for <see cref="HybridAnimancerComponentEditor"/>s.</summary>
  11. /// https://kybernetik.com.au/animancer/api/Animancer.Editor/HybridAnimancerComponentEditor
  12. ///
  13. [CustomEditor(typeof(HybridAnimancerComponent), true), CanEditMultipleObjects]
  14. public class HybridAnimancerComponentEditor : NamedAnimancerComponentEditor
  15. {
  16. /************************************************************************************************************************/
  17. /// <inheritdoc/>
  18. protected override bool DoOverridePropertyGUI(string path, SerializedProperty property, GUIContent label)
  19. {
  20. switch (path)
  21. {
  22. case "_Controller":
  23. EditorGUILayout.PropertyField(property, label, true);
  24. property = property.FindPropertyRelative("_Controller");
  25. var hasAnimatorController = property?.objectReferenceValue != null;
  26. var warning = GetAnimatorControllerWarning(hasAnimatorController, out var messageType);
  27. if (warning is not null)
  28. {
  29. EditorGUILayout.HelpBox(warning, messageType);
  30. if (AnimancerGUI.TryUseClickEventInLastRect())
  31. Application.OpenURL(Strings.DocsURLs.AnimatorControllers);
  32. }
  33. return true;
  34. }
  35. return base.DoOverridePropertyGUI(path, property, label);
  36. }
  37. /************************************************************************************************************************/
  38. private string GetAnimatorControllerWarning(bool hasAnimatorController, out MessageType messageType)
  39. {
  40. if (!hasAnimatorController)
  41. {
  42. messageType = MessageType.Warning;
  43. return
  44. $"No Animator Controller is assigned to this component so" +
  45. $" you should likely use a base {nameof(AnimancerComponent)} instead." +
  46. $" Click here for more information.";
  47. }
  48. messageType = MessageType.Info;
  49. if (Targets.Length > 0)
  50. {
  51. var animator = Targets[0].Animator;
  52. if (animator != null && animator.runtimeAnimatorController != null)
  53. {
  54. return
  55. $"A Native Animator Controller is assigned to the Animator component" +
  56. $" and a Hybrid Animator Controller is also assigned to this component." +
  57. $" That's not necessarily a problem, but using both systems at the same time is very unusual." +
  58. $" Click here for more information.";
  59. }
  60. }
  61. return null;
  62. }
  63. /************************************************************************************************************************/
  64. }
  65. }
  66. #endif