private static void DrawStateData(AnimationState state, ref bool markDirty)
        {
            const float labelWidth = 55f;

            var old = state.Name;

            state.Name = EditorUtilities.TextField("Name", state.Name, labelWidth);
            if (old != state.Name)
            {
                markDirty = true;
            }

            state.speed = EditorUtilities.DoubleField("Speed", state.speed, labelWidth);

            //@TODO: C# 7 pattern matching
            var type = state.GetType();

            if (type == typeof(SingleClipState))
            {
                DrawSingleClipState((SingleClipState)state, ref markDirty, labelWidth);
            }
            else if (type == typeof(BlendTree1D))
            {
                Draw1DBlendTree((BlendTree1D)state, ref markDirty);
            }

            else if (type == typeof(BlendTree2D))
            {
                Draw2DBlendTree((BlendTree2D)state, ref markDirty);
            }
            else
            {
                EditorGUILayout.LabelField($"Unknown animation state type: {type.Name}");
            }
        }
Example #2
0
        private static void DrawStateData(AnimationState state, ref bool updateStateNames)
        {
            const float labelWidth = 55f;

            var old = state.Name;

            state.Name = EditorUtilities.TextField("Name", state.Name, labelWidth);
            if (old != state.Name)
            {
                updateStateNames = true;
            }

            state.speed = EditorUtilities.DoubleField("Speed", state.speed, labelWidth);

            //@TODO: Use pattern matching when C# 7
            var type = state.GetType();

            if (type == typeof(SingleClipState))
            {
                var singleClipState = (SingleClipState)state;
                var oldClip         = singleClipState.clip;
                singleClipState.clip = EditorUtilities.ObjectField("Clip", singleClipState.clip, labelWidth);
                if (singleClipState.clip != null && singleClipState.clip != oldClip)
                {
                    updateStateNames |= singleClipState.OnClipAssigned(singleClipState.clip);
                }
            }
            else if (type == typeof(BlendTree1D))
            {
                var blendTree = (BlendTree1D)state;
                blendTree.blendVariable = EditorUtilities.TextField("Blend with variable", blendTree.blendVariable, 120f);
                EditorGUI.indentLevel++;
                foreach (var blendTreeEntry in blendTree.blendTree)
                {
                    updateStateNames |= DrawBlendTreeEntry(state, blendTreeEntry, blendTree.blendVariable);
                }

                EditorGUI.indentLevel--;

                GUILayout.Space(10f);
                EditorGUILayout.BeginHorizontal();
                if (GUILayout.Button("Add blend tree entry", GUILayout.Width(150f)))
                {
                    blendTree.blendTree.Add(new BlendTreeEntry1D());
                }
                GUILayout.FlexibleSpace();
                EditorGUILayout.EndHorizontal();
            }

            else if (type == typeof(BlendTree2D))
            {
                var blendTree2D = (BlendTree2D)state;
                blendTree2D.blendVariable  = EditorUtilities.TextField("First blend variable", blendTree2D.blendVariable, 120f);
                blendTree2D.blendVariable2 = EditorUtilities.TextField("Second blend variable", blendTree2D.blendVariable2, 120f);
                EditorGUI.indentLevel++;
                foreach (var blendTreeEntry in blendTree2D.blendTree)
                {
                    updateStateNames |= DrawBlendTreeEntry(state, blendTreeEntry, blendTree2D.blendVariable, blendTree2D.blendVariable2);
                }

                EditorGUI.indentLevel--;

                GUILayout.Space(10f);
                EditorGUILayout.BeginHorizontal();
                if (GUILayout.Button("Add blend tree entry", GUILayout.Width(150f)))
                {
                    blendTree2D.blendTree.Add(new BlendTreeEntry2D());
                }
                GUILayout.FlexibleSpace();
                EditorGUILayout.EndHorizontal();
            }
            else
            {
                EditorGUILayout.LabelField($"Unknown animation state type: {type.Name}");
            }
        }