-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAnimatorConstantFieldsGeneratorSettings.cs
67 lines (58 loc) · 2.82 KB
/
AnimatorConstantFieldsGeneratorSettings.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
namespace BarelyAStudio.AnimatorConstantFieldsGenerator
{
public class AnimatorConstantFieldsGeneratorSettings : ScriptableObject
{
public const string k_MyCustomSettingsPath = "Assets/AnimatorConstantFieldsGeneratorSettings.asset";
public string @namespace = "GeneratedNamespace";
public string fileName = "Assets/AnimatorConstants.cs";
internal static AnimatorConstantFieldsGeneratorSettings GetOrCreateSettings()
{
var settings = AssetDatabase.LoadAssetAtPath<AnimatorConstantFieldsGeneratorSettings>(k_MyCustomSettingsPath);
if (settings == null)
{
settings = CreateInstance<AnimatorConstantFieldsGeneratorSettings>();
settings.@namespace = "GeneratedNamespace";
settings.fileName = "Assets/AnimatorConstants.cs";
AssetDatabase.CreateAsset(settings, k_MyCustomSettingsPath);
AssetDatabase.SaveAssets();
}
return settings;
}
internal static SerializedObject GetSerializedSettings()
{
return new SerializedObject(GetOrCreateSettings());
}
}
// Register a SettingsProvider using IMGUI for the drawing framework:
public static class CustomSettingsIMGUIRegister
{
[SettingsProvider]
public static SettingsProvider CreateMyCustomSettingsProvider()
{
// 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/AnimatorConstantFieldsGeneratorSettings", SettingsScope.Project)
{
// By default the last token of the path is used as display name if no label is provided.
label = "Animator Constant Fields Generator",
// Create the SettingsProvider and initialize its drawing (IMGUI) function in place:
guiHandler = (searchContext) =>
{
var settings = AnimatorConstantFieldsGeneratorSettings.GetSerializedSettings();
EditorGUILayout.PropertyField(settings.FindProperty("namespace"), new GUIContent("Namespace"));
EditorGUILayout.PropertyField(settings.FindProperty("fileName"), new GUIContent("File Name And Location"));
settings.ApplyModifiedPropertiesWithoutUndo();
},
// Populate the search keywords to enable smart search filtering and label highlighting:
keywords = new HashSet<string>(new[]
{
"Animator", "Constants", "Fields"
})
};
return provider;
}
}
}