3 using System.Collections.Generic;
 
    9     [CanEditMultipleObjects]
 
   10     [CustomEditor(typeof(SimpleAnimationsManager))]
 
   11     public class SimpleAnimationsManagerInspector : UnityEditor.Editor
 
   13         private Type[] implementations;
 
   14         private int selectedImplementationIndex;
 
   15         private SimpleAnimationsManager simpleAnimationsManager;
 
   18         public override void OnInspectorGUI()
 
   22             serializedObject.Update ();
 
   28             simpleAnimationsManager = target as SimpleAnimationsManager;
 
   29             if (simpleAnimationsManager == 
null) { 
return; }
 
   32             if (implementations == 
null)
 
   33                 implementations = Utils.GetTypeImplementationsNotUnityObject<ISimpleAnimation>();
 
   35             EditorGUILayout.Space();
 
   38             selectedImplementationIndex = EditorGUILayout.Popup(
new GUIContent(
"Animation type"),
 
   39                 selectedImplementationIndex, implementations.Select(impl => impl.Name).ToArray());
 
   41             ISimpleAnimation newAnimation = 
null;
 
   42             if (GUILayout.Button(
"Create animation"))
 
   45                 newAnimation = (ISimpleAnimation) Activator.CreateInstance(implementations[selectedImplementationIndex]);
 
   49             if (newAnimation != 
null)
 
   52                 Undo.RegisterCompleteObjectUndo(target, 
"Added new animation");
 
   54                 if (simpleAnimationsManager.animations == 
null)
 
   55                     simpleAnimationsManager.animations = 
new List<ISimpleAnimation>();
 
   56                 simpleAnimationsManager.animations.Add(newAnimation);
 
   60             EditorGUILayout.Space(); EditorGUILayout.LabelField(
"", GUI.skin.horizontalSlider); EditorGUILayout.Space();
 
   62             if (simpleAnimationsManager.animations != 
null)
 
   64                 for (
int a = 0; a < simpleAnimationsManager.animations.Count; a++)
 
   66                     if (simpleAnimationsManager.animations[a] == 
null)
 
   67                         EditorGUILayout.HelpBox(
"The animation with index " + a + 
" is null.\nRecommended to delete the array element by right clicking on it.", MessageType.Warning);
 
   69                     if (simpleAnimationsManager.animations.Count() != simpleAnimationsManager.animations.Distinct().Count())
 
   71                         for (
int d = a+1; d < simpleAnimationsManager.animations.Count; d++)
 
   73                             if (simpleAnimationsManager.animations[a] != 
null && (simpleAnimationsManager.animations[a] == simpleAnimationsManager.animations[d]) )
 
   74                                 EditorGUILayout.HelpBox(
"The animations with index " + a + 
" and " + d + 
" are the same object.", MessageType.Warning);
 
   80             EditorGUI.indentLevel += 1;
 
   81             EditorGUILayout.Space(); 
 
   82             GUILayout.Label(
"Animations Configuration", EditorStyles.boldLabel);
 
   83             ShowAnimationsArray(serializedObject.FindProperty(
"animations"));
 
   85             EditorGUI.indentLevel -= 1;
 
   88             EditorGUILayout.Space(); EditorGUILayout.Space();  
 
   89             EditorGUILayout.LabelField(
"", GUI.skin.horizontalSlider); 
 
   92             EditorGUILayout.BeginHorizontal();
 
   93             if (implementations != 
null) EditorGUILayout.LabelField($
"Found {implementations.Count()} implementations", EditorStyles.helpBox);
 
   94             if (implementations == 
null || GUILayout.Button(
"Search implementations"))
 
   97                 implementations = Utils.GetTypeImplementationsNotUnityObject<ISimpleAnimation>();
 
   99             EditorGUILayout.EndHorizontal();
 
  105             serializedObject.ApplyModifiedProperties ();
 
  112         private void ShowAnimationsArray(UnityEditor.SerializedProperty list)
 
  114             UnityEditor.EditorGUI.indentLevel += 1;
 
  115             for (
int i = 0; i < list.arraySize; i++)
 
  117                 EditorGUILayout.Space();
 
  118                 using (
new GUILayout.VerticalScope(EditorStyles.helpBox))
 
  120                     SerializedProperty transformProp = list.GetArrayElementAtIndex(i);
 
  122                     SimpleAnimation animation = ((SimpleAnimation) simpleAnimationsManager.animations[i]);
 
  125                     if (animation.name.IsNullOrEmpty())
 
  126                         itemName = $
"Animation [{i}]";
 
  128                         itemName = $
"'{animation.name}' animation [{i}]";
 
  136                     EditorGUILayout.PropertyField(transformProp, 
new GUIContent(itemName), 
true);
 
  138                     DisplayPreview(animation);
 
  140                     EditorGUILayout.Space();
 
  142                 EditorGUILayout.Space();
 
  145             UnityEditor.EditorGUI.indentLevel -= 1;
 
  147         private void DisplayPreview(SimpleAnimation animation)
 
  150             UnityEngine.Object animatedObject = animation.GetAnimatedObject(
false);
 
  151             if (animatedObject == 
null)
 
  153             int oldIndentLevel = UnityEditor.EditorGUI.indentLevel;
 
  154             UnityEditor.EditorGUI.indentLevel = 1;
 
  155             EditorGUILayout.BeginHorizontal();
 
  156             float oldLabelWidth = EditorGUIUtility.labelWidth;
 
  157             EditorGUIUtility.labelWidth = 75;
 
  158             EditorGUILayout.LabelField(
"Animation preview");
 
  159             EditorGUIUtility.labelWidth = oldLabelWidth;
 
  160             EditorGUI.BeginChangeCheck();
 
  161             float animProgression = animation.progress;
 
  164             animProgression = EditorGUILayout.Slider(animProgression, 0f, 1f);
 
  165             if (EditorGUI.EndChangeCheck())
 
  167                 if (animatedObject != 
null)
 
  169                     Undo.RecordObject(animatedObject, 
"Changed animation progress (Animated Object)");
 
  171                 Undo.RecordObject(simpleAnimationsManager, 
"Changed animation progress (Simple Animation Manager)");
 
  172                 animation.SetProgress(animProgression);
 
  174             EditorGUILayout.EndHorizontal();
 
  175             UnityEditor.EditorGUI.indentLevel = oldIndentLevel;