/// <summary>New Element is Created through "ScriptableObject.CreateInstance(type) as CGElement" and it's skin set to that of the current element</summary> public CGElement AddNew(System.Type type) { CGElement element = ScriptableObject.CreateInstance(type) as CGElement; element.SetParent(this); #if UNITY_EDITOR if (AssetDatabase.GetAssetPath(this).Length > 0) { AssetDatabase.AddObjectToAsset(element, this); AssetDatabase.SaveAssets(); } #endif element.skin = skin; return(element); }
override public void OnInspectorGUI() { main = target as CreateGUI; if (main.root == null) { main.OnEnable(); } GUI.SetNextControlName("unfocus"); GUI.TextField(new Rect(-3, 0, 0, 0), ""); if (selectedElement == null) { selectedElement = main.root; } if (deleteThis != null) { DestroyImmediate(deleteThis, true); AssetDatabase.SaveAssets(); selectedElement = main.root; } if (addChild != null && selectedElement != null) { addChild.SetParent(selectedElement); addChild = null; } if (cloneThis != null) { cloneThis.GetParent().GetChildren().Add((CGElement)ScriptableObject.Instantiate(cloneThis)); cloneThis = null; } GUIStyle selectedItemArea = new GUIStyle(); selectedItemArea.fixedWidth = Screen.width / 2; GUILayout.BeginHorizontal(); scrollPosition_SelectedElement = GUILayout.BeginScrollView(scrollPosition_SelectedElement, selectedItemArea); if (selectedElement == main.root) { GeneralOptions(main); } else { EditElement(selectedElement, main); } GUILayout.EndScrollView(); scrollPosition_ElementList = GUILayout.BeginScrollView(scrollPosition_ElementList, selectedItemArea); GUILayout.BeginVertical(); GUILayout.BeginHorizontal(); GUIStyle createGUISelectButtonStyle = new GUIStyle(GUI.skin.FindStyle("TL tab left")); if (selectedElement == main.root) { createGUISelectButtonStyle.normal.textColor = lightBlue; } if (GUILayout.Button("CREATE GUI", createGUISelectButtonStyle)) { if (Event.current.shift && selectedElement != main.root) { Debug.LogWarning("The root cannot become the child of Element \"" + selectedElement.name + "\""); } else { GUI.FocusControl("unfocus"); selectedElement = main.root; } } GUIStyle popupStyle = new GUIStyle(GUI.skin.FindStyle("TL tab plus right")); popupStyle.fixedWidth = 20; string[] options = new string[main.elementTypes.Length + 1]; options[0] = ""; int count = 0; foreach (System.Type elementType in main.elementTypes) { count++; options[count] = elementType.Name; } int action = EditorGUILayout.Popup(0, options, popupStyle); if (action != 0) { if (0 < action && action <= main.elementTypes.Length) { CGElement addition = main.root.AddNew(main.elementTypes[action - 1]); addition.name = "Element " + MonoScript.FindObjectsOfType(main.elementTypes[action - 1]).Length; } } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); ListElements(main.root.GetChildren()); GUILayout.FlexibleSpace(); GUILayout.EndVertical(); GUILayout.EndScrollView(); GUILayout.EndHorizontal(); if (GUI.changed) { main.transform.position = main.transform.position; } }