using System.Collections; using System.Collections.Generic; using System.IO; using UnityEditor; using UnityEngine; namespace YKMoonEditor { public partial class YKAnimatorPresetSettingProvider { [SettingsProvider] public static SettingsProvider CreateProvider() { // First parameter is the path in the Settings window. // Second parameter is the scope of this setting: it only appears in the Project Settings window. var provider = new SettingsProvider("Project/YKAnimatorPresetSetting", SettingsScope.Project) { // By default the last token of the path is used as display name if no label is provided. label = "YKMoon AnimatorPreset", // Create the SettingsProvider and initialize its drawing (IMGUI) function in place: guiHandler = (searchContext) => { var settings = YKAnimatorPresetSettingManager.GetSettings(); if(settings == null) { EditorGUILayout.HelpBox(string.Format("Animator Preset工具需要{0}配置文件,\n" + "配置文件不存在,是否创建?", YKAnimatorPresetSettingManager.configPath), MessageType.Error); if(GUILayout.Button("创建配置文件")) { settings = YKAnimatorPresetSettingManager.CreateSettings(); } } else { SerializedObject serializedObject = new SerializedObject(settings); var m_styles = serializedObject.FindProperty("styles"); if(settings.styles.Count <= 0) { EditorGUILayout.HelpBox("至少需要一个Style", MessageType.Error); } EditorGUILayout.PropertyField(m_styles, new GUIContent("Styles")); if(GUILayout.Button("Create New Style")) { var style = CreateStyle(); if(style != null) { settings.styles.Add(style); AssetDatabase.Refresh(); } } serializedObject.ApplyModifiedPropertiesWithoutUndo(); } }, // Populate the search keywords to enable smart search filtering and label highlighting: keywords = new HashSet(new[] { "YKAnimatorPreset Templete Path", "YKAnimatorPreset Templete FileName", }) }; return provider; } private static YKAnimatorPresetSettingStyle CreateStyle() { var path = EditorUtility.SaveFilePanel("Save File", Application.dataPath, "NewAnimatorStyle", "asset"); if(string.IsNullOrEmpty(path)) { return null; } if(!path.Contains(Application.dataPath)) { Debug.LogError("Must in Project path"); EditorUtility.DisplayDialog( "Save File", "Must in Project path!", "Ok"); return null; } if(path.Length != 0) { var newStyle = ScriptableObject.CreateInstance(); path = path.Replace(Application.dataPath + "/", "Assets/"); Debug.LogFormat("Save:{0}", path); AssetDatabase.CreateAsset(newStyle, path); var controller = YKAnimatorEditorUtility.CreateUIController(path); newStyle.controllerPreset = controller; AssetDatabase.ImportAsset(path); return newStyle; } return null; } } }