1
0
Fork 0
LaboratoryProtection/Assets/UnityTest/ZXL/Scripts/AnimatorManager.cs

41 lines
1.2 KiB
C#
Raw Normal View History

2023-09-12 23:18:01 +08:00
using System.Collections.Generic;
using Sirenix.OdinInspector;
using UnityEditor;
using UnityEngine;
namespace UnityTest.ZXL
{
2023-09-13 15:04:19 +08:00
public class AnimatorManager : BaseAutoMono<AnimatorManager>
2023-09-12 23:18:01 +08:00
{
public Dictionary<string, List<Animator>> dictionary = new Dictionary<string, List<Animator>>();
2023-09-13 15:04:19 +08:00
public List<Animator> Get(string aniName)
{
dictionary.TryGetValue(aniName, out List<Animator> list);
return list;
}
2023-09-13 02:20:37 +08:00
#if UNITY_EDITOR
2023-09-12 23:18:01 +08:00
[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
2023-09-13 15:04:19 +08:00
dictionary.Add(animatorName, new List<Animator>() {animator});
2023-09-12 23:18:01 +08:00
}
}
2023-09-13 02:20:37 +08:00
#endif
2023-09-12 23:18:01 +08:00
}
}