public static void InspectorGUI(BuildrEditMode _editMode, BuildrData _data) { editMode = _editMode; data = _data; constraints = data.generatorConstraints; EditModes newmode = (EditModes)EditorGUILayout.EnumPopup(mode); if (newmode != mode) { mode = newmode; switch (mode) { case EditModes.general: editMode.stage = BuildrEditMode.stages.building; break; case EditModes.floorplan: editMode.stage = BuildrEditMode.stages.floorplan; editMode.SetMode(BuildrEditMode.modes.floorplan); break; } } switch (mode) { case EditModes.general: GeneralOptionsInspector(); break; case EditModes.floorplan: EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Constrain Building Generation to Floorplan", GUILayout.Width(280)); constraints.constrainPlanByPlan = EditorGUILayout.Toggle(constraints.constrainPlanByPlan); EditorGUILayout.EndHorizontal(); EditorGUI.BeginDisabledGroup(!constraints.constrainPlanByPlan); BuildrEditModeFloorplan.InspectorGUI(editMode, _data.plan); EditorGUI.EndDisabledGroup(); if (data.plan != null) { constraints.plan = data.plan.Duplicate(); } break; } if (GUI.changed) { EditorUtility.SetDirty(_editMode); EditorUtility.SetDirty(_data); _editMode.UpdateRender(); } }
public override void OnInspectorGUI() { bool editing = (_data != null) ? _data.editing : true; EditorGUILayout.Space(); GUILayout.BeginVertical(GUILayout.Width(400)); if (editing) { if (_editMode.stage == BuildrEditMode.stages.start) { GUILayout.Space(10); EditorGUILayout.Space(); if (Event.current.type == EventType.Repaint) { _splashRect = GUILayoutUtility.GetLastRect(); } _splashRect.width = 300; _splashRect.height = 194; GUI.DrawTexture(_splashRect, (Texture2D)Resources.Load("splash")); GUILayout.Space(_splashRect.height); EditorGUILayout.LabelField("Welcome to BuildR.\nSelect from the following menu to begin a new building.", GUILayout.Height(30)); if (GUILayout.Button("Start floorplan with basic square")) { _editMode.StartBuilding(); _editMode.SetMode(BuildrEditMode.modes.addNewVolume); } if (GUILayout.Button("Start floorplan by drawing square")) { _editMode.StartBuilding(); _editMode.SetMode(BuildrEditMode.modes.addNewVolumeByDraw); } if (GUILayout.Button("Start floorplan by drawing walls")) { _editMode.StartBuilding(); _editMode.SetMode(BuildrEditMode.modes.addNewVolumeByPoints); } if (GUILayout.Button("Procedurally Generate Building")) { _editMode.StartBuilding(); _editMode.SetStage(BuildrEditMode.stages.building); _editMode.data.editing = false; } if (GUILayout.Button("Start floorplan from XML")) { string xmlPath = EditorUtility.OpenFilePanel("Select the XML file...", "Assets/BuildR/Exported/", "xml"); if (xmlPath == "") { return; } BuildrData buildData = _editMode.gameObject.AddComponent <BuildrData>(); buildData.plan = ScriptableObject.CreateInstance <BuildrPlan>(); BuildrXMLImporter.Import(xmlPath, buildData); _editMode.SetStage(BuildrEditMode.stages.building); } GUILayout.Space(10); GUILayout.BeginHorizontal(); if (GUILayout.Button("Online Documentation")) { Help.BrowseURL("http://buildr.jasperstocker.com/documentation/"); } if (GUILayout.Button("Contact")) { Help.BrowseURL("mailto:[email protected]"); } GUILayout.EndHorizontal(); } else { EditorGUILayout.Space(); EditorGUILayout.BeginHorizontal(); //TITLE GUIStyle title = new GUIStyle(GUI.skin.label); title.fixedHeight = 60; title.fixedWidth = 223; title.alignment = TextAnchor.UpperCenter; title.fontStyle = FontStyle.Bold; title.normal.textColor = Color.white; EditorGUILayout.LabelField("Edit Mode", title); Texture2D facadeTexture = new Texture2D(1, 1); facadeTexture.SetPixel(0, 0, BuildrColours.BLUE); facadeTexture.Apply(); Rect sqrPos = new Rect(0, 0, 0, 0); if (Event.current.type == EventType.Repaint) { sqrPos = GUILayoutUtility.GetLastRect(); } GUI.DrawTexture(sqrPos, facadeTexture); EditorGUI.LabelField(sqrPos, "Edit Mode", title); if (GUILayout.Button("Switch to Generate Mode", GUILayout.Width(165))) { _editMode.stage = BuildrEditMode.stages.building; _data.editing = false; } EditorGUILayout.EndHorizontal(); bool isLegal = _data.plan != null; if (isLegal) { isLegal = !(_data.plan.illegalPoints.Length > 0); } if (isLegal) { isLegal = _editMode.transform.localScale == Vector3.one; } EditorGUILayout.Space(); GUILayout.BeginHorizontal(); int currentStage = (int)_editMode.stage - 1; GUIContent[] guiContent = new GUIContent[9]; for (int i = 0; i < 9; i++) { guiContent[i] = new GUIContent(_stageToolbarTextures[i], _stageToolbar[i]); } int newStage = GUILayout.Toolbar(currentStage, guiContent, GUILayout.Width(400), GUILayout.Height(50)); if (newStage != currentStage) { _editMode.stage = (BuildrEditMode.stages)(newStage + 1); _editMode.mode = BuildrEditMode.modes.floorplan;//reset the floorplan mode UpdateGui(); } GUILayout.EndHorizontal(); EditorGUILayout.Space(); if (_editMode.transform.localScale != Vector3.one) { EditorGUILayout.HelpBox("The scale is not set to (1,1,1)!", MessageType.Error); return; } if (_data.plan != null) { if (_data.plan.illegalPoints.Length > 0) { EditorGUILayout.HelpBox("Your floorplan contains walls that intersect one another. " + "\nEnsure that no walls intersect another. " + "\nThe intersecting walls are highlighted red.", MessageType.Error); } } switch (_editMode.stage) { case BuildrEditMode.stages.floorplan: RenderTitle(_stageToolbar[0]); BuildrEditModeFloorplan.InspectorGUI(_editMode, _data.plan); break; case BuildrEditMode.stages.textures: RenderTitle(_stageToolbar[1]); BuildrEditModeTextures.InspectorGUI(_editMode, _data); break; case BuildrEditMode.stages.facades: RenderTitle(_stageToolbar[2]); BuildrEditModeFacades.InspectorGUI(_editMode, _data); break; case BuildrEditMode.stages.roofs: RenderTitle(_stageToolbar[3]); BuildrEditModeRoofs.InspectorGUI(_editMode, _data); break; case BuildrEditMode.stages.details: RenderTitle(_stageToolbar[4]); BuildrEditModeDetails.InspectorGUI(_editMode, _data); break; case BuildrEditMode.stages.interior: RenderTitle(_stageToolbar[5]); BuildrEditModeInterior.InspectorGUI(_editMode, _data); break; case BuildrEditMode.stages.building: RenderTitle(_stageToolbar[6]); BuildrEditModeBuilding.InspectorGUI(_editMode, _data); break; case BuildrEditMode.stages.options: RenderTitle(_stageToolbar[7]); BuildrEditModeOptions.InspectorGUI(_editMode, _data); break; case BuildrEditMode.stages.export: RenderTitle(_stageToolbar[8]); BuildrEditModeExport.InspectorGUI(_editMode, _data); break; } } } else { EditorGUILayout.BeginHorizontal(); //TITLE GUIStyle title = new GUIStyle(GUI.skin.label); title.fixedHeight = 60; title.fixedWidth = 223; title.alignment = TextAnchor.UpperCenter; title.fontStyle = FontStyle.Bold; EditorGUILayout.LabelField("", title); Texture2D facadeTexture = new Texture2D(1, 1); facadeTexture.SetPixel(0, 0, BuildrColours.BLUE); facadeTexture.Apply(); Rect sqrPos = new Rect(0, 0, 0, 0); if (Event.current.type == EventType.Repaint) { sqrPos = GUILayoutUtility.GetLastRect(); } GUI.DrawTexture(sqrPos, facadeTexture); EditorGUI.LabelField(sqrPos, "Genereate Mode (beta)", title); if (GUILayout.Button("Switch to Edit Mode", GUILayout.Width(165))) { _editMode.stage = BuildrEditMode.stages.generate; _data.editing = true; } EditorGUILayout.EndHorizontal(); //generating BuildrGenerateModeEditor.InspectorGUI(_editMode, _data); } GUILayout.EndVertical(); if (Event.current.type == EventType.ValidateCommand) { switch (Event.current.commandName) { case "UndoRedoPerformed": GUI.changed = true; break; } } if (GUI.changed) { EditorUtility.SetDirty(_editMode); if (_data != null) { EditorUtility.SetDirty(_data);//TODO: LOOK INTO ERROR HERE } _editMode.UpdateRender(); UpdateGui(); //Undo.RegisterSceneUndo("Building Modified"); } }