using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEditor; using UnityEditor.Animations; namespace YKMoonEditor { [System.Serializable] public class YKAnimatorPresetSettingStyle : ScriptableObject { public AnimatorController controllerPreset; } [CustomEditor(typeof(YKAnimatorPresetSettingStyle))] public class YKAnimatorPresetSettingStyleInspector : UEditorBase { SerializedProperty p_controllerPreset; private void OnEnable() { p_controllerPreset = serializedObject.FindProperty("controllerPreset"); } public override void OnInspectorGUI() { serializedObject.Update(); EditorGUILayout.PropertyField(p_controllerPreset); if(p_controllerPreset.objectReferenceValue == null) { if(GUILayout.Button("创建新Animator Controller")) { var path = AssetDatabase.GetAssetPath(target); var controller = YKAnimatorEditorUtility.CreateUIController(path); p_controllerPreset.objectReferenceValue = controller; AssetDatabase.SaveAssets(); AssetDatabase.ImportAsset(path); AssetDatabase.Refresh(); } } DrawFoldoutHeaderGroup("isFoldoutHeaderAnimationSetting", false, new GUIContent("自定义动画"), DrawStates); serializedObject.ApplyModifiedProperties(); } private static Vector2 scrollPosState; private string newStateName = ""; private void DrawStates() { var runtimeAnimatorController = p_controllerPreset.objectReferenceValue as AnimatorController; if(runtimeAnimatorController == null) { return; } YKAnimatorEditorUtility.DrawAnimatorCustomStates(runtimeAnimatorController, ref newStateName, ref scrollPosState); } } }