private void GuiLayoutBeginImporterSection(Texture2D icon, string title, string author) { GUIStyle style = new GUIStyle(); style.normal.background = SabreCSGResources.ImporterBackgroundTexture; EditorGUILayout.BeginVertical(style); EditorGUILayout.BeginHorizontal(); GUILayout.Label(icon); EditorGUILayout.BeginVertical(); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); GUILayout.Label(title, SabreGUILayout.GetTitleStyle()); GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); GUILayout.Label("Author: " + author); GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); EditorGUILayout.EndVertical(); EditorGUILayout.EndHorizontal(); }
private void DrawStairPreview(Rect rect) { // Calculate an appropriate world space to UI scale for the diagram float depthTotal = stepDepthProp.floatValue * 2 + stepDepthSpacingProp.floatValue; float heightTotal = stepHeightProp.floatValue * 2 + stepHeightSpacingProp.floatValue; float uiScale = Mathf.Min(150 / depthTotal, 60 / heightTotal); // Offset the center of the diagram to fit better Vector2 centerOffset = rect.center + new Vector2(0, 10); // Draw white background //Graphics.DrawTexture(rect, EditorGUIUtility.whiteTexture); // Step size and spacing in UI space Vector2 stepUISize = new Vector2(stepDepthProp.floatValue * uiScale, stepHeightProp.floatValue * uiScale); Vector2 stepUISpacing = new Vector2(stepDepthSpacingProp.floatValue * uiScale, stepHeightSpacingProp.floatValue * uiScale); // Tint boxes blue GUI.color = new Color(0, 0.7f, 1f); // Draw bottom left step Rect stepRect1 = new Rect(centerOffset.x, centerOffset.y, stepUISize.x, stepUISize.y); stepRect1.center += new Vector2(-stepUISize.x - stepUISpacing.x / 2f, stepUISpacing.y / 2f); GUI.Box(stepRect1, new GUIContent()); // Draw top right step Rect stepRect2 = new Rect(centerOffset.x, centerOffset.y, stepUISize.x, stepUISize.y); stepRect2.center += new Vector2(stepUISpacing.x / 2f, -stepUISize.y - stepUISpacing.y / 2f); GUI.Box(stepRect2, new GUIContent()); // Draw depth spacing lines GUI.color = Color.grey; Rect drawRect = new Rect(stepRect1.xMax, stepRect2.yMin - 20, 1, 18); GUI.DrawTexture(drawRect, EditorGUIUtility.whiteTexture); drawRect = new Rect(stepRect2.xMin, stepRect2.yMin - 20, 1, 18); GUI.DrawTexture(drawRect, EditorGUIUtility.whiteTexture); // Draw height spacing lines drawRect = new Rect(stepRect1.xMin - 20, stepRect1.yMin, 18, 1); GUI.DrawTexture(drawRect, EditorGUIUtility.whiteTexture); drawRect = new Rect(stepRect1.xMin - 20, stepRect2.yMax, 18, 1); GUI.DrawTexture(drawRect, EditorGUIUtility.whiteTexture); // Draw text annotations SabreGUILayout.DrawAnchoredLabel(stepDepthProp.floatValue.ToString(), new Vector2(stepRect1.center.x, stepRect1.yMax), new Vector2(30, 20), TextAnchor.UpperCenter); SabreGUILayout.DrawAnchoredLabel(stepHeightProp.floatValue.ToString(), new Vector2(stepRect1.xMax, stepRect1.center.y), new Vector2(30, 20), TextAnchor.MiddleLeft); SabreGUILayout.DrawAnchoredLabel(stepDepthSpacingProp.floatValue.ToString(), new Vector2((stepRect1.xMax + stepRect2.xMin) / 2f, stepRect2.yMin - 20), new Vector2(30, 20), TextAnchor.LowerCenter); SabreGUILayout.DrawAnchoredLabel(stepHeightSpacingProp.floatValue.ToString(), new Vector2(stepRect1.xMin - 20, (stepRect1.yMin + stepRect2.yMax) / 2f), new Vector2(30, 20), TextAnchor.MiddleRight); // Reset GUI tints for rest of UI GUI.color = Color.white; }
void OnToolbarGUI(int windowID) { GUI.enabled = (primaryTargetBrush != null); EditorGUILayout.BeginHorizontal(); if (SabreGUILayout.Button("Clip")) { ApplyClipPlane(false); } if (SabreGUILayout.Button("Split")) { ApplyClipPlane(true); } if (SabreGUILayout.Button("Edge Loop")) { InsertEdgeLoop(); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); if (SabreGUILayout.Button("Flip Plane")) { isFlipped = !isFlipped; } GUI.enabled = (pointSelected > -1); if (SabreGUILayout.Button("Snap To Grid")) { float snapDistance = CurrentSettings.PositionSnapDistance; Vector3 newPosition = points[pointSelected]; newPosition = primaryTargetBrush.transform.TransformPoint(newPosition); newPosition = MathHelper.RoundVector3(newPosition, snapDistance); newPosition = primaryTargetBrush.transform.InverseTransformPoint(newPosition); points[pointSelected] = newPosition; } EditorGUILayout.EndHorizontal(); if (isFlipped) { displayPlane = new Plane(points[0], points[1], points[2]); } else { displayPlane = new Plane(points[2], points[1], points[0]); } planePosition = (points[0] + points[1] + points[2]) / 3f; }
private static void OnWarningToolbar(int windowID) { GUIStyle style = SabreGUILayout.GetOverlayStyle(); Vector2 size = style.CalcSize(new GUIContent(warningMessage)); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); GUILayout.Box(warningMessage, style, GUILayout.Width(size.x)); GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); }
void OnGUI() { if (surfaceEditor == null || csgModel == null) { // Link to face tool has been lost, so attempt to reacquire CSGModel[] csgModels = FindObjectsOfType <CSGModel>(); // Build the first csg model that is currently being edited for (int i = 0; i < csgModels.Length; i++) { if (csgModels[i].EditMode) { csgModel = csgModels[i]; surfaceEditor = csgModels[i].GetTool(MainMode.Face) as SurfaceEditor; break; } } // If it's still null if (surfaceEditor == null || csgModel == null) { GUILayout.Label("No active CSG Model"); return; } } GUILayout.Label("Set Vertex Colors", SabreGUILayout.GetTitleStyle()); Color sourceColor = surfaceEditor.GetColor(); Color newColor = EditorGUILayout.ColorField(sourceColor); if (newColor != sourceColor) { surfaceEditor.SetSelectionColor(newColor); } // Preset color buttons GUILayout.BeginHorizontal(); for (int i = 0; i < PRESET_COLORS.Length; i++) { if (SabreGUILayout.ColorButton(PRESET_COLORS[i])) { surfaceEditor.SetSelectionColor(PRESET_COLORS[i]); } } GUILayout.EndHorizontal(); }
private static void OnTopToolbarGUI(int windowID) { EditorGUILayout.BeginHorizontal(); MainMode currentMode = CurrentSettings.CurrentMode; if (CurrentSettings.OverrideMode != OverrideMode.None) { currentMode = (MainMode)(-1); } MainMode newMainMode = SabreGUILayout.DrawEnumGrid(currentMode, GUILayout.Width(50)); if (newMainMode != currentMode) { csgModel.SetCurrentMode(newMainMode); } /* * bool isClipMode = (CurrentSettings.OverrideMode == OverrideMode.Clip); * if(SabreGUILayout.Toggle(isClipMode, "Clip")) * { * csgModel.SetOverrideMode(OverrideMode.Clip); * } * else * { * if(isClipMode) * { * csgModel.ExitOverrideMode(); * } * } * * bool isDrawMode = (CurrentSettings.OverrideMode == OverrideMode.Draw); * * if(SabreGUILayout.Toggle(isDrawMode, "Draw")) * { * csgModel.SetOverrideMode(OverrideMode.Draw); * } * else * { * if(isDrawMode) * { * csgModel.ExitOverrideMode(); * } * } */ EditorGUILayout.EndHorizontal(); }
public override void OnInspectorGUI() { GUILayout.Label("SabreCSG Key Mappings", SabreGUILayout.GetTitleStyle()); EditorGUILayout.BeginHorizontal(); GUILayout.Label("Uses Unity shortcut format"); GUIStyle style = new GUIStyle(GUI.skin.label); style.normal.textColor = Color.blue; style.fontStyle = FontStyle.Bold; if (GUILayout.Button("See format docs", style)) { Application.OpenURL("http://unity3d.com/support/documentation/ScriptReference/MenuItem.html"); } EditorGUILayout.EndHorizontal(); DrawDefaultInspector(); }
private static void OnWarningToolbar(int windowID) { GUIStyle style = SabreGUILayout.GetOverlayStyle(); Vector2 size = style.CalcSize(new GUIContent(warningMessage)); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); GUILayout.Box(warningMessage, style, GUILayout.Width(size.x)); //, GUILayout.Width(size.x + 30), GUILayout.Height(50)); GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); // GUIStyle style = SabreGUILayout.FormatStyle(Color.black, 20, TextAnchor.MiddleCenter); // GUILayout.Label(warningMessage, style); // Rect rect = GUILayoutUtility.GetLastRect(); // rect.center -= Vector2.one; // style.normal.textColor = Color.red; // // GUI.Label(rect, warningMessage, style); }
private static void OnTopToolbarGUI(int windowID) { EditorGUILayout.BeginHorizontal(); // csgModel.SetCurrentMode(SabreGUILayout.DrawEnumGrid(CurrentSettings.CurrentMode, GUILayout.Width(67))); csgModel.SetCurrentMode(SabreGUILayout.DrawEnumGrid(CurrentSettings.CurrentMode, GUILayout.Width(50))); /* * bool isClipMode = (CurrentSettings.OverrideMode == OverrideMode.Clip); * if(SabreGUILayout.Toggle(isClipMode, "Clip")) * { * csgModel.SetOverrideMode(OverrideMode.Clip); * } * else * { * if(isClipMode) * { * csgModel.ExitOverrideMode(); * } * } * * bool isDrawMode = (CurrentSettings.OverrideMode == OverrideMode.Draw); * * if(SabreGUILayout.Toggle(isDrawMode, "Draw")) * { * csgModel.SetOverrideMode(OverrideMode.Draw); * } * else * { * if(isDrawMode) * { * csgModel.ExitOverrideMode(); * } * } */ EditorGUILayout.EndHorizontal(); }
public static void PreferencesGUI() { // Event.current.GetTypeForControl // // if(Event.current.type == EventType.KeyDown) // { // cachedEvent = new Event(Event.current); //// this.Repaint(); // } // // GUILayout.TextField(""); // // if(cachedEvent != null) // { // GUILayout.Label(cachedEvent.ToString()); // } // else // { // GUILayout.Label("No event"); // } GUILayout.Space(10); bool newHideGridInPerspective = GUILayout.Toggle(CurrentSettings.HideGridInPerspective, "Hide grid in perspective scene views"); if (newHideGridInPerspective != CurrentSettings.HideGridInPerspective) { SceneView.RepaintAll(); CurrentSettings.HideGridInPerspective = newHideGridInPerspective; } CurrentSettings.AlwaysSnapToCurrentGrid = GUILayout.Toggle(CurrentSettings.AlwaysSnapToCurrentGrid, new GUIContent("Always snap to current grid size", "When position snapping is enabled, you can press " + KeyMappings.Instance.SnapSelectionToCurrentGrid + " to snap movement to the current grid size or tick this option to have it always on.")); CurrentSettings.OverrideFlyCamera = GUILayout.Toggle(CurrentSettings.OverrideFlyCamera, "Linear fly camera"); EditorGUI.BeginChangeCheck(); CurrentSettings.ShowExcludedPolygons = GUILayout.Toggle(CurrentSettings.ShowExcludedPolygons, "Show excluded polygons"); if (EditorGUI.EndChangeCheck()) { // What's shown in the SceneView has potentially changed, so force it to repaint SceneView.RepaintAll(); } EditorGUI.BeginChangeCheck(); CurrentSettings.ShowBrushesAsWireframes = GUILayout.Toggle(CurrentSettings.ShowBrushesAsWireframes, "Show brushes as wireframes"); if (EditorGUI.EndChangeCheck()) { // What's shown in the SceneView has potentially changed, so force it to repaint CSGModel.UpdateAllBrushesVisibility(); SceneView.RepaintAll(); } EditorGUI.BeginChangeCheck(); CurrentSettings.ShowBrushBoundsGuideLines = GUILayout.Toggle(CurrentSettings.ShowBrushBoundsGuideLines, "Show brush bounds guide lines"); if (EditorGUI.EndChangeCheck()) { // What's shown in the SceneView has potentially changed, so force it to repaint CSGModel.UpdateAllBrushesVisibility(); SceneView.RepaintAll(); } EditorGUILayout.Space(); EditorGUI.indentLevel = 1; EditorGUILayout.LabelField("Developer Options", EditorStyles.boldLabel); EditorGUI.indentLevel = 0; EditorGUILayout.Space(); EditorGUI.BeginChangeCheck(); CurrentSettings.ShowHiddenGameObjectsInHierarchy = GUILayout.Toggle(CurrentSettings.ShowHiddenGameObjectsInHierarchy, "Show hidden game objects in hierarchy"); if (EditorGUI.EndChangeCheck()) { // What's shown in the SceneView has potentially changed, so force it to repaint CSGModel.RebuildAllVolumes(); SceneView.RepaintAll(); } GUILayout.Space(10); if (GUILayout.Button("Change key mappings")) { Selection.activeObject = KeyMappings.Instance; // Show inspector EditorApplication.ExecuteMenuItem("Window/Inspector"); } // CurrentSettings.ReducedHandleThreshold = GUILayout.Toggle(CurrentSettings.ReducedHandleThreshold, "Reduced handle threshold"); GUILayout.Space(20); GUIStyle style = SabreGUILayout.GetForeStyle(); style.wordWrap = true; GUILayout.Label("Runtime CSG is a new experimental feature which allows you to create, alter and build brushes at runtime in your built applications.", style); BuildTargetGroup buildTargetGroup = EditorUserBuildSettings.selectedBuildTargetGroup; string defines = PlayerSettings.GetScriptingDefineSymbolsForGroup(buildTargetGroup); List <string> definesSplit = defines.Split(';').ToList(); bool enabled = definesSplit.Contains(RUNTIME_CSG_DEFINE); if (enabled) { if (GUILayout.Button("Disable Runtime CSG (Experimental)")) { definesSplit.Remove(RUNTIME_CSG_DEFINE); defines = string.Join(";", definesSplit.ToArray()); PlayerSettings.SetScriptingDefineSymbolsForGroup(buildTargetGroup, defines); } } else { if (GUILayout.Button("Enable Runtime CSG (Experimental)")) { if (!definesSplit.Contains(RUNTIME_CSG_DEFINE)) { definesSplit.Add(RUNTIME_CSG_DEFINE); } defines = string.Join(";", definesSplit.ToArray()); PlayerSettings.SetScriptingDefineSymbolsForGroup(buildTargetGroup, defines); } } GUILayout.Space(20); GUILayout.Label("Debug mode executes additional code for verbose error checking. Used by SabreCSG developers.", style); buildTargetGroup = EditorUserBuildSettings.selectedBuildTargetGroup; defines = PlayerSettings.GetScriptingDefineSymbolsForGroup(buildTargetGroup); definesSplit = defines.Split(';').ToList(); enabled = definesSplit.Contains(SABRE_CSG_DEBUG_DEFINE); if (enabled) { if (GUILayout.Button("Disable Debug Mode (Recommended)")) { definesSplit.Remove(SABRE_CSG_DEBUG_DEFINE); defines = string.Join(";", definesSplit.ToArray()); PlayerSettings.SetScriptingDefineSymbolsForGroup(buildTargetGroup, defines); } } else { if (GUILayout.Button("Enable Debug Mode (Not Recommended)")) { if (!definesSplit.Contains(SABRE_CSG_DEBUG_DEFINE)) { definesSplit.Add(SABRE_CSG_DEBUG_DEFINE); } defines = string.Join(";", definesSplit.ToArray()); PlayerSettings.SetScriptingDefineSymbolsForGroup(buildTargetGroup, defines); } } GUILayout.FlexibleSpace(); GUILayout.Label("SabreCSG Version " + CSGModel.VERSION_STRING, SabreGUILayout.GetForeStyle()); }
private static void OnBottomToolbarGUI(int windowID) { GUILayout.BeginHorizontal(); GUIStyle createBrushStyle = new GUIStyle(EditorStyles.toolbarButton); createBrushStyle.fixedHeight = 20; if (GUI.Button(new Rect(0, 0, 30, createBrushStyle.fixedHeight), SabreCSGResources.ButtonCubeTexture, createBrushStyle)) { CreatePrimitiveBrush(PrimitiveBrushType.Cube); } if (GUI.Button(new Rect(30, 0, 30, createBrushStyle.fixedHeight), SabreCSGResources.ButtonPrismTexture, createBrushStyle)) { CreatePrimitiveBrush(PrimitiveBrushType.Prism); } //if(GUI.Button(new Rect(60,0, 30, createBrushStyle.fixedHeight), "", createBrushStyle)) //{ //} if (GUI.Button(new Rect(60, 0, 30, createBrushStyle.fixedHeight), SabreCSGResources.ButtonStairsTexture, createBrushStyle)) { CreateCompoundBrush <StairBrush>(); } if (GUI.Button(new Rect(90, 0, 30, createBrushStyle.fixedHeight), SabreCSGResources.ButtonCurvedStairsTexture, createBrushStyle)) { CreateCompoundBrush <CurvedStairBrush>(); } GUILayout.Space(92 + 30); #if DEBUG_SABRECSG_PERF // For debugging frame rate GUILayout.Label(((int)(1 / csgModel.CurrentFrameDelta)).ToString(), SabreGUILayout.GetLabelStyle()); #endif if (SabreGUILayout.Button("Rebuild")) { csgModel.Build(false, false); } if (SabreGUILayout.Button("Force Rebuild")) { csgModel.Build(true, false); } GUI.color = Color.white; if (csgModel.AutoRebuild) { GUI.color = Color.green; } csgModel.AutoRebuild = SabreGUILayout.Toggle(csgModel.AutoRebuild, "Auto Rebuild"); GUI.color = Color.white; GUILayout.Label(csgModel.BuildMetrics.BuildMetaData.ToString(), SabreGUILayout.GetForeStyle(), GUILayout.Width(140)); bool lastBrushesHidden = CurrentSettings.BrushesHidden; if (lastBrushesHidden) { GUI.color = Color.red; } CurrentSettings.BrushesHidden = SabreGUILayout.Toggle(CurrentSettings.BrushesHidden, "Brushes Hidden"); if (CurrentSettings.BrushesHidden != lastBrushesHidden) { // Has changed CSGModel.UpdateAllBrushesVisibility(); SceneView.RepaintAll(); } GUI.color = Color.white; bool lastMeshHidden = CurrentSettings.MeshHidden; if (lastMeshHidden) { GUI.color = Color.red; } CurrentSettings.MeshHidden = SabreGUILayout.Toggle(CurrentSettings.MeshHidden, "Mesh Hidden"); if (CurrentSettings.MeshHidden != lastMeshHidden) { // Has changed CSGModel.UpdateAllBrushesVisibility(); SceneView.RepaintAll(); } GUI.color = Color.white; if (GUILayout.Button("Grid " + CurrentSettings.GridMode.ToString(), EditorStyles.toolbarDropDown, GUILayout.Width(90))) { GenericMenu menu = new GenericMenu(); string[] names = Enum.GetNames(typeof(GridMode)); for (int i = 0; i < names.Length; i++) { GridMode value = (GridMode)Enum.Parse(typeof(GridMode), names[i]); bool selected = false; if (CurrentSettings.GridMode == value) { selected = true; } menu.AddItem(new GUIContent(names[i]), selected, OnSelectedGridOption, value); } menu.DropDown(gridRect); } if (Event.current.type == EventType.Repaint) { gridRect = GUILayoutUtility.GetLastRect(); gridRect.width = 100; } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); // Line Two GUILayout.BeginHorizontal(); if (GUI.Button(new Rect(0, createBrushStyle.fixedHeight, 30, createBrushStyle.fixedHeight), SabreCSGResources.ButtonCylinderTexture, createBrushStyle)) { CreatePrimitiveBrush(PrimitiveBrushType.Cylinder); } if (GUI.Button(new Rect(30, createBrushStyle.fixedHeight, 30, createBrushStyle.fixedHeight), SabreCSGResources.ButtonSphereTexture, createBrushStyle)) { CreatePrimitiveBrush(PrimitiveBrushType.Sphere); } if (GUI.Button(new Rect(60, createBrushStyle.fixedHeight, 30, createBrushStyle.fixedHeight), SabreCSGResources.ButtonConeTexture, createBrushStyle)) { CreatePrimitiveBrush(PrimitiveBrushType.Cone); } //if (GUI.Button(new Rect(60, createBrushStyle.fixedHeight, 30, createBrushStyle.fixedHeight), "", createBrushStyle)) //{ //} if (GUI.Button(new Rect(90, createBrushStyle.fixedHeight, 30, createBrushStyle.fixedHeight), "...", createBrushStyle)) { GenericMenu menu = new GenericMenu(); List <Type> compoundBrushTypes = CompoundBrush.FindAllInAssembly(); for (int i = 0; i < compoundBrushTypes.Count; i++) { menu.AddItem(new GUIContent(compoundBrushTypes[i].Name), false, CreateCompoundBrush, compoundBrushTypes[i]); } menu.DropDown(new Rect(60, createBrushStyle.fixedHeight, 100, createBrushStyle.fixedHeight)); } GUILayout.Space(92 + 30); // Display brush count GUILayout.Label(csgModel.BrushCount.ToStringWithSuffix(" brush", " brushes"), SabreGUILayout.GetLabelStyle()); // CurrentSettings.GridMode = (GridMode)EditorGUILayout.EnumPopup(CurrentSettings.GridMode, EditorStyles.toolbarPopup, GUILayout.Width(80)); if (Selection.activeGameObject != null) { BrushBase primaryBrush = Selection.activeGameObject.GetComponent <BrushBase>(); List <BrushBase> brushes = new List <BrushBase>(); for (int i = 0; i < Selection.gameObjects.Length; i++) { BrushBase brush = Selection.gameObjects[i].GetComponent <BrushBase>(); if (brush != null) { brushes.Add(brush); } } if (primaryBrush != null) { CSGMode brushMode = (CSGMode)EditorGUILayout.EnumPopup(primaryBrush.Mode, EditorStyles.toolbarPopup, GUILayout.Width(80)); if (brushMode != primaryBrush.Mode) { bool anyChanged = false; foreach (BrushBase brush in brushes) { Undo.RecordObject(brush, "Change Brush To " + brushMode); brush.Mode = brushMode; anyChanged = true; } if (anyChanged) { // Need to update the icon for the csg mode in the hierarchy EditorApplication.RepaintHierarchyWindow(); } } bool[] noCSGStates = brushes.Select(brush => brush.IsNoCSG).Distinct().ToArray(); bool isNoCSG = (noCSGStates.Length == 1) ? noCSGStates[0] : false; bool newIsNoCSG = SabreGUILayout.ToggleMixed(noCSGStates, "NoCSG", GUILayout.Width(53)); bool[] collisionStates = brushes.Select(item => item.HasCollision).Distinct().ToArray(); bool hasCollision = (collisionStates.Length == 1) ? collisionStates[0] : false; bool newHasCollision = SabreGUILayout.ToggleMixed(collisionStates, "Collision", GUILayout.Width(53)); bool[] visibleStates = brushes.Select(item => item.IsVisible).Distinct().ToArray(); bool isVisible = (visibleStates.Length == 1) ? visibleStates[0] : false; bool newIsVisible = SabreGUILayout.ToggleMixed(visibleStates, "Visible", GUILayout.Width(53)); if (newIsNoCSG != isNoCSG) { foreach (BrushBase brush in brushes) { Undo.RecordObject(brush, "Change Brush NoCSG Mode"); brush.IsNoCSG = newIsNoCSG; } // Tell the brushes that they have changed and need to recalc intersections foreach (BrushBase brush in brushes) { brush.Invalidate(true); } EditorApplication.RepaintHierarchyWindow(); } if (newHasCollision != hasCollision) { foreach (BrushBase brush in brushes) { Undo.RecordObject(brush, "Change Brush Collision Mode"); brush.HasCollision = newHasCollision; } // Tell the brushes that they have changed and need to recalc intersections foreach (BrushBase brush in brushes) { brush.Invalidate(true); } } if (newIsVisible != isVisible) { foreach (BrushBase brush in brushes) { Undo.RecordObject(brush, "Change Brush Visible Mode"); brush.IsVisible = newIsVisible; } // Tell the brushes that they have changed and need to recalc intersections foreach (BrushBase brush in brushes) { brush.Invalidate(true); } if (newIsVisible == false) { csgModel.NotifyPolygonsRemoved(); } } } } GUILayout.Space(10); // Position snapping UI CurrentSettings.PositionSnappingEnabled = SabreGUILayout.Toggle(CurrentSettings.PositionSnappingEnabled, "Pos Snapping"); CurrentSettings.PositionSnapDistance = EditorGUILayout.FloatField(CurrentSettings.PositionSnapDistance, GUILayout.Width(50)); if (SabreGUILayout.Button("-", EditorStyles.miniButtonLeft)) { CurrentSettings.ChangePosSnapDistance(.5f); } if (SabreGUILayout.Button("+", EditorStyles.miniButtonRight)) { CurrentSettings.ChangePosSnapDistance(2f); } // Rotation snapping UI CurrentSettings.AngleSnappingEnabled = SabreGUILayout.Toggle(CurrentSettings.AngleSnappingEnabled, "Ang Snapping"); CurrentSettings.AngleSnapDistance = EditorGUILayout.FloatField(CurrentSettings.AngleSnapDistance, GUILayout.Width(50)); if (SabreGUILayout.Button("-", EditorStyles.miniButtonLeft)) { if (CurrentSettings.AngleSnapDistance > 15) { CurrentSettings.AngleSnapDistance -= 15; } else { CurrentSettings.AngleSnapDistance -= 5; } } if (SabreGUILayout.Button("+", EditorStyles.miniButtonRight)) { if (CurrentSettings.AngleSnapDistance >= 15) { CurrentSettings.AngleSnapDistance += 15; } else { CurrentSettings.AngleSnapDistance += 5; } } GUILayout.FlexibleSpace(); if (SabreGUILayout.Button("Prefs")) { SabreCSGPreferences.CreateAndShow(); } if (SabreGUILayout.Button("Disable")) { Selection.activeGameObject = null; csgModel.EditMode = false; } GUILayout.EndHorizontal(); }
private static void OnBottomToolbarGUI(int windowID) { GUILayout.BeginHorizontal(); // For debugging frame rate // GUILayout.Label(((int)(1 / csgModel.CurrentFrameDelta)).ToString(), SabreGUILayout.GetLabelStyle()); if (GUILayout.Button("Create", EditorStyles.toolbarDropDown)) { GenericMenu menu = new GenericMenu(); string[] names = Enum.GetNames(typeof(PrimitiveBrushType)); for (int i = 0; i < names.Length; i++) { if (names[i] != "Custom") { menu.AddItem(new GUIContent(names[i]), false, OnSelectedCreateOption, Enum.Parse(typeof(PrimitiveBrushType), names[i])); } } menu.DropDown(createRect); } if (Event.current.type == EventType.Repaint) { createRect = GUILayoutUtility.GetLastRect(); createRect.width = 100; } if (SabreGUILayout.Button("Rebuild")) { csgModel.Build(false); } if (SabreGUILayout.Button("Force Rebuild")) { csgModel.Build(true); } GUI.color = Color.white; if (csgModel.AutoRebuild) { GUI.color = Color.green; } csgModel.AutoRebuild = SabreGUILayout.Toggle(csgModel.AutoRebuild, "Auto Rebuild"); GUI.color = Color.white; GUILayout.Label(csgModel.BuildMetrics.BuildMetaData.ToString(), SabreGUILayout.GetForeStyle(), GUILayout.Width(140)); bool lastBrushesHidden = CurrentSettings.BrushesHidden; if (lastBrushesHidden) { GUI.color = Color.red; } CurrentSettings.BrushesHidden = SabreGUILayout.Toggle(CurrentSettings.BrushesHidden, "Brushes Hidden"); if (CurrentSettings.BrushesHidden != lastBrushesHidden) { // Has changed csgModel.UpdateBrushVisibility(); SceneView.RepaintAll(); } GUI.color = Color.white; bool lastMeshHidden = CurrentSettings.MeshHidden; if (lastMeshHidden) { GUI.color = Color.red; } CurrentSettings.MeshHidden = SabreGUILayout.Toggle(CurrentSettings.MeshHidden, "Mesh Hidden"); if (CurrentSettings.MeshHidden != lastMeshHidden) { // Has changed csgModel.UpdateBrushVisibility(); SceneView.RepaintAll(); } GUI.color = Color.white; if (GUILayout.Button("Grid " + CurrentSettings.GridMode.ToString(), EditorStyles.toolbarDropDown, GUILayout.Width(90))) { GenericMenu menu = new GenericMenu(); string[] names = Enum.GetNames(typeof(GridMode)); for (int i = 0; i < names.Length; i++) { GridMode value = (GridMode)Enum.Parse(typeof(GridMode), names[i]); bool selected = false; if (CurrentSettings.GridMode == value) { selected = true; } menu.AddItem(new GUIContent(names[i]), selected, OnSelectedGridOption, value); } menu.DropDown(gridRect); } if (Event.current.type == EventType.Repaint) { gridRect = GUILayoutUtility.GetLastRect(); gridRect.width = 100; } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); // Line Two GUILayout.BeginHorizontal(); // Display brush count GUILayout.Label(csgModel.BrushCount.ToStringWithSuffix(" brush", " brushes"), SabreGUILayout.GetLabelStyle()); // CurrentSettings.GridMode = (GridMode)EditorGUILayout.EnumPopup(CurrentSettings.GridMode, EditorStyles.toolbarPopup, GUILayout.Width(80)); if (Selection.activeGameObject != null) { Brush primaryBrush = Selection.activeGameObject.GetComponent <Brush>(); List <Brush> brushes = new List <Brush>(); for (int i = 0; i < Selection.gameObjects.Length; i++) { Brush brush = Selection.gameObjects[i].GetComponent <Brush>(); if (brush != null) { brushes.Add(brush); } } if (primaryBrush != null) { CSGMode brushMode = (CSGMode)EditorGUILayout.EnumPopup(primaryBrush.Mode, EditorStyles.toolbarPopup, GUILayout.Width(80)); if (brushMode != primaryBrush.Mode) { bool anyChanged = false; foreach (Brush brush in brushes) { Undo.RecordObject(brush, "Change Brush To " + brushMode); brush.Mode = brushMode; anyChanged = true; } if (anyChanged) { // Need to update the icon for the csg mode in the hierarchy EditorApplication.RepaintHierarchyWindow(); } } bool[] noCSGStates = brushes.Select(brush => brush.IsNoCSG).Distinct().ToArray(); bool isNoCSG = (noCSGStates.Length == 1) ? noCSGStates[0] : false; bool newIsNoCSG = SabreGUILayout.ToggleMixed(noCSGStates, "NoCSG", GUILayout.Width(53)); bool[] collisionStates = brushes.Select(item => item.HasCollision).Distinct().ToArray(); bool hasCollision = (collisionStates.Length == 1) ? collisionStates[0] : false; bool newHasCollision = SabreGUILayout.ToggleMixed(collisionStates, "Collision", GUILayout.Width(53)); bool[] visibleStates = brushes.Select(item => item.IsVisible).Distinct().ToArray(); bool isVisible = (visibleStates.Length == 1) ? visibleStates[0] : false; bool newIsVisible = SabreGUILayout.ToggleMixed(visibleStates, "Visible", GUILayout.Width(53)); if (newIsNoCSG != isNoCSG) { foreach (Brush brush in brushes) { Undo.RecordObject(brush, "Change Brush NoCSG Mode"); brush.IsNoCSG = newIsNoCSG; } // Tell the brushes that they have changed and need to recalc intersections foreach (Brush brush in brushes) { brush.Invalidate(true); } } if (newHasCollision != hasCollision) { foreach (Brush brush in brushes) { Undo.RecordObject(brush, "Change Brush Collision Mode"); brush.HasCollision = newHasCollision; } // Tell the brushes that they have changed and need to recalc intersections foreach (Brush brush in brushes) { brush.Invalidate(true); } } if (newIsVisible != isVisible) { foreach (Brush brush in brushes) { Undo.RecordObject(brush, "Change Brush Visible Mode"); brush.IsVisible = newIsVisible; } // Tell the brushes that they have changed and need to recalc intersections foreach (Brush brush in brushes) { brush.Invalidate(true); } if (newIsVisible == false) { csgModel.NotifyPolygonsRemoved(); } } } } GUILayout.Space(10); // Position snapping UI CurrentSettings.PositionSnappingEnabled = SabreGUILayout.Toggle(CurrentSettings.PositionSnappingEnabled, "Pos Snapping"); CurrentSettings.PositionSnapDistance = EditorGUILayout.FloatField(CurrentSettings.PositionSnapDistance, GUILayout.Width(50)); if (SabreGUILayout.Button("-", EditorStyles.miniButtonLeft)) { CurrentSettings.ChangePosSnapDistance(.5f); } if (SabreGUILayout.Button("+", EditorStyles.miniButtonRight)) { CurrentSettings.ChangePosSnapDistance(2f); } // Rotation snapping UI CurrentSettings.AngleSnappingEnabled = SabreGUILayout.Toggle(CurrentSettings.AngleSnappingEnabled, "Ang Snapping"); CurrentSettings.AngleSnapDistance = EditorGUILayout.FloatField(CurrentSettings.AngleSnapDistance, GUILayout.Width(50)); if (SabreGUILayout.Button("-", EditorStyles.miniButtonLeft)) { if (CurrentSettings.AngleSnapDistance > 15) { CurrentSettings.AngleSnapDistance -= 15; } else { CurrentSettings.AngleSnapDistance -= 5; } } if (SabreGUILayout.Button("+", EditorStyles.miniButtonRight)) { if (CurrentSettings.AngleSnapDistance >= 15) { CurrentSettings.AngleSnapDistance += 15; } else { CurrentSettings.AngleSnapDistance += 5; } } // Disabled test build options // CurrentSettings.RestoreOriginalPolygons = SabreGUILayout.Toggle(CurrentSettings.RestoreOriginalPolygons, "Restore Original Polygons", GUILayout.Width(153)); // CurrentSettings.RemoveHiddenGeometry = SabreGUILayout.Toggle(CurrentSettings.RemoveHiddenGeometry, "Remove Hidden Geometry", GUILayout.Width(153)); GUILayout.FlexibleSpace(); // if (CurrentSettings.CurrentMode != MainMode.Free) // { // if( Tools.current == UnityEditor.Tool.View && Tools.viewTool == ViewTool.Pan) // { // GUI.color = Color.yellow; // } // } if (SabreGUILayout.Button("Prefs")) { SabreCSGPreferences.CreateAndShow(); } if (SabreGUILayout.Button("Disable")) { Selection.activeGameObject = null; csgModel.EditMode = false; } GUILayout.EndHorizontal(); }
private static void OnTopToolbarGUI(int windowID) { csgModel.SetCurrentMode(SabreGUILayout.DrawEnumGrid(CurrentSettings.CurrentMode, GUILayout.Width(50))); }
public void DrawBrushTypeField() { GUILayout.BeginHorizontal(); PrimitiveBrushType[] selectedTypes = BrushTargets.Select(item => item.BrushType).ToArray(); if (overridenBrushType.HasValue) { selectedTypes = new PrimitiveBrushType[] { overridenBrushType.Value }; } PrimitiveBrushType?newType = SabreGUILayout.EnumPopupMixed("Brush Type", selectedTypes); if (newType.HasValue) { overridenBrushType = newType; if (newType.Value == PrimitiveBrushType.Prism) { GUILayout.Label("Sides", SabreGUILayout.GetForeStyle(), GUILayout.Width(30)); EditorGUILayout.PropertyField(prismSideCountProp, new GUIContent("")); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); } else if (newType.Value == PrimitiveBrushType.Cylinder) { GUILayout.Label("Sides", SabreGUILayout.GetForeStyle(), GUILayout.Width(30)); EditorGUILayout.PropertyField(cylinderSideCountProp, new GUIContent("")); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); } else if (newType.Value == PrimitiveBrushType.Sphere) { GUILayout.Label("Sides", SabreGUILayout.GetForeStyle(), GUILayout.Width(30)); EditorGUILayout.PropertyField(sphereSideCountProp, new GUIContent("")); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); } } if (GUILayout.Button("Reset Polygons")) { Undo.RecordObjects(targets, "Reset Polygons"); foreach (var thisBrush in targets) { if (overridenBrushType.HasValue) { ((PrimitiveBrush)thisBrush).BrushType = overridenBrushType.Value; } ((PrimitiveBrush)thisBrush).ResetPolygons(); ((PrimitiveBrush)thisBrush).Invalidate(true); } overridenBrushType = null; } GUILayout.EndHorizontal(); if (GUILayout.Button("Shell")) { List <GameObject> newSelection = new List <GameObject>(); foreach (var thisBrush in targets) { GameObject newObject = ((PrimitiveBrush)thisBrush).Duplicate(); Polygon[] polygons = newObject.GetComponent <PrimitiveBrush>().GetPolygons(); VertexUtility.DisplacePolygons(polygons, -CurrentSettings.PositionSnapDistance); Bounds newBounds = newObject.GetComponent <PrimitiveBrush>().GetBounds(); // Verify the new geometry if (GeometryHelper.IsBrushConvex(polygons) && newBounds.GetSmallestExtent() > 0) { Undo.RegisterCreatedObjectUndo(newObject, "Shell"); newSelection.Add(newObject); } else { // Produced a concave brush, delete it and pretend nothing happened GameObject.DestroyImmediate(newObject); Debug.LogWarning("Could not shell " + thisBrush.name + " as shelled geometry would not be valid. Try lowering Pos Snapping and attempt Shell again."); } } if (newSelection.Count > 0) { Selection.objects = newSelection.ToArray(); } } }
private static void OnBottomToolbarGUI(int windowID) { GUILayout.BeginHorizontal(); GUIStyle createBrushStyle = new GUIStyle(EditorStyles.toolbarButton); createBrushStyle.fixedHeight = 20; if (GUILayout.Button(SabreCSGResources.ButtonCubeTexture, createBrushStyle)) { CreatePrimitiveBrush(PrimitiveBrushType.Cube); } primitiveMenuShowing = GUILayout.Toggle(primitiveMenuShowing, primitiveMenuShowing?"▼": "▲", createBrushStyle); #if DEBUG_SABRECSG_PERF // For debugging frame rate GUILayout.Label(((int)(1 / csgModel.CurrentFrameDelta)).ToString(), SabreGUILayout.GetLabelStyle()); #endif if (SabreGUILayout.Button("Rebuild", createBrushStyle)) { csgModel.Build(false, false); } if (SabreGUILayout.Button("Force Rebuild", createBrushStyle)) { csgModel.Build(true, false); } GUI.color = Color.white; csgModel.AutoRebuild = GUILayout.Toggle(csgModel.AutoRebuild, "Auto Rebuild", createBrushStyle); GUI.color = Color.white; #if SABRE_CSG_DEBUG GUILayout.Label(csgModel.BuildMetrics.BuildMetaData.ToString(), SabreGUILayout.GetForeStyle(), GUILayout.Width(140)); #else EditorGUILayout.Space(); #endif if (showToolbarOnTwoLines) { GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); } GUILayout.FlexibleSpace(); GUIStyle labelStyle = new GUIStyle(EditorStyles.label); labelStyle.fontSize = 9; labelStyle.fixedHeight = 16; labelStyle.alignment = TextAnchor.MiddleCenter; GUILayout.Label("Grid size", labelStyle); CurrentSettings.PositionSnapDistance = EditorGUILayout.FloatField(CurrentSettings.PositionSnapDistance, GUILayout.MaxWidth(70f), GUILayout.MinWidth(30f)); if (SabreGUILayout.Button("-", EditorStyles.miniButtonLeft)) { CurrentSettings.ChangePosSnapDistance(.5f); } if (SabreGUILayout.Button("+", EditorStyles.miniButtonRight)) { CurrentSettings.ChangePosSnapDistance(2f); } viewMenuShowing = GUILayout.Toggle(viewMenuShowing, "Viewport settings", createBrushStyle); GUILayout.EndHorizontal(); }
static void OnViewMenuGUI(int windowID) { float left_pad = 90f; EditorGUIUtility.labelWidth = 118f; GUILayout.Space(4); GUILayout.BeginHorizontal(); GUILayout.Label("Viewport Settings", EditorStyles.boldLabel); GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); bool lastBrushesHidden = CurrentSettings.BrushesHidden; CurrentSettings.BrushesHidden = EditorGUILayout.Toggle( new GUIContent("Hide Brushes", "Hotkey: " + KeyMappings.Instance.ToggleBrushesHidden), CurrentSettings.BrushesHidden ); if (CurrentSettings.BrushesHidden != lastBrushesHidden) { // Has changed CSGModel.UpdateAllBrushesVisibility(); SceneView.RepaintAll(); } GUILayout.EndHorizontal(); bool lastMeshHidden = CurrentSettings.MeshHidden; CurrentSettings.MeshHidden = EditorGUILayout.Toggle("Hide Meshes", CurrentSettings.MeshHidden); if (CurrentSettings.MeshHidden != lastMeshHidden) { // Has changed CSGModel.UpdateAllBrushesVisibility(); SceneView.RepaintAll(); } GUILayout.Space(10); GUILayout.BeginHorizontal(); GUILayout.Label("Grid Settings", EditorStyles.boldLabel); GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Grid type", EditorStyles.label); GUILayout.FlexibleSpace(); GridMode lastMode = CurrentSettings.GridMode; CurrentSettings.GridMode = (GridMode)EditorGUILayout.EnumPopup(CurrentSettings.GridMode, GUILayout.Width(left_pad)); if (CurrentSettings.GridMode != lastMode) { OnSelectedGridOption(CurrentSettings.GridMode); } GUILayout.EndHorizontal(); // Projected grid bool lastProjectedGridEnabled = CurrentSettings.ProjectedGridEnabled; CurrentSettings.ProjectedGridEnabled = EditorGUILayout.Toggle( new GUIContent("Projected Grid", "Hotkey: " + KeyMappings.Instance.ToggleProjectedGrid.Replace("#", "Shift+")), CurrentSettings.ProjectedGridEnabled ); if (CurrentSettings.ProjectedGridEnabled != lastProjectedGridEnabled) { SceneView.RepaintAll(); } if (Event.current.type == EventType.Repaint) { gridRect = GUILayoutUtility.GetLastRect(); gridRect.width = 100; } // Position snapping UI CurrentSettings.PositionSnappingEnabled = EditorGUILayout.Toggle( new GUIContent("Grid snapping", "Hotkey: " + KeyMappings.Instance.TogglePosSnapping.Replace("#", "Shift+")), CurrentSettings.PositionSnappingEnabled ); // Position snapping UI CurrentSettings.AngleSnappingEnabled = EditorGUILayout.Toggle( new GUIContent("Rotation snapping", "Hotkey: " + KeyMappings.Instance.ToggleAngSnapping.Replace("#", "Shift+")), CurrentSettings.AngleSnappingEnabled ); // Rotation snapping UI GUILayout.BeginHorizontal(); GUILayout.Label(new GUIContent( "Rotation size", "Hotkeys: " + KeyMappings.Instance.DecreaseAngSnapping.Replace("#", "Shift+") + " " + KeyMappings.Instance.IncreaseAngSnapping.Replace("#", "Shift+") ), EditorStyles.label); GUILayout.FlexibleSpace(); // CurrentSettings.AngleSnappingEnabled = SabreGUILayout.Toggle(CurrentSettings.AngleSnappingEnabled, "Ang Snapping"); CurrentSettings.AngleSnapDistance = EditorGUILayout.FloatField(CurrentSettings.AngleSnapDistance, GUILayout.Width(50)); if (SabreGUILayout.Button("-", EditorStyles.miniButtonLeft)) { if (CurrentSettings.AngleSnapDistance > 15) { CurrentSettings.AngleSnapDistance -= 15; } else { CurrentSettings.AngleSnapDistance -= 5; } } if (SabreGUILayout.Button("+", EditorStyles.miniButtonRight)) { if (CurrentSettings.AngleSnapDistance >= 15) { CurrentSettings.AngleSnapDistance += 15; } else { CurrentSettings.AngleSnapDistance += 5; } } GUILayout.EndHorizontal(); }
public static void PreferencesGUI() { // Commented out for 1.2.5 release as runtime code is currently not finished // GUIStyle style = SabreGUILayout.GetForeStyle(); // style.wordWrap = true; // GUILayout.Label("Runtime CSG allows you to create, alter and build brushes at runtime in your built applications.", style); // BuildTargetGroup buildTargetGroup = EditorUserBuildSettings.selectedBuildTargetGroup; // string defines = PlayerSettings.GetScriptingDefineSymbolsForGroup(buildTargetGroup); // List<string> definesSplit = defines.Split(';').ToList(); // bool enabled = definesSplit.Contains(RUNTIME_CSG_DEFINE); // // if(enabled) // { // if(GUILayout.Button("Disable Runtime CSG")) // { // definesSplit.Remove(RUNTIME_CSG_DEFINE); // defines = string.Join(";", definesSplit.ToArray()); // PlayerSettings.SetScriptingDefineSymbolsForGroup(buildTargetGroup, defines); // } // } // else // { // if(GUILayout.Button("Enable Runtime CSG")) // { // definesSplit.Add(RUNTIME_CSG_DEFINE); // defines = string.Join(";", definesSplit.ToArray()); // PlayerSettings.SetScriptingDefineSymbolsForGroup(buildTargetGroup, defines); // } // } // Event.current.GetTypeForControl // // if(Event.current.type == EventType.KeyDown) // { // cachedEvent = new Event(Event.current); //// this.Repaint(); // } // // GUILayout.TextField(""); // // if(cachedEvent != null) // { // GUILayout.Label(cachedEvent.ToString()); // } // else // { // GUILayout.Label("No event"); // } bool newHideGridInPerspective = GUILayout.Toggle(CurrentSettings.HideGridInPerspective, "Hide grid in perspective scene views"); if (newHideGridInPerspective != CurrentSettings.HideGridInPerspective) { SceneView.RepaintAll(); CurrentSettings.HideGridInPerspective = newHideGridInPerspective; } CurrentSettings.OverrideFlyCamera = GUILayout.Toggle(CurrentSettings.OverrideFlyCamera, "Linear fly camera"); GUILayout.FlexibleSpace(); GUILayout.Label("SabreCSG Version " + CSGModel.VERSION_STRING, SabreGUILayout.GetForeStyle()); }
void OnGUI() { GUILayout.Label("SabreCSG Preferences", SabreGUILayout.GetTitleStyle(20)); PreferencesGUI(); }
private void OnToolbarGUI(int windowID) { EditorGUILayout.Space(); restrictToFace = SabreGUILayout.Toggle(restrictToFace, "Restrict To Face"); drawingMode = SabreGUILayout.DrawEnumGrid(drawingMode); // radius slider EditorGUILayout.BeginHorizontal(); GUI.color = Color.black; GUILayout.Label("Radius"); GUI.color = Color.white; brushRadius = EditorGUILayout.Slider("", brushRadius, 0.1f, 5f, GUILayout.MaxWidth(128)); EditorGUILayout.EndHorizontal(); // opacity slider EditorGUILayout.BeginHorizontal(); GUI.color = Color.black; GUILayout.Label("Opacity"); GUI.color = Color.white; switch (drawingMode) { case DrawingMode.Color: colorBrushStrength = EditorGUILayout.Slider("", colorBrushStrength, 0f, 1f, GUILayout.MaxWidth(128)); break; case DrawingMode.R: redBrushStrength = EditorGUILayout.Slider("", redBrushStrength, 0f, 1f, GUILayout.MaxWidth(128)); break; case DrawingMode.G: greenBrushStrength = EditorGUILayout.Slider("", greenBrushStrength, 0f, 1f, GUILayout.MaxWidth(128)); break; case DrawingMode.B: blueBrushStrength = EditorGUILayout.Slider("", blueBrushStrength, 0f, 1f, GUILayout.MaxWidth(128)); break; case DrawingMode.Alpha: alphaBrushStrength = EditorGUILayout.Slider("", alphaBrushStrength, 0f, 1f, GUILayout.MaxWidth(128)); break; } EditorGUILayout.EndHorizontal(); switch (drawingMode) { case DrawingMode.Color: // color picker field colorBrushColor = SabreGUILayout.ColorField(new GUIContent("Color"), colorBrushColor, false, false, GUILayout.MaxWidth(183)); // color blending mode EditorGUILayout.BeginHorizontal(); GUI.color = Color.black; GUILayout.Label("Blending"); GUI.color = Color.white; colorBrushBlendingMode = (BlendingMode)EditorGUILayout.EnumPopup(colorBrushBlendingMode, GUILayout.MaxWidth(96)); EditorGUILayout.EndHorizontal(); break; case DrawingMode.R: // red color slider EditorGUILayout.BeginHorizontal(); GUI.color = Color.black; GUILayout.Label("Red"); GUI.color = Color.white; redBrushColor = EditorGUILayout.Slider("", redBrushColor, 0f, 1f, GUILayout.MaxWidth(128)); EditorGUILayout.EndHorizontal(); break; case DrawingMode.G: // green color slider EditorGUILayout.BeginHorizontal(); GUI.color = Color.black; GUILayout.Label("Green"); GUI.color = Color.white; greenBrushColor = EditorGUILayout.Slider("", greenBrushColor, 0f, 1f, GUILayout.MaxWidth(128)); EditorGUILayout.EndHorizontal(); break; case DrawingMode.B: // blue color slider EditorGUILayout.BeginHorizontal(); GUI.color = Color.black; GUILayout.Label("Blue"); GUI.color = Color.white; blueBrushColor = EditorGUILayout.Slider("", blueBrushColor, 0f, 1f, GUILayout.MaxWidth(128)); EditorGUILayout.EndHorizontal(); break; case DrawingMode.Alpha: // alpha color slider EditorGUILayout.BeginHorizontal(); GUI.color = Color.black; GUILayout.Label("Alpha"); GUI.color = Color.white; alphaBrushColor = EditorGUILayout.Slider("", alphaBrushColor, 0f, 1f, GUILayout.MaxWidth(128)); EditorGUILayout.EndHorizontal(); break; } // draw color palette: DrawToolbarPalette(); }
public override void OnGUI(Rect rect) { bool hasScale = true; bool hasConvexBrushes = true; string accept = ""; switch (popupMode) { case PopupMode.BezierDetailLevel: GUILayout.Label("Bezier Detail Level", EditorStyles.boldLabel); hasScale = false; hasConvexBrushes = false; accept = "Apply"; GUILayout.BeginHorizontal(EditorStyles.toolbar); if (GUILayout.Button("1", EditorStyles.toolbarButton, GUILayout.MinWidth(24), GUILayout.MaxWidth(24))) { bezierDetailLevel_Detail = 1; onApply(this); } if (GUILayout.Button("2", EditorStyles.toolbarButton, GUILayout.MinWidth(24), GUILayout.MaxWidth(24))) { bezierDetailLevel_Detail = 2; onApply(this); } if (GUILayout.Button("3", EditorStyles.toolbarButton, GUILayout.MinWidth(24), GUILayout.MaxWidth(24))) { bezierDetailLevel_Detail = 3; onApply(this); } if (GUILayout.Button("4", EditorStyles.toolbarButton, GUILayout.MinWidth(24), GUILayout.MaxWidth(24))) { bezierDetailLevel_Detail = 4; onApply(this); } if (GUILayout.Button("5", EditorStyles.toolbarButton, GUILayout.MinWidth(24), GUILayout.MaxWidth(24))) { bezierDetailLevel_Detail = 5; onApply(this); } if (GUILayout.Button("6", EditorStyles.toolbarButton, GUILayout.MinWidth(24), GUILayout.MaxWidth(24))) { bezierDetailLevel_Detail = 6; onApply(this); } if (GUILayout.Button("7", EditorStyles.toolbarButton, GUILayout.MinWidth(24), GUILayout.MaxWidth(24))) { bezierDetailLevel_Detail = 7; onApply(this); } if (GUILayout.Button("8", EditorStyles.toolbarButton, GUILayout.MinWidth(24), GUILayout.MaxWidth(24))) { bezierDetailLevel_Detail = 8; onApply(this); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(EditorStyles.toolbar); if (GUILayout.Button("9", EditorStyles.toolbarButton, GUILayout.MinWidth(24), GUILayout.MaxWidth(24))) { bezierDetailLevel_Detail = 9; onApply(this); } if (GUILayout.Button("10", EditorStyles.toolbarButton, GUILayout.MinWidth(24), GUILayout.MaxWidth(24))) { bezierDetailLevel_Detail = 10; onApply(this); } if (GUILayout.Button("11", EditorStyles.toolbarButton, GUILayout.MinWidth(24), GUILayout.MaxWidth(24))) { bezierDetailLevel_Detail = 11; onApply(this); } if (GUILayout.Button("12", EditorStyles.toolbarButton, GUILayout.MinWidth(24), GUILayout.MaxWidth(24))) { bezierDetailLevel_Detail = 12; onApply(this); } if (GUILayout.Button("13", EditorStyles.toolbarButton, GUILayout.MinWidth(24), GUILayout.MaxWidth(24))) { bezierDetailLevel_Detail = 13; onApply(this); } if (GUILayout.Button("14", EditorStyles.toolbarButton, GUILayout.MinWidth(24), GUILayout.MaxWidth(24))) { bezierDetailLevel_Detail = 14; onApply(this); } if (GUILayout.Button("15", EditorStyles.toolbarButton, GUILayout.MinWidth(24), GUILayout.MaxWidth(24))) { bezierDetailLevel_Detail = 15; onApply(this); } if (GUILayout.Button("16", EditorStyles.toolbarButton, GUILayout.MinWidth(24), GUILayout.MaxWidth(24))) { bezierDetailLevel_Detail = 16; onApply(this); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(EditorStyles.toolbar); if (GUILayout.Button("17", EditorStyles.toolbarButton, GUILayout.MinWidth(24), GUILayout.MaxWidth(24))) { bezierDetailLevel_Detail = 17; onApply(this); } if (GUILayout.Button("18", EditorStyles.toolbarButton, GUILayout.MinWidth(24), GUILayout.MaxWidth(24))) { bezierDetailLevel_Detail = 18; onApply(this); } if (GUILayout.Button("19", EditorStyles.toolbarButton, GUILayout.MinWidth(24), GUILayout.MaxWidth(24))) { bezierDetailLevel_Detail = 19; onApply(this); } if (GUILayout.Button("20", EditorStyles.toolbarButton, GUILayout.MinWidth(24), GUILayout.MaxWidth(24))) { bezierDetailLevel_Detail = 20; onApply(this); } if (GUILayout.Button("21", EditorStyles.toolbarButton, GUILayout.MinWidth(24), GUILayout.MaxWidth(24))) { bezierDetailLevel_Detail = 21; onApply(this); } if (GUILayout.Button("22", EditorStyles.toolbarButton, GUILayout.MinWidth(24), GUILayout.MaxWidth(24))) { bezierDetailLevel_Detail = 22; onApply(this); } if (GUILayout.Button("23", EditorStyles.toolbarButton, GUILayout.MinWidth(24), GUILayout.MaxWidth(24))) { bezierDetailLevel_Detail = 23; onApply(this); } if (GUILayout.Button("24", EditorStyles.toolbarButton, GUILayout.MinWidth(24), GUILayout.MaxWidth(24))) { bezierDetailLevel_Detail = 24; onApply(this); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(EditorStyles.toolbar); if (GUILayout.Button("25", EditorStyles.toolbarButton, GUILayout.MinWidth(24), GUILayout.MaxWidth(24))) { bezierDetailLevel_Detail = 25; onApply(this); } if (GUILayout.Button("26", EditorStyles.toolbarButton, GUILayout.MinWidth(24), GUILayout.MaxWidth(24))) { bezierDetailLevel_Detail = 26; onApply(this); } if (GUILayout.Button("27", EditorStyles.toolbarButton, GUILayout.MinWidth(24), GUILayout.MaxWidth(24))) { bezierDetailLevel_Detail = 27; onApply(this); } if (GUILayout.Button("28", EditorStyles.toolbarButton, GUILayout.MinWidth(24), GUILayout.MaxWidth(24))) { bezierDetailLevel_Detail = 28; onApply(this); } if (GUILayout.Button("29", EditorStyles.toolbarButton, GUILayout.MinWidth(24), GUILayout.MaxWidth(24))) { bezierDetailLevel_Detail = 29; onApply(this); } if (GUILayout.Button("30", EditorStyles.toolbarButton, GUILayout.MinWidth(24), GUILayout.MaxWidth(24))) { bezierDetailLevel_Detail = 30; onApply(this); } if (GUILayout.Button("31", EditorStyles.toolbarButton, GUILayout.MinWidth(24), GUILayout.MaxWidth(24))) { bezierDetailLevel_Detail = 31; onApply(this); } if (GUILayout.Button("32", EditorStyles.toolbarButton, GUILayout.MinWidth(24), GUILayout.MaxWidth(24))) { bezierDetailLevel_Detail = 32; onApply(this); } GUILayout.EndHorizontal(); bezierDetailLevel_Detail = EditorGUILayout.IntField("Detail", bezierDetailLevel_Detail); if (bezierDetailLevel_Detail < 1) { bezierDetailLevel_Detail = 1; } if (bezierDetailLevel_Detail > 999) { bezierDetailLevel_Detail = 999; } break; case PopupMode.GlobalPivotPosition: GUILayout.Label("Global Pivot Position", EditorStyles.boldLabel); hasScale = false; hasConvexBrushes = false; accept = "Set Position"; #if !UNITY_2017_2_OR_NEWER EditorGUIUtility.wideMode = true; GlobalPivotPosition_Position = Vector2Int.FloorToInt(EditorGUILayout.Vector2Field("Position", GlobalPivotPosition_Position)); EditorGUIUtility.wideMode = false; #else EditorGUIUtility.wideMode = true; GlobalPivotPosition_Position = EditorGUILayout.Vector2IntField("Position", GlobalPivotPosition_Position); EditorGUIUtility.wideMode = false; #endif break; case PopupMode.GenerateCircle: GUILayout.Label("Generate Circle", EditorStyles.boldLabel); hasScale = false; hasConvexBrushes = false; accept = "Add Shape"; GenerateCircle_Radius = SabreGUILayout.EvenIntField(new GUIContent("Radius"), GenerateCircle_Radius); bezierDetailLevel_Detail = EditorGUILayout.IntField("Detail", bezierDetailLevel_Detail); if (bezierDetailLevel_Detail < 1) { bezierDetailLevel_Detail = 1; } if (bezierDetailLevel_Detail > 999) { bezierDetailLevel_Detail = 999; } break; case PopupMode.CreatePolygon: GUILayout.Label("Create Polygon", EditorStyles.boldLabel); accept = "Create"; break; case PopupMode.RevolveShape: GUILayout.Label("Revolve Shape", EditorStyles.boldLabel); accept = "Revolve"; revolve360 = EditorGUILayout.IntField("Per 360", revolve360); if (revolve360 < 3) { revolve360 = 3; } revolveSteps = EditorGUILayout.IntField("Steps", revolveSteps); if (revolveSteps < 1) { revolveSteps = 1; } revolveSpiralSloped = EditorGUILayout.Toggle("Sloped Spiral", revolveSpiralSloped); // steps can't be more than 360. if (revolveSteps > revolve360) { revolveSteps = revolve360; } break; case PopupMode.ExtrudeShape: GUILayout.Label("Extrude Shape", EditorStyles.boldLabel); accept = "Extrude"; extrudeDepth = EditorGUILayout.FloatField("Depth", extrudeDepth); if (extrudeDepth < 0.01f) { extrudeDepth = 0.01f; } break; case PopupMode.ExtrudePoint: GUILayout.Label("Extrude Point", EditorStyles.boldLabel); accept = "Extrude"; extrudeDepth = EditorGUILayout.FloatField("Depth", extrudeDepth); if (extrudeDepth < 0.01f) { extrudeDepth = 0.01f; } break; case PopupMode.ExtrudeBevel: GUILayout.Label("Extrude Bevel", EditorStyles.boldLabel); accept = "Extrude"; extrudeDepth = EditorGUILayout.FloatField("Depth", extrudeDepth); if (extrudeDepth < 0.01f) { extrudeDepth = 0.01f; } extrudeClipDepth = EditorGUILayout.FloatField("Clip Depth", extrudeClipDepth); if (extrudeClipDepth < 0.01f) { extrudeClipDepth = 0.01f; } if (extrudeClipDepth > extrudeDepth) { extrudeClipDepth = extrudeDepth; } break; } if (hasConvexBrushes) { convexBrushes = EditorGUILayout.Toggle("Convex Brushes", convexBrushes); } if (hasScale) { EditorGUIUtility.wideMode = true; extrudeScale = EditorGUILayout.Vector2Field("Scale", extrudeScale); EditorGUIUtility.wideMode = false; if (extrudeScale.x < 0.01f) { extrudeScale.x = 0.01f; } if (extrudeScale.y < 0.01f) { extrudeScale.y = 0.01f; } } if (GUILayout.Button(accept)) { onApply(this); } }
public static void PreferencesGUI() { // Event.current.GetTypeForControl // // if(Event.current.type == EventType.KeyDown) // { // cachedEvent = new Event(Event.current); //// this.Repaint(); // } // // GUILayout.TextField(""); // // if(cachedEvent != null) // { // GUILayout.Label(cachedEvent.ToString()); // } // else // { // GUILayout.Label("No event"); // } GUILayout.Space(10); bool newHideGridInPerspective = GUILayout.Toggle(CurrentSettings.HideGridInPerspective, "Hide grid in perspective scene views"); if (newHideGridInPerspective != CurrentSettings.HideGridInPerspective) { SceneView.RepaintAll(); CurrentSettings.HideGridInPerspective = newHideGridInPerspective; } CurrentSettings.OverrideFlyCamera = GUILayout.Toggle(CurrentSettings.OverrideFlyCamera, "Linear fly camera"); EditorGUI.BeginChangeCheck(); CurrentSettings.ShowExcludedPolygons = GUILayout.Toggle(CurrentSettings.ShowExcludedPolygons, "Show excluded polygons"); if (EditorGUI.EndChangeCheck()) { // What's shown in the SceneView has potentially changed, so force it to repaint SceneView.RepaintAll(); } GUILayout.Space(10); if (GUILayout.Button("Change key mappings")) { Selection.activeObject = KeyMappings.Instance; // Show inspector EditorApplication.ExecuteMenuItem("Window/Inspector"); } // CurrentSettings.ReducedHandleThreshold = GUILayout.Toggle(CurrentSettings.ReducedHandleThreshold, "Reduced handle threshold"); GUILayout.Space(20); GUIStyle style = SabreGUILayout.GetForeStyle(); style.wordWrap = true; GUILayout.Label("Runtime CSG is a new experimental feature which allows you to create, alter and build brushes at runtime in your built applications.", style); BuildTargetGroup buildTargetGroup = EditorUserBuildSettings.selectedBuildTargetGroup; string defines = PlayerSettings.GetScriptingDefineSymbolsForGroup(buildTargetGroup); List <string> definesSplit = defines.Split(';').ToList(); bool enabled = definesSplit.Contains(RUNTIME_CSG_DEFINE); if (enabled) { if (GUILayout.Button("Disable Runtime CSG (Experimental)")) { definesSplit.Remove(RUNTIME_CSG_DEFINE); defines = string.Join(";", definesSplit.ToArray()); PlayerSettings.SetScriptingDefineSymbolsForGroup(buildTargetGroup, defines); } } else { if (GUILayout.Button("Enable Runtime CSG (Experimental)")) { if (!definesSplit.Contains(RUNTIME_CSG_DEFINE)) { definesSplit.Add(RUNTIME_CSG_DEFINE); } defines = string.Join(";", definesSplit.ToArray()); PlayerSettings.SetScriptingDefineSymbolsForGroup(buildTargetGroup, defines); } } GUILayout.FlexibleSpace(); GUILayout.Label("SabreCSG Version " + CSGModel.VERSION_STRING, SabreGUILayout.GetForeStyle()); }
void OnToolbarGUI(int windowID) { GUILayout.Label("Vertex", SabreGUILayout.GetTitleStyle()); // Button should only be enabled if there are any vertices selected GUI.enabled = selectedVertices.Count > 0; if (GUILayout.Button("Connect", EditorStyles.miniButton)) { if (selectedVertices != null) { // Cache selection Dictionary <Brush, List <Vertex> > refinedSelections = new Dictionary <Brush, List <Vertex> >(); foreach (PrimitiveBrush brush in targetBrushes) { refinedSelections.Add(brush, SelectedVerticesOfBrush(brush)); } ClearSelection(); foreach (PrimitiveBrush brush in targetBrushes) { Undo.RecordObject(brush.transform, "Connect Vertices"); Undo.RecordObject(brush, "Connect Vertices"); List <Edge> newEdges; // Polygon[] newPolygons = VertexUtility.ConnectVertices(brush.GetPolygons(), refinedSelections[brush], out newEdge); Polygon[] newPolygons = VertexUtility.ConnectVertices(brush.GetPolygons(), refinedSelections[brush], out newEdges); if (newPolygons != null) { brush.SetPolygons(newPolygons); for (int i = 0; i < newEdges.Count; i++) { SelectEdges(brush, newPolygons, newEdges[i]); } } } } } if (GUILayout.Button("Weld Selection To Mid-Point", EditorStyles.miniButton)) { if (selectedVertices != null) { Dictionary <Brush, List <Vertex> > refinedSelections = new Dictionary <Brush, List <Vertex> >(); foreach (PrimitiveBrush brush in targetBrushes) { refinedSelections.Add(brush, SelectedVerticesOfBrush(brush)); } ClearSelection(); foreach (PrimitiveBrush brush in targetBrushes) { Undo.RecordObject(brush.transform, "Weld Vertices"); Undo.RecordObject(brush, "Weld Vertices"); Polygon[] newPolygons = VertexUtility.WeldVerticesToCenter(brush.GetPolygons(), refinedSelections[brush]); if (newPolygons != null) { brush.SetPolygons(newPolygons); } SelectVertices(brush, newPolygons, refinedSelections[brush]); } } } EditorGUILayout.BeginHorizontal(); weldTolerance = EditorGUILayout.FloatField(weldTolerance); if (GUILayout.Button("Weld with Tolerance", EditorStyles.miniButton)) { if (selectedVertices != null) { Dictionary <Brush, List <Vertex> > refinedSelections = new Dictionary <Brush, List <Vertex> >(); foreach (PrimitiveBrush brush in targetBrushes) { refinedSelections.Add(brush, SelectedVerticesOfBrush(brush)); } ClearSelection(); foreach (PrimitiveBrush brush in targetBrushes) { Undo.RecordObject(brush.transform, "Weld Vertices"); Undo.RecordObject(brush, "Weld Vertices"); Polygon[] newPolygons = VertexUtility.WeldNearbyVertices(weldTolerance, brush.GetPolygons(), refinedSelections[brush]); if (newPolygons != null) { brush.SetPolygons(newPolygons); } SelectVertices(brush, newPolygons, refinedSelections[brush]); } } } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("Global Snap", EditorStyles.miniButton)) { foreach (PrimitiveBrush brush in targetBrushes) { Undo.RecordObject(brush.transform, "Snap Vertices"); Undo.RecordObject(brush, "Snap Vertices"); } SnapSelectedVertices(true); } if (GUILayout.Button("Local Snap", EditorStyles.miniButton)) { foreach (PrimitiveBrush brush in targetBrushes) { Undo.RecordObject(brush.transform, "Snap Vertices"); Undo.RecordObject(brush, "Snap Vertices"); } SnapSelectedVertices(false); } EditorGUILayout.EndHorizontal(); GUILayout.Label("Edge", SabreGUILayout.GetTitleStyle()); GUI.enabled = selectedEdges.Count > 0; if (GUILayout.Button("Connect Mid-Points", EditorStyles.miniButton)) { if (selectedEdges != null) { List <Edge> selectedEdgesCopy = new List <Edge>(selectedEdges); ClearSelection(); foreach (PrimitiveBrush brush in targetBrushes) { Undo.RecordObject(brush.transform, "Connect Mid-Points"); Undo.RecordObject(brush, "Connect Mid-Points"); Polygon[] newPolygons; List <Edge> newEdges; if (EdgeUtility.SplitPolygonsByEdges(brush.GetPolygons(), selectedEdgesCopy, out newPolygons, out newEdges)) { brush.SetPolygons(newPolygons); for (int i = 0; i < newEdges.Count; i++) { SelectEdges(brush, newPolygons, newEdges[i]); } } } } } if (GUILayout.Button("Split", EditorStyles.miniButton)) { if (selectedEdges != null) { List <KeyValuePair <Vertex, Brush> > newSelectedVertices = new List <KeyValuePair <Vertex, Brush> >(); foreach (PrimitiveBrush brush in targetBrushes) { Undo.RecordObject(brush.transform, "Split Edge"); Undo.RecordObject(brush, "Split Edge"); Polygon[] polygons = brush.GetPolygons(); for (int j = 0; j < selectedEdges.Count; j++) { // First check if this edge actually belongs to the brush Brush parentBrush = selectedVertices[selectedEdges[j].Vertex1]; if (parentBrush == brush) { for (int i = 0; i < polygons.Length; i++) { Vertex newVertex; if (EdgeUtility.SplitPolygonAtEdge(polygons[i], selectedEdges[j], out newVertex)) { newSelectedVertices.Add(new KeyValuePair <Vertex, Brush>(newVertex, brush)); } } } } brush.Invalidate(true); } ClearSelection(); for (int i = 0; i < newSelectedVertices.Count; i++) { Brush brush = newSelectedVertices[i].Value; Vertex vertex = newSelectedVertices[i].Key; SelectVertices(brush, brush.GetPolygons(), new List <Vertex>() { vertex }); } } } }