forked from zxl/LaboratoryProtection
41 lines
1.2 KiB
C#
41 lines
1.2 KiB
C#
using System.Collections.Generic;
|
|
using Sirenix.OdinInspector;
|
|
using UnityEditor;
|
|
using UnityEngine;
|
|
|
|
namespace UnityTest.ZXL
|
|
{
|
|
public class AnimatorManager : BaseAutoMono<AnimatorManager>
|
|
{
|
|
public Dictionary<string, List<Animator>> dictionary = new Dictionary<string, List<Animator>>();
|
|
|
|
public List<Animator> Get(string aniName)
|
|
{
|
|
dictionary.TryGetValue(aniName, out List<Animator> list);
|
|
return list;
|
|
}
|
|
|
|
|
|
#if UNITY_EDITOR
|
|
[Button("Add")]
|
|
void AutoAdd()
|
|
{
|
|
var activeObject = Selection.activeObject as GameObject;
|
|
var animators = activeObject.GetComponentAllChild<Animator>();
|
|
foreach (var animator in animators)
|
|
{
|
|
var animatorName = animator.name;
|
|
if (animator.transform.parent != null)
|
|
{
|
|
animatorName = animator.transform.parent.name;
|
|
}
|
|
|
|
if (dictionary.ContainsKey(animatorName))
|
|
dictionary[animatorName].Add(animator);
|
|
else
|
|
dictionary.Add(animatorName, new List<Animator>() {animator});
|
|
}
|
|
}
|
|
#endif
|
|
}
|
|
} |