5 using System.Collections.Generic;
11 namespace HKI.Core.Settings.Editor
16 [CustomEditor(typeof(SettingsSystem))]
20 const string warningsEnabledSPName =
"WarningsEnabled";
21 const string useTargetFrameRateSPName =
"UseTargetFrameRate";
22 static readonly
string[] serializedPropertyNames = {
"Resolution",
"Fullscreen",
"RefreshRate",
"Quality",
"FRAVSM",
"AAM",
"TextLanguage",
"AudioLanguage",
"MasterVolume",
"AmbientVolume",
"FxVolume",
"UiFxVolume",
"VoicesVolume" };
23 const string audioMixerSPName =
"AudioMixer";
24 const string filenameSPName =
"ConfigFilename";
25 const string editorPathSPName =
"EditorPath";
27 bool showReferences =
false;
29 SerializedProperty warningsEnabledSP = null;
30 SerializedProperty useTargetFrameRateSP = null;
31 List<SerializedProperty> serializedProperties =
new List<SerializedProperty>();
32 SerializedProperty audioMixerSP = null;
34 SerializedProperty filenameSP = null;
35 SerializedProperty editorPathSP = null;
41 [MenuItem(
"HKI/Core/Subsystems/Settings System")]
44 CreateSettingsSystem();
56 if (!
string.IsNullOrEmpty(rootFolder))
59 if(
string.IsNullOrEmpty(folder))
61 folder =
EditorHelper.
GetFolderFromUser(
"Select folder for settings system to be saved in",
"The given path for the settings system is null or empty");
62 if (
string.IsNullOrEmpty(folder))
66 EditorUtility.DisplayProgressBar(
"Create settings system",
"Create settings system", 0.0f);
70 SerializedObject settingsSystemSO =
new SerializedObject(settingsSystem);
72 settingsSystemSO.Update();
75 EditorUtility.DisplayProgressBar(
"Create settings system",
"Create default settings for screen", 0.2f);
87 EditorUtility.DisplayProgressBar(
"Create settings system",
"Create default settings for localization", 0.4f);
92 EditorUtility.DisplayProgressBar(
"Create settings system",
"Create default settings for volume", 0.6f);
101 settingsSystemSO.ApplyModifiedProperties();
103 settingsSystemSO.Update();
106 EditorUtility.DisplayProgressBar(
"Create settings system",
"Find audio mixer", 0.8f);
108 SerializedProperty audioMixerSP = settingsSystemSO.FindProperty(audioMixerSPName);
112 if (audioMixer != null)
113 audioMixerSP.objectReferenceValue = audioMixer;
115 Debug.LogError(
"Couldn't find a audio mixer! Please add it manually.");
117 settingsSystemSO.FindProperty(editorPathSPName).stringValue = Application.dataPath +
"/";
119 settingsSystemSO.ApplyModifiedProperties();
121 EditorUtility.DisplayProgressBar(
"Create settings system",
"Get references to settings variables", 0.8f);
123 MethodInfo getReferencesMethod = typeof(
SettingsSystem).GetMethod(
"GetReferences", BindingFlags.NonPublic | BindingFlags.Instance);
124 getReferencesMethod.Invoke(settingsSystem, null);
128 settingsSystemSO.ApplyModifiedProperties();
130 EditorUtility.DisplayProgressBar(
"Create settings system",
"Done", 1.0f);
132 Selection.activeObject = settingsSystem;
134 EditorUtility.ClearProgressBar();
140 for (
int i = 0; i < serializedPropertyNames.Length; i++)
141 serializedProperties.Add(serializedObject.FindProperty(serializedPropertyNames[i]));
143 warningsEnabledSP = serializedObject.FindProperty(warningsEnabledSPName);
144 useTargetFrameRateSP = serializedObject.FindProperty(useTargetFrameRateSPName);
146 filenameSP = serializedObject.FindProperty(filenameSPName);
147 editorPathSP = serializedObject.FindProperty(editorPathSPName);
149 audioMixerSP = serializedObject.FindProperty(audioMixerSPName);
158 serializedObject.Update();
160 EditorGUILayout.LabelField(
"References", EditorStyles.boldLabel);
162 showReferences = EditorGUILayout.Foldout(showReferences,
"References");
165 if(GUILayout.Button(
"Get References to standard settings."))
167 MethodInfo getReferencesMethod = typeof(
SettingsSystem).GetMethod(
"GetReferences", BindingFlags.NonPublic | BindingFlags.Instance);
168 getReferencesMethod.Invoke(target, null);
171 for(
int i = 0; i < serializedProperties.Count; i++)
172 EditorGUILayout.PropertyField(serializedProperties[i]);
174 EditorGUILayout.Space();
176 EditorGUILayout.PropertyField(audioMixerSP);
179 EditorGUILayout.Space();
181 EditorGUILayout.LabelField(
"Settings system settings", EditorStyles.boldLabel);
183 EditorGUILayout.PropertyField(warningsEnabledSP);
184 EditorGUILayout.PropertyField(useTargetFrameRateSP);
186 EditorGUILayout.Space();
188 EditorGUILayout.LabelField(
"Paths and filename", EditorStyles.boldLabel);
190 EditorGUILayout.PropertyField(filenameSP);
192 EditorGUILayout.BeginHorizontal();
193 EditorGUILayout.PropertyField(editorPathSP);
194 if(GUILayout.Button(
"Change", GUILayout.Width(60.0f)))
196 string newEditorPath =
"";
198 if(!newEditorPath.EndsWith(
"/") && !newEditorPath.EndsWith(
"\\"))
199 newEditorPath +=
"/";
201 editorPathSP.stringValue = newEditorPath;
203 EditorGUILayout.EndHorizontal();
206 EditorGUILayout.TextField(
"Runtime Path", Application.persistentDataPath +
"/");
209 EditorGUILayout.Space();
213 EditorGUILayout.Space();
217 serializedObject.ApplyModifiedProperties();
static void AddScriptableObjectToInitializer(ScriptableObject obj)
This function adds a scriptable object as a subasset to the initializer asset.
static bool FindAndSelectIfExists(string filter, string fileEnding=".asset")
Special Variable enables the use of the AntiAliasingModes data type as a variable of the settings sys...
This system loades, saves and stores settings. In addition to that it sets settings in the engine for...
This is a data type that combines a int width and a int height value into one value. This can be used for storing resolution information.
static void CreateSettingsSystem(string rootFolder=null)
This class containes helper functions for editor scripts.
This class extends the Unity ReorderableList with features so it can be used by HKIVar. HKIVars are longer than one line so the height of each ReorderableList element must be adjusted accordingly.
static string GetFolderFromUser(string panelText, string errorMsg)
static void CreateSettingsSystemMenu()
Custom inspector for the Container class. The code is split into two subclasses for better readabilit...
AntiAliasingModes
All possible settings for anti aliasing.
Special Variable enables the use of the FrameRateAndVSyncModes data type as a variable of the setting...
Special Variable enables the use of the SystemLanguage data type as a variable of the settings system...
override void OnInspectorGUI()
Implementation of a boolean value as a HKIVar via HKIVarGeneric.
This class contains the creation function of the menu for all HKI Core systems.
Custom inspector for the SettingsSystem class.
Implementation of a integer value as a HKIVar via HKIVarGeneric.
static Object FindAndLoad(string objectType, string fileEnding=".asset")
Implementation of a string value as a HKIVar via HKIVarGeneric.
FrameRateAndVSyncModes
All possible settings for frame rate and VSync.
Implementation of a IntegerWidthHeight value as a HKIVar via HKIVarGeneric.
Implementation of a min max float value as a HKIVar via HKIVarGenericMinMax.
void SetWidthAndHeight(int width, int height)