ScriptableObjectEditor.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // Animancer // https://kybernetik.com.au/animancer // Copyright 2018-2024 Kybernetik //
  2. // Uncomment this #define to apply this custom editor to all ScriptableObjects.
  3. // If you have another plugin with a custom ScriptableObject editor, you will probably want that one instead.
  4. //#define ANIMANCER_SCRIPTABLE_OBJECT_EDITOR
  5. #if UNITY_EDITOR
  6. using UnityEditor;
  7. using UnityEngine;
  8. namespace Animancer.Editor
  9. {
  10. /// <summary>[Editor-Only]
  11. /// A custom Inspector for <see cref="ScriptableObject"/>s which adds a message explaining that changes in play
  12. /// mode will persist.
  13. /// </summary>
  14. /// https://kybernetik.com.au/animancer/api/Animancer.Editor/ScriptableObjectEditor
  15. ///
  16. #if ANIMANCER_SCRIPTABLE_OBJECT_EDITOR
  17. [CustomEditor(typeof(ScriptableObject), true, isFallback = true), CanEditMultipleObjects]
  18. #endif
  19. public class ScriptableObjectEditor : UnityEditor.Editor
  20. {
  21. /************************************************************************************************************************/
  22. /// <summary>Draws the regular Inspector then adds a message explaining that changes in Play Mode will persist.</summary>
  23. /// <remarks>Called by the Unity editor to draw the custom Inspector GUI elements.</remarks>
  24. public override void OnInspectorGUI()
  25. {
  26. base.OnInspectorGUI();
  27. if (target != null &&
  28. EditorApplication.isPlayingOrWillChangePlaymode &&
  29. EditorUtility.IsPersistent(target))
  30. {
  31. EditorGUILayout.HelpBox("This is an asset, not a scene object," +
  32. " which means that any changes you make to it are permanent" +
  33. " and will NOT be undone when you exit Play Mode.", MessageType.Warning);
  34. }
  35. }
  36. /************************************************************************************************************************/
  37. }
  38. }
  39. #endif