add all anims in animancer component
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
#if UNITY_EDITOR
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEditor;
|
||||
using UnityEditorInternal;
|
||||
using UnityEngine;
|
||||
@@ -36,6 +37,12 @@ namespace Animancer.Editor
|
||||
{
|
||||
DoAnimationsField(property);
|
||||
}
|
||||
|
||||
EditorGUILayout.Space();
|
||||
if (GUILayout.Button("AddAllAnimationClips"))
|
||||
{
|
||||
AddAllAnimationClips();
|
||||
}
|
||||
return true;
|
||||
|
||||
default:
|
||||
@@ -248,6 +255,48 @@ namespace Animancer.Editor
|
||||
}
|
||||
|
||||
/************************************************************************************************************************/
|
||||
|
||||
private void AddAllAnimationClips()
|
||||
{
|
||||
var component = (NamedAnimancerComponent)target;
|
||||
var animator = component.GetComponent<Animator>();
|
||||
if (animator == null)
|
||||
{
|
||||
EditorUtility.DisplayDialog("NamedAnimancerComponent", "No Animator found on the same GameObject.", "OK");
|
||||
return;
|
||||
}
|
||||
|
||||
var controller = animator.runtimeAnimatorController;
|
||||
if (controller == null)
|
||||
{
|
||||
EditorUtility.DisplayDialog("NamedAnimancerComponent", "Animator has no RuntimeAnimatorController.", "OK");
|
||||
return;
|
||||
}
|
||||
|
||||
var clipsFromAnimator = controller.animationClips;
|
||||
if (clipsFromAnimator == null || clipsFromAnimator.Length == 0)
|
||||
{
|
||||
EditorUtility.DisplayDialog("NamedAnimancerComponent", "No AnimationClips found in the Animator.", "OK");
|
||||
return;
|
||||
}
|
||||
|
||||
var currentClips = component.Animations ?? System.Array.Empty<AnimationClip>();
|
||||
var combined = new List<AnimationClip>(currentClips.Length + clipsFromAnimator.Length);
|
||||
combined.AddRange(currentClips.Where(c => c != null));
|
||||
|
||||
foreach (var clip in clipsFromAnimator)
|
||||
{
|
||||
if (clip == null)
|
||||
continue;
|
||||
if (!combined.Contains(clip))
|
||||
combined.Add(clip);
|
||||
}
|
||||
|
||||
Undo.RecordObject(component, "Add All Animation Clips");
|
||||
component.Animations = combined.ToArray();
|
||||
EditorUtility.SetDirty(component);
|
||||
}
|
||||
/************************************************************************************************************************/
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user