HKI Core
SceneLoaderEditor.cs
Go to the documentation of this file.
1 using UnityEngine;
2 using UnityEditor;
3 using HKI.Core.Loc;
4 using HKI.Core.Editor.Misc;
5 
6 namespace HKI.Core.Scenes.Editor
7 {
11  [CustomEditor(typeof(SceneLoader))]
12  public class SceneLoaderEditor : UnityEditor.Editor
13  {
14  // Private variables
15  const string loadingSceneSPName = "LoadingScene";
16  const string sceneLoaderControllerPrefabSPName = "SceneLoaderControllerPrefab";
17  const string textLanguageSPName = "TextLanguage";
18  const string doFadingSPName = "DoFading";
19  const string fadeInTimeSPName = "FadeInTime";
20  const string fadeOutTimeSPName = "FadeOutTime";
21 
22  SerializedProperty loadingSceneSP = null;
23  SerializedProperty sceneLoaderControllerPrefabSP = null;
24  SerializedProperty textLanguageSP = null;
25  SerializedProperty doFadingSP = null;
26  SerializedProperty fadeInTimeSP = null;
27  SerializedProperty fadeOutTimeSP = null;
28 
29  // Create function
30  [MenuItem("HKI/Core/Subsystems/Scene Loader")]
31  static void CreateSceneLoaderMenu()
32  {
33  CreateSceneLoader();
34  }
35 
36  public static void CreateSceneLoader(string rootFolder = null)
37  {
38  // Find and select the settings system if it exists
40  return;
41 
42  // Create a new setting system
43  string folder = null;
44 
45  if (!string.IsNullOrEmpty(rootFolder))
46  folder = rootFolder;
47 
48  if (string.IsNullOrEmpty(folder))
49  {
50  folder = EditorHelper.GetFolderFromUser("Select folder for the scene loader to be saved in", "The given path for the scene loader is null or empty");
51  if (string.IsNullOrEmpty(folder))
52  return;
53  }
54 
55  EditorUtility.DisplayProgressBar("Create scene loader", "Create scene loader", 0.0f);
56 
57  SceneLoader sceneLoader = EditorHelper.CreateAsset<SceneLoader>("Scene Loader", folder);
58 
59  SerializedObject sceneLoaderSO = new SerializedObject(sceneLoader);
60 
61  sceneLoaderSO.Update();
62 
63  sceneLoaderSO.FindProperty(textLanguageSPName).objectReferenceValue = FindAudioLanguage();
64 
65  sceneLoaderSO.ApplyModifiedProperties();
66 
68 
69  EditorUtility.DisplayProgressBar("Create scene loader", "Done", 1.0f);
70 
71  Selection.activeObject = sceneLoader;
72 
73  EditorUtility.ClearProgressBar();
74  }
75 
76  // OnEnable function
77  void OnEnable()
78  {
79  loadingSceneSP = serializedObject.FindProperty(loadingSceneSPName);
80  sceneLoaderControllerPrefabSP = serializedObject.FindProperty(sceneLoaderControllerPrefabSPName);
81  textLanguageSP = serializedObject.FindProperty(textLanguageSPName);
82  doFadingSP = serializedObject.FindProperty(doFadingSPName);
83  fadeInTimeSP = serializedObject.FindProperty(fadeInTimeSPName);
84  fadeOutTimeSP = serializedObject.FindProperty(fadeOutTimeSPName);
85  }
86 
87  // OnInspectorGUI function
88  public override void OnInspectorGUI()
89  {
90  serializedObject.Update();
91 
92  EditorGUILayout.LabelField("General settings", EditorStyles.boldLabel);
93 
94  EditorGUILayout.PropertyField(loadingSceneSP);
95  EditorGUILayout.PropertyField(sceneLoaderControllerPrefabSP);
96 
97  EditorGUILayout.LabelField("Language settings", EditorStyles.boldLabel);
98 
99  EditorGUILayout.PropertyField(textLanguageSP);
100 
101  EditorGUILayout.LabelField("Fading settings", EditorStyles.boldLabel);
102 
103  EditorGUILayout.PropertyField(doFadingSP);
104  EditorGUILayout.PropertyField(fadeInTimeSP);
105  EditorGUILayout.PropertyField(fadeOutTimeSP);
106 
107  serializedObject.ApplyModifiedProperties();
108  }
109  // Helper function
111  {
112  string[] GUIDs = AssetDatabase.FindAssets("t:" + typeof(Language).Name);
113  if (GUIDs.Length > 0)
114  {
115  for (int i = 0; i < GUIDs.Length; i++)
116  {
117  string assetPath = AssetDatabase.GUIDToAssetPath(GUIDs[i]);
118  Object[] objs = AssetDatabase.LoadAllAssetsAtPath(assetPath);
119  string filename = "Text Language";
120  foreach (Object obj in objs)
121  {
122  if (obj.name == filename)
123  return (Language)obj;
124  }
125  }
126  }
127 
128  return null;
129  }
130  }
131 }
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")
Definition: EditorHelper.cs:13
static void CreateSceneLoader(string rootFolder=null)
This class containes helper functions for editor scripts.
Definition: EditorHelper.cs:10
static string GetFolderFromUser(string panelText, string errorMsg)
Definition: EditorHelper.cs:32
This ScriptableObject spawns the SceneLoaderController prefab and gives access to the SceneLoaderCont...
Definition: SceneLoader.cs:10
Custom inspector for the SceneLoader class.
Special Variable enables the use of the SystemLanguage data type as a variable of the settings system...
Definition: Language.cs:13
This class contains the creation function of the menu for all HKI Core systems.