static void OnBottomBarUI(int windowID) { EditorGUI.BeginChangeCheck(); GUILayout.BeginHorizontal(); // TODO: assign hotkey to rebuild, and possibly move it elsewhere to avoid it seemingly like a necessary action. if (GUILayout.Button(rebuildButton, buttonStyle)) { Rebuild(); } GUILayout.FlexibleSpace(); CSGEditorSettings.ShowGrid = GUILayout.Toggle(CSGEditorSettings.ShowGrid, "Show Grid", toggleStyle); CSGEditorSettings.UniformSnapDistance = EditorGUILayout.FloatField(CSGEditorSettings.UniformSnapDistance, floatWidthLayout); if (GUILayout.Button(halveSnapDistanceButton, EditorStyles.miniButtonLeft)) { MultiplySnapDistance(0.5f); } if (GUILayout.Button(doubleSnapDistanceButton, EditorStyles.miniButtonRight)) { MultiplySnapDistance(2.0f); } GUILayout.EndHorizontal(); if (EditorGUI.EndChangeCheck()) { CSGEditorSettings.Save(); } }
static void OnWindowGUI(Rect position) { var togglePosition = position; togglePosition.height = kSingleLineHeight; for (int i = 0; i < editModes.Length; i++) { var editMode = editModes[i]; EditorGUI.BeginChangeCheck(); var value = GUI.Toggle(togglePosition, CSGEditModeManager.EditMode == editMode.value, editMode.content, GUI.skin.button); if (EditorGUI.EndChangeCheck() && value) { // If we're changing edit mode from a generator, we restore our previous selection. if (Instance.HaveSelection()) { Instance.RestoreSelection(skipEditMode: true); } CSGEditModeManager.EditMode = editMode.value; CSGEditorSettings.Save(); } togglePosition.y += kSingleLineHeight + kSingleSpacing; } togglePosition.y += kGeneratorSeparator; for (int i = 0; i < generatorModes.Length; i++) { var editMode = generatorModes[i]; EditorGUI.BeginChangeCheck(); var value = GUI.Toggle(togglePosition, CSGEditModeManager.EditMode == editMode.value, editMode.content, GUI.skin.button); if (EditorGUI.EndChangeCheck() && value) { // When we select a generator, we don't want anything else selected since the combination makes no sense. // We store the selection, however, if our previous edit mode was not a generator. if (CSGEditModeManager.EditMode < CSGEditMode.FirstGenerator) { Instance.RememberSelection(); } CSGEditModeManager.EditMode = editMode.value; CSGEditorSettings.Save(); } togglePosition.y += kSingleLineHeight + kSingleSpacing; } }
public static Rect OnSceneGUI(SceneView sceneView) { // TODO: put somewhere else var curSkin = EditorGUIUtility.isProSkin; if (toolbarStyle == null || prevSkin != curSkin) { toolbarStyle = new GUIStyle(EditorStyles.toolbar); toolbarStyle.fixedHeight = kBottomBarHeight; toggleStyle = new GUIStyle(EditorStyles.toolbarButton); toggleStyle.fixedHeight = kBottomBarHeight; buttonStyle = new GUIStyle(EditorStyles.toolbarButton); buttonStyle.fixedHeight = kBottomBarHeight; floatWidthLayout = GUILayout.Width(kFloatFieldWidth); prevSkin = curSkin; CSGEditorSettings.Load(); } // Calculate size of bottom bar and draw it Rect position = sceneView.position; position.x = 0; position.y = position.height - kBottomBarHeight; position.height = kBottomBarHeight; GUILayout.Window(bottomBarGuiId, position, OnBottomBarUI, "", toolbarStyle); CSGEditorUtility.ConsumeUnusedMouseEvents(BottomBarGUIHash, position); Rect dragArea = sceneView.position; dragArea.x = 0; dragArea.y = kTopBarHeight; dragArea.height -= kBottomBarHeight + kTopBarHeight; return(dragArea); }
private static void GridOnSceneGUI(SceneView sceneView) { if (Event.current.type != EventType.Repaint) { return; } if (ShowUnityGrid) { ShowUnityGrid = false; CSGEditorSettings.Load(); CSGEditorSettings.ShowGrid = false; CSGEditorSettings.Save(); } if (Tools.pivotRotation == PivotRotation.Local) { var activeTransform = Selection.activeTransform; var rotation = Tools.handleRotation; var center = (activeTransform && activeTransform.parent) ? activeTransform.parent.position : Vector3.zero; UnitySceneExtensions.Grid.defaultGrid.GridToWorldSpace = Matrix4x4.TRS(center, rotation, Vector3.one); } else { UnitySceneExtensions.Grid.defaultGrid.GridToWorldSpace = Matrix4x4.identity; } if (CSGEditorSettings.ShowGrid) { var grid = UnitySceneExtensions.Grid.HoverGrid; if (grid == null) { grid = UnitySceneExtensions.Grid.ActiveGrid; } grid.Render(sceneView); } }
private static void OnKeyboardEventCalled(KeyEventType type) { switch (type) { case KeyEventType.HalfGridSizeKey: CSGSceneBottomGUI.MultiplySnapDistance(0.5f); break; case KeyEventType.DoubleGridSizeKey: CSGSceneBottomGUI.MultiplySnapDistance(2.0f); break; // TODO: turn this into utility functions that are shared with CSGSceneBottomGUI case KeyEventType.ToggleBoundsSnappingKey: CSGEditorSettings.PivotSnapping = !CSGEditorSettings.PivotSnapping; CSGEditorSettings.Save(); break; case KeyEventType.TogglePivotSnappingKey: CSGEditorSettings.BoundsSnapping = !CSGEditorSettings.BoundsSnapping; CSGEditorSettings.Save(); break; case KeyEventType.ToggleShowGridKey: CSGEditorSettings.ShowGrid = !CSGEditorSettings.ShowGrid; CSGEditorSettings.Save(); break; } }