From a768fe69180baed99abbeb65186d3b2052dd0ff6 Mon Sep 17 00:00:00 2001 From: Le Duc Anh Date: Mon, 20 Oct 2025 14:14:41 +0700 Subject: [PATCH] add all anims in animancer component --- .../GUI/NamedAnimancerComponentEditor.cs | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/Assets/Plugins/Animancer/Internal/Editor/GUI/NamedAnimancerComponentEditor.cs b/Assets/Plugins/Animancer/Internal/Editor/GUI/NamedAnimancerComponentEditor.cs index 468ec995aa..b9110b6346 100644 --- a/Assets/Plugins/Animancer/Internal/Editor/GUI/NamedAnimancerComponentEditor.cs +++ b/Assets/Plugins/Animancer/Internal/Editor/GUI/NamedAnimancerComponentEditor.cs @@ -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(); + 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(); + var combined = new List(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); + } + /************************************************************************************************************************/ } }