|
4 | 4 |
|
5 | 5 | //Customizable settings for the importer
|
6 | 6 | namespace Spriter2UnityDX {
|
7 |
| - public class S2USettings : ScriptableObject { |
8 |
| - private const string IMPORT = "import"; |
9 |
| - |
10 |
| - public static AnimationImportOption ImportStyle { |
11 |
| - get { return (AnimationImportOption)EditorPrefs.GetInt (IMPORT); } |
12 |
| - set { EditorPrefs.SetInt (IMPORT, (int)value); } |
13 |
| - } |
14 |
| - |
15 |
| - [MenuItem ("Edit/Project Settings/Spriter2UnityDX")] |
16 |
| - public static void Select () { |
17 |
| - var settings = CreateInstance<S2USettings> (); |
18 |
| - Selection.activeObject = settings; |
| 7 | + internal static class S2USettingsIMGUIRegister |
| 8 | + { |
| 9 | + [SettingsProvider] |
| 10 | + public static SettingsProvider CreateS2USettingsProvider() |
| 11 | + { |
| 12 | + var provider = new SettingsProvider("Project/Spriter2UnityDX", SettingsScope.Project) |
| 13 | + { |
| 14 | + guiHandler = (searchContext) => |
| 15 | + { |
| 16 | + var settings = S2USettings.GetSerializedSettings(); |
| 17 | + var label = new GUIContent("Animation Import Style", |
| 18 | + "By default, animations are nested into the generated prefab. Change this option to instead place animations into a separate folder."); |
| 19 | + EditorGUILayout.PropertyField(settings.FindProperty("importOption"), label); |
| 20 | + settings.ApplyModifiedProperties(); |
| 21 | + }, |
| 22 | + }; |
| 23 | + |
| 24 | + return provider; |
19 | 25 | }
|
20 | 26 | }
|
21 | 27 |
|
22 |
| - public enum AnimationImportOption : byte { NestedInPrefab, SeparateFolder } |
23 |
| - |
24 |
| - [CustomEditor (typeof(S2USettings))] public class SettingsEditor: Editor { |
25 |
| - private AnimationImportOption importStyle; |
26 |
| - |
27 |
| - private void OnEnable () { |
28 |
| - importStyle = S2USettings.ImportStyle; |
29 |
| - } |
30 |
| - |
31 |
| - private void OnDisable () { |
32 |
| - DestroyImmediate (target); |
| 28 | + public class S2USettings : ScriptableObject |
| 29 | + { |
| 30 | + private const string settingsPath = "Assets/Spriter2UnityDX/Editor/Settings.asset"; |
| 31 | + |
| 32 | + [SerializeField] |
| 33 | + private AnimationImportOption importOption; |
| 34 | + |
| 35 | + internal AnimationImportOption ImportOption { get { return importOption; } } |
| 36 | + |
| 37 | + internal static S2USettings GetOrCreateSettings() |
| 38 | + { |
| 39 | + var settings = AssetDatabase.LoadAssetAtPath<S2USettings>(settingsPath); |
| 40 | + if (settings == null) |
| 41 | + { |
| 42 | + settings = ScriptableObject.CreateInstance<S2USettings>(); |
| 43 | + settings.importOption = AnimationImportOption.NestedInPrefab; |
| 44 | + AssetDatabase.CreateAsset(settings, settingsPath); |
| 45 | + AssetDatabase.SaveAssets(); |
| 46 | + } |
| 47 | + return settings; |
33 | 48 | }
|
34 | 49 |
|
35 |
| - public override void OnInspectorGUI () { |
36 |
| - EditorGUI.BeginChangeCheck (); |
37 |
| - var label = new GUIContent ("Animation Import Style", |
38 |
| - "By default, animations are nested into the generated prefab. Change this option to instead place animations into a separate folder."); |
39 |
| - importStyle = (AnimationImportOption)EditorGUILayout.EnumPopup (label, importStyle); |
40 |
| - if (EditorGUI.EndChangeCheck ()) S2USettings.ImportStyle = importStyle; |
| 50 | + internal static SerializedObject GetSerializedSettings() |
| 51 | + { |
| 52 | + return new SerializedObject(GetOrCreateSettings()); |
41 | 53 | }
|
42 | 54 | }
|
| 55 | + |
| 56 | + public enum AnimationImportOption : byte { NestedInPrefab, SeparateFolder } |
43 | 57 | }
|
0 commit comments