Ejemplo n.º 1
0
        private static void DrawAddStateButtons(AnimationPlayer animationPlayer, PersistedInt selectedState, AnimationPlayerEditor editor, AnimationLayer layer)
        {
            if (GUILayout.Button("Single Clip State", buttonWidth))
            {
                EditorUtilities.RecordUndo(animationPlayer, "Add state to animation player");
                layer.states.Add(SingleClipState.Create(GetUniqueStateName(SingleClipState.DefaultName, layer.states)));
                selectedState.SetTo(layer.states.Count - 1);
                editor.MarkDirty();
            }

            if (GUILayout.Button("1D Blend Tree", buttonWidth))
            {
                EditorUtilities.RecordUndo(animationPlayer, "Add blend tree to animation player");
                layer.states.Add(BlendTree1D.Create(GetUniqueStateName(BlendTree1D.DefaultName, layer.states)));
                selectedState.SetTo(layer.states.Count - 1);
                editor.MarkDirty();
            }

            if (GUILayout.Button("2D Blend Tree", buttonWidth))
            {
                EditorUtilities.RecordUndo(animationPlayer, "Add 2D blend tree to animation player");
                layer.states.Add(BlendTree2D.Create(GetUniqueStateName(BlendTree2D.DefaultName, layer.states)));
                selectedState.SetTo(layer.states.Count - 1);
                editor.MarkDirty();
            }
        }
Ejemplo n.º 2
0
        public static SingleClipState Create(string name, AnimationClip clip = null)
        {
            var state = new SingleClipState();

            state.Initialize(name, DefaultName);
            state.clip = clip;
            return(state);
        }
Ejemplo n.º 3
0
        private static void DoDragAndDrop(AnimationPlayer animationPlayer, PersistedInt selectedLayer, PersistedInt selectedState, AnimationPlayerEditor editor)
        {
            var   dragAndDropRect = EditorUtilities.ReserveRect(GUILayout.Height(62f));
            Event evt             = Event.current;

            GUI.Box(dragAndDropRect, "Drag clips here to add\nthem to the player!", dragAndDropBoxStyle);

            switch (evt.type)
            {
            case EventType.DragUpdated:
            case EventType.DragPerform:
                if (!dragAndDropRect.Contains(evt.mousePosition))
                {
                    return;
                }

                DragAndDrop.visualMode = DragAndDropVisualMode.Copy;

                if (evt.type == EventType.DragPerform)
                {
                    DragAndDrop.AcceptDrag();

                    var animationClips = DragAndDrop.objectReferences.FilterByType <AnimationClip>().ToList();
                    foreach (var obj in DragAndDrop.objectReferences.FilterByType <GameObject>())
                    {
                        var assetPath = AssetDatabase.GetAssetPath(obj);
                        if (!(AssetImporter.GetAtPath(assetPath) is ModelImporter))
                        {
                            return;
                        }

                        animationClips.AddRange(AssetDatabase.LoadAllAssetsAtPath(assetPath).FilterByType <AnimationClip>().
                                                Where(clip => (clip.hideFlags & HideFlags.HideInHierarchy) == 0));
                    }

                    if (animationClips.Count > 0)
                    {
                        EditorUtilities.RecordUndo(animationPlayer, "Added clip to Animation Player");
                        var layer          = animationPlayer.layers[selectedLayer];
                        int numClipsBefore = layer.states.Count;

                        foreach (var clip in animationClips)
                        {
                            var newStateName = GetUniqueStateName(clip.name, layer.states);
                            var newState     = SingleClipState.Create(newStateName, clip);
                            layer.states.Add(newState);
                        }

                        selectedState.SetTo(numClipsBefore);

                        editor.MarkDirty();
                    }
                }

                break;
            }
        }
Ejemplo n.º 4
0
        private static void DrawSingleClipState(SingleClipState state, ref bool markDirty, float labelWidth)
        {
            var oldClip = state.clip;

            state.clip = EditorUtilities.ObjectField("Clip", state.clip, labelWidth);
            if (state.clip != oldClip)
            {
                state.OnClipAssigned(state.clip);
                markDirty = true;
            }
        }
        private static void AddClipsAsSeperateStates(AnimationPlayer animationPlayer, PersistedInt selectedLayer, PersistedInt selectedState,
                                                     AnimationPlayerEditor editor, List <AnimationClip> animationClips)
        {
            EditorUtilities.RecordUndo(animationPlayer, "Added clip to Animation Player");
            var layer          = animationPlayer.layers[selectedLayer];
            int numClipsBefore = layer.states.Count;

            foreach (var clip in animationClips)
            {
                var newStateName = GetUniqueStateName(clip.name, layer.states);
                var newState     = SingleClipState.Create(newStateName, clip);
                layer.states.Add(newState);
            }

            selectedState.SetTo(numClipsBefore);

            editor.MarkDirty();
        }