public static void OpenWindow(BlueprintEditor editor, bool creatingAField, BlueprintField currentField) { var instance = GetWindow <BlueprintEditEditor>(); instance.editor = editor; instance.creatingAField = creatingAField; instance.currentField = currentField; }
void DrawBlueprintsEditor() { GUILayout.BeginVertical("Edit Blueprints", boxStyle, GUILayout.Width(300), GUILayout.ExpandHeight(true)); GUILayout.Space(15); if (currentBlueprint != null) { BlueprintField tempField; currentBlueprint.blueprintName = EditorGUILayout.TextField("Blueprint name : ", currentBlueprint.blueprintName); GUILayout.Space(10); fieldsListScrollPos = EditorGUILayout.BeginScrollView(fieldsListScrollPos, boxStyle); for (int i = 0; i < currentBlueprint.fields.Count; i++) { tempField = currentBlueprint.fields[i]; GUILayout.BeginVertical(boxStyle, GUILayout.Height(35)); GUILayout.BeginHorizontal(); GUI.enabled = tempField.data.Count > 0; if (GUILayout.Button(tempField.isOpen ? dropdown_down_icon : dropdown_right_icon, centeredStyle, GUILayout.Width(20), GUILayout.Height(20))) { tempField.isOpen = !tempField.isOpen; } GUI.enabled = true; GUILayout.Label("Field : " + tempField.name, invisibleButtonStyle); if (GUILayout.Button("+", boxStyle, GUILayout.Width(25), GUILayout.Height(25))) { BlueprintEditEditor.OpenWindow(this, false, tempField); } if (GUILayout.Button("-", boxStyle, GUILayout.Height(25), GUILayout.Width(25))) { if (currentBlueprint != null) { if (EditorUtility.DisplayDialog("Delete", "Are you sure you want to delete this field? \nThis cannot be undone!", "Yes", "No")) { currentBlueprint.RemoveField(tempField); } } } GUILayout.EndHorizontal(); if (tempField.isOpen) { GUILayout.Space(5); for (int b = 0; b < tempField.data.Count; b++) { currentChild = tempField.data[b]; GUILayout.BeginVertical(boxStyle, GUILayout.Height(35)); GUILayout.BeginHorizontal(); GUILayout.Label("Building : " + currentChild.name, invisibleButtonStyle); if (GUILayout.Button("-", boxStyle, GUILayout.Height(20), GUILayout.Width(20))) { if (currentBlueprint != null) { if (EditorUtility.DisplayDialog("Delete", "Are you sure you want to delete this field? \nThis cannot be undone!", "Yes", "No")) { tempField.data.Remove(currentChild); } } } GUI.enabled = currentChild.data != null && currentChild.data.Count != 0; if (GUILayout.Button(new GUIContent("P", "Pack a gameObject data to this field"), boxStyle, GUILayout.Width(20), GUILayout.Height(20))) { if ((currentChild.data == null || currentChild.data.Count == 0) || (tempField.data.Count != 0 && EditorUtility.DisplayDialog("Confirm Override", "Are u sure you want to override the existing data ? \nThis cannot be undone!", "Yes Continue", "No"))) { lastFocusedBlueprint = tempField; UC_EditorUtility.DisplayObjectField((GameObject go, int index) => { if (lastFocusedBlueprint != null) { lastFocusedBlueprint.data[index].Pack(go); currentBlueprint.Save(); } }, b, true); } } if (GUILayout.Button(new GUIContent("Ex", "Export this child to a game object"), boxStyle, GUILayout.Width(20), GUILayout.Height(20))) { if (EditorUtility.DisplayDialog("Prefab Save", "Do u want to save changes to the prefab ? \nPlease note this cannot be undone!.", "Yes Continue", "No")) { lastFocusedBlueprint = tempField; UC_EditorUtility.DisplayObjectField((GameObject go, int index) => { if (lastFocusedBlueprint != null) { lastFocusedBlueprint.data[index].UnPack(go, true); } }, b, true); } else { lastFocusedBlueprint = tempField; UC_EditorUtility.DisplayObjectField((GameObject go, int index) => { if (lastFocusedBlueprint != null) { lastFocusedBlueprint.data[index].UnPack(go, false); } }, b, true); } } GUI.enabled = true; GUILayout.EndHorizontal(); GUILayout.EndVertical(); } } GUILayout.EndVertical(); } EditorGUILayout.EndScrollView(); GUILayout.BeginHorizontal(); if (GUILayout.Button("+", invisibleButtonStyle, GUILayout.Height(20), GUILayout.Width(20))) { BlueprintEditEditor.OpenWindow(this, true, null); } GUILayout.EndHorizontal(); if (GUILayout.Button("Apply Changes")) { if (currentBlueprint != null) { currentBlueprint.Save(); } } } else { GUILayout.Label("Please choose a blueprint in order to edit it."); } GUILayout.EndVertical(); }