SpriteLibraryInspector.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. using UnityEngine.Experimental.U2D.Animation;
  2. namespace UnityEditor.Experimental.U2D.Animation
  3. {
  4. [CustomEditor(typeof(SpriteLibrary))]
  5. [CanEditMultipleObjects]
  6. internal class SpriteLibraryInspector : Editor
  7. {
  8. private SerializedProperty m_SpriteLib;
  9. public void OnEnable()
  10. {
  11. m_SpriteLib = serializedObject.FindProperty("m_SpriteLibraryAsset");
  12. }
  13. public override void OnInspectorGUI()
  14. {
  15. serializedObject.Update();
  16. EditorGUI.BeginChangeCheck();
  17. EditorGUILayout.PropertyField(m_SpriteLib);
  18. if (EditorGUI.EndChangeCheck())
  19. {
  20. serializedObject.ApplyModifiedProperties();
  21. foreach (var t in targets)
  22. {
  23. var srs = (t as SpriteLibrary).GetComponentsInChildren<SpriteResolver>();
  24. foreach (var sr in srs)
  25. {
  26. sr.ResolveSpriteToSpriteRenderer();
  27. sr.spriteLibChanged = true;
  28. }
  29. }
  30. }
  31. }
  32. }
  33. }