Last active
January 11, 2021 12:10
-
-
Save JonathanMCarter/5a07b69316c57d083feff2944ef39c05 to your computer and use it in GitHub Desktop.
The code the runs the display in the first tab of the Save Data Editor in the Save manager asset. It's purpose is to help the user name a class with savable values.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Shows the Generate class display | |
/// </summary> | |
private void TabOneDisplay() | |
{ | |
EditorGUILayout.HelpBox("Create a new SaveData class here.\n\nYou may just write it yourself, however if you wish " + | |
"for the asset to work with the data you want to save, we advise you use the provided editor to generate it. " + | |
"To begin, press the add field button, and repeat for each field you need. When done, press the Generate Class button.", MessageType.Info, true); | |
GUI.backgroundColor = Color.green; | |
EditorGUILayout.BeginHorizontal(); | |
GUILayout.FlexibleSpace(); | |
if (GUILayout.Button("+ Add Field", GUILayout.Width(90f))) | |
{ | |
if (!isCreatingFile) | |
{ | |
isCreatingFile = true; | |
types = new List<dataTypes>(); | |
shouldArray = new List<bool>(); | |
shouldList = new List<bool>(); | |
valueNames = new List<string>(); | |
classNames = new List<string>(); | |
types.Add(dataTypes.stringValue); | |
shouldArray.Add(false); | |
shouldList.Add(false); | |
valueNames.Add(""); | |
classNames.Add(""); | |
} | |
else | |
{ | |
types.Add(dataTypes.stringValue); | |
shouldArray.Add(false); | |
shouldList.Add(false); | |
valueNames.Add(""); | |
classNames.Add(""); | |
} | |
} | |
GUI.backgroundColor = Color.white; | |
GUILayout.FlexibleSpace(); | |
EditorGUILayout.EndHorizontal(); | |
EditorGUILayout.Space(); | |
/* | |
* | |
* Stuff that displays the fields... | |
* | |
*/ | |
if (isCreatingFile) | |
{ | |
if (types.Count > 0) | |
{ | |
ScrollPos = EditorGUILayout.BeginScrollView(ScrollPos, GUILayout.Width(position.width), GUILayout.ExpandHeight(true)); | |
for (int i = 0; i < types.Count; i++) | |
{ | |
EditorGUILayout.BeginVertical(EditorStyles.helpBox); | |
EditorGUILayout.BeginHorizontal(); | |
EditorGUILayout.LabelField("Data Type", EditorStyles.boldLabel, GUILayout.Width(125f)); | |
EditorGUILayout.LabelField("Variable Name", EditorStyles.boldLabel, GUILayout.MinWidth(100), GUILayout.MaxWidth(300)); | |
if (types[i] == dataTypes.classValue) | |
{ | |
EditorGUILayout.LabelField("Class Name", EditorStyles.boldLabel, GUILayout.MinWidth(100), GUILayout.MaxWidth(300)); | |
} | |
EditorGUILayout.EndHorizontal(); | |
EditorGUILayout.BeginHorizontal(); | |
GUI.backgroundColor = Color.yellow; | |
types[i] = (dataTypes)EditorGUILayout.EnumPopup(types[i], GUILayout.Width(125f)); | |
GUI.backgroundColor = Color.white; | |
valueNames[i] = EditorGUILayout.TextField(valueNames[i], GUILayout.MinWidth(100), GUILayout.MaxWidth(300)); | |
if (types[i] == dataTypes.classValue) | |
{ | |
classNames[i] = EditorGUILayout.TextField(classNames[i], GUILayout.MinWidth(100), GUILayout.MaxWidth(300)); | |
} | |
EditorGUILayout.EndHorizontal(); | |
EditorGUILayout.Space(); | |
EditorGUILayout.BeginHorizontal(); | |
EditorGUILayout.LabelField("Should be an Array of type?", GUILayout.Width(170f)); | |
shouldArray[i] = EditorGUILayout.Toggle(shouldArray[i], GUILayout.Width(38f)); | |
EditorGUILayout.EndHorizontal(); | |
EditorGUILayout.BeginHorizontal(); | |
EditorGUILayout.LabelField("Should be an List of type?", GUILayout.Width(170f)); | |
shouldList[i] = EditorGUILayout.Toggle(shouldList[i], GUILayout.MinWidth(38f), GUILayout.MaxWidth(535)); | |
GUILayout.FlexibleSpace(); | |
GUI.backgroundColor = Color.red; | |
if (GUILayout.Button("- Remove Field", GUILayout.MaxWidth(110f))) | |
{ | |
types.Remove(types[i]); | |
shouldArray.Remove(shouldArray[i]); | |
shouldList.Remove(shouldList[i]); | |
valueNames.Remove(valueNames[i]); | |
classNames.Remove(classNames[i]); | |
} | |
GUI.backgroundColor = Color.white; | |
EditorGUILayout.EndHorizontal(); | |
EditorGUILayout.EndVertical(); | |
EditorGUILayout.Space(); | |
} | |
EditorGUILayout.EndScrollView(); | |
} | |
GUI.backgroundColor = Color.green; | |
EditorGUILayout.BeginHorizontal(); | |
GUILayout.FlexibleSpace(); | |
if (GUILayout.Button("Generate New SaveData Class", GUILayout.MaxWidth(200f))) | |
{ | |
if (Directory.Exists(Application.dataPath + "/Scripts/")) | |
{ | |
if (Directory.Exists(Application.dataPath + "/Scripts/Carter Games/")) | |
{ | |
if (Directory.Exists(Application.dataPath + "/Scripts/Carter Games/Save Manager")) | |
{ | |
GenerateClass(); | |
} | |
else | |
{ | |
AssetDatabase.CreateFolder("Assets/Scripts/Carter Games", "Save Manager"); | |
GenerateClass(); | |
} | |
} | |
else | |
{ | |
AssetDatabase.CreateFolder("Assets/Scripts", "Carter Games"); | |
AssetDatabase.CreateFolder("Assets/Scripts/Carter Games", "Save Manager"); | |
GenerateClass(); | |
} | |
} | |
else | |
{ | |
AssetDatabase.CreateFolder("Assets", "Scripts"); | |
AssetDatabase.CreateFolder("Assets/Scripts", "Carter Games"); | |
AssetDatabase.CreateFolder("Assets/Scripts/Carter Games", "Save Manager"); | |
GenerateClass(); | |
} | |
} | |
GUILayout.FlexibleSpace(); | |
EditorGUILayout.EndHorizontal(); | |
GUI.backgroundColor = Color.white; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment