void OnGUI() { // The actual window code goes here skeletonScript = EditorGUILayout.ObjectField("Skeleton Script", skeletonScript, typeof(SkeletonScripts.SkeletonScript), false) as SkeletonScripts.SkeletonScript; skeletonScriptReplace = EditorGUILayout.ObjectField("Skeleton Script Replace", skeletonScriptReplace, typeof(SkeletonScripts.SkeletonScriptReplace), false) as SkeletonScripts.SkeletonScriptReplace; if (skeletonScript != null) { GUI.enabled = false; path = SkeletonScripts.Core.GetProjectDirectory(); if (path == null) { path = ""; } EditorGUILayout.TextField(new GUIContent("Directory", "Select a file in the \"Project\" window to set Directory"), path); GUI.enabled = true; nameOfFile = EditorGUILayout.TextField("Name", nameOfFile); //if (path != null && path[path.Length - 1] == '\\') path.Remove(path.Length - 1); //path += "\\"; previewPath = path + "/" + nameOfFile + skeletonScript.extention; if (path != null && nameOfFile != null && !File.Exists(previewPath)) { displayPreview = EditorGUILayout.ToggleLeft("Display Preview", displayPreview); error = !SkeletonScripts.Core.PathValidCheck(previewPath); if (!error) { if (GUILayout.Button("Create Skeleton Script")) { SkeletonScripts.Core.CreateFile(nameOfFile, skeletonScript.extention, skeletonScript.lines, skeletonScriptReplace.settings); AssetDatabase.Refresh(); } } else { GUI.enabled = false; GUILayout.Button("Can't save because of invalid path or name"); GUI.enabled = true; } if (displayPreview) { if (GUILayout.Button("Refresh Preview")) { previewContent = SkeletonScripts.Core.GetPreview(skeletonScript.lines, skeletonScriptReplace.settings, nameOfFile); previewPath = path + "\\" + nameOfFile + skeletonScript.extention; } GUI.enabled = false; EditorGUILayout.LabelField(new GUIContent(previewPath, "Where the Script will save to")); EditorGUILayout.TextArea(previewContent, GUILayout.Height(position.height - 30)); GUI.enabled = true; } } } }
// Draw the property inside the given rect public override void OnInspectorGUI() { SkeletonScripts.SkeletonScriptReplace skeletonScriptReplace = (serializedObject.targetObject as SkeletonScripts.SkeletonScriptReplace); using (new GUILayout.VerticalScope("box")) { skeletonScriptReplace.settings.enableReplaceWithFileNameList = EditorGUILayout.ToggleLeft("Replace With File Name", skeletonScriptReplace.settings.enableReplaceWithFileNameList); if (!skeletonScriptReplace.settings.enableReplaceWithFileNameList) { GUI.enabled = false; } EditorGUI.indentLevel++; using (new GUILayout.VerticalScope("box")) { expandFileName = EditorGUILayout.Foldout(expandFileName, new GUIContent(expandFileName ? "Hide" : "Show")); if (expandFileName) { int count = skeletonScriptReplace.settings.ReplaceWithFileNameList.Count; for (int i = 0; i < count; i++) { skeletonScriptReplace.settings.ReplaceWithFileNameList[i] = EditorGUILayout.DelayedTextField("Find", skeletonScriptReplace.settings.ReplaceWithFileNameList[i]); } if (GUILayout.Button("Add")) { skeletonScriptReplace.settings.ReplaceWithFileNameList.Add(""); } if (GUILayout.Button("Remove")) { if (count > 0) { skeletonScriptReplace.settings.ReplaceWithFileNameList.RemoveAt(count - 1); } } } EditorGUI.indentLevel--; GUI.enabled = true; } } using (new GUILayout.VerticalScope("box")) { skeletonScriptReplace.settings.enableReplaceList = EditorGUILayout.ToggleLeft("Replace With", skeletonScriptReplace.settings.enableReplaceList); if (!skeletonScriptReplace.settings.enableReplaceList) { GUI.enabled = false; } EditorGUI.indentLevel++; using (new GUILayout.VerticalScope("box")) { expandReplaceWith = EditorGUILayout.Foldout(expandReplaceWith, new GUIContent(expandReplaceWith ? "Hide" : "Show")); if (expandReplaceWith) { int count = skeletonScriptReplace.settings.ReplaceList.Count; for (int i = 0; i < count; i++) { using (new GUILayout.VerticalScope("box")) { SkeletonScripts.Core.ReplaceSettings.FindAndReplace findAndReplace = skeletonScriptReplace.settings.ReplaceList[i]; findAndReplace.Find = EditorGUILayout.DelayedTextField("Find", findAndReplace.Find); findAndReplace.Replace = EditorGUILayout.DelayedTextField("Replace With", findAndReplace.Replace); skeletonScriptReplace.settings.ReplaceList[i] = findAndReplace; } } //using (var verticalScope = new GUILayout.VerticalScope("box")) { if (GUILayout.Button("Add")) { skeletonScriptReplace.settings.ReplaceList.Add(new SkeletonScripts.Core.ReplaceSettings.FindAndReplace()); } if (GUILayout.Button("Remove")) { if (count > 0) { skeletonScriptReplace.settings.ReplaceList.RemoveAt(count - 1); } } } } EditorGUI.indentLevel--; GUI.enabled = true; } } if (GUILayout.Button("Use in new Script")) { CreateSkeletonScriptWindow.skeletonScriptReplace = skeletonScriptReplace; CreateSkeletonScriptWindow.ShowWindow(); } }