public static bool ToggleButton(Rect r, ToggleContent content, bool enabled, GUIStyle imageStyle, GUIStyle altStyle) { content.m_GuiContent.image = enabled ? content.imageOn : content.imageOff; content.m_GuiContent.text = content.m_GuiContent.image == null ? (enabled ? content.textOn : content.textOff) : ""; return(GUI.Button(r, content.m_GuiContent, content.m_GuiContent.image != null ? imageStyle : altStyle)); }
void DrawSceneToolbar() { Styles.Init(); var currentEvent = Event.current; // repaint scene gui if mouse is near controls if (currentEvent.type == EventType.MouseMove) { bool tmp = extendoButtonHovering; extendoButtonHovering = extendoButtonRect.Contains(currentEvent.mousePosition); if (extendoButtonHovering != tmp) { DoGridRepaint(); } mouseOverMenu = backgroundRect.Contains(currentEvent.mousePosition); } bool srgb = GL.sRGBWrite; GL.sRGBWrite = false; GUI.backgroundColor = menuBackgroundColor; backgroundRect.x = menuRect.x - 4; backgroundRect.y = 0; backgroundRect.width = menuRect.width + 8; backgroundRect.height = menuRect.y + menuRect.height + k_MenuItemPadding; GUI.Box(backgroundRect, "", Styles.backgroundStyle); // when hit testing mouse for showing the background, add some leeway backgroundRect.width += 32f; backgroundRect.height += 32f; GUI.backgroundColor = Color.white; menuRect.y = menuStart; Styles.snapIncrementContent.text = (SnapValueInGridUnits * SnapMultiplier).ToString("#.####"); if (GUI.Button(menuRect, Styles.snapIncrementContent, Styles.gridButtonStyleBlank)) { #if UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX // On Mac ShowAsDropdown and ShowAuxWindow both throw stack pop exceptions when initialized. ScenePreferencesWindow options = EditorWindow.GetWindow <ScenePreferencesWindow>(true, "ProGrids Settings", true); Rect screenRect = SceneView.lastActiveSceneView.position; options.editor = this; options.position = new Rect(screenRect.x + menuRect.x + menuRect.width + k_MenuItemPadding, screenRect.y + menuRect.y + 24, 256, 140); #else ScenePreferencesWindow options = ScriptableObject.CreateInstance <ScenePreferencesWindow>(); Rect screenRect = SceneView.lastActiveSceneView.position; options.editor = this; options.ShowAsDropDown(new Rect(screenRect.x + menuRect.x + menuRect.width + k_MenuItemPadding, screenRect.y + menuRect.y + 24, 0, 0), new Vector2(256, 140)); #endif } menuRect.y += menuRect.height + k_MenuItemPadding; // Draw grid if (ToggleContent.ToggleButton(menuRect, Styles.gridEnabledContent, m_DrawGrid, Styles.gridButtonStyle, EditorStyles.miniButton)) { SetGridEnabled(!m_DrawGrid); } menuRect.y += menuRect.height + k_MenuItemPadding; // Snap enabled if (ToggleContent.ToggleButton(menuRect, Styles.snapEnabledContent, GetSnapEnabled(), Styles.gridButtonStyle, EditorStyles.miniButton)) { SetSnapEnabled(!GetSnapEnabled()); } menuRect.y += menuRect.height + k_MenuItemPadding; // Push to grid if (ToggleContent.ToggleButton(menuRect, Styles.snapToGridContent, true, Styles.gridButtonStyle, EditorStyles.miniButton)) { SnapToGrid(Selection.transforms); } menuRect.y += menuRect.height + k_MenuItemPadding; // Lock grid if (ToggleContent.ToggleButton(menuRect, Styles.lockGridContent, m_GridIsLocked, Styles.gridButtonStyle, EditorStyles.miniButton)) { m_GridIsLocked = !m_GridIsLocked; EditorPrefs.SetBool(PreferenceKeys.LockGrid, m_GridIsLocked); EditorPrefs.SetString(PreferenceKeys.LockedGridPivot, m_Pivot.ToString()); // if we've modified the nudge value, reset the pivot here if (!m_GridIsLocked) { GridRenderOffset = 0f; } ProGridsEditor.DoGridRepaint(); } if (menuIsOrtho) { menuRect.y += menuRect.height + k_MenuItemPadding; if (ToggleContent.ToggleButton(menuRect, Styles.angleEnabledContent, m_DrawAngles, Styles.gridButtonStyle, EditorStyles.miniButton)) { SetDrawAngles(!m_DrawAngles); } } // perspective toggles menuRect.y += menuRect.height + k_MenuItemPadding + 4; if (ToggleContent.ToggleButton(menuRect, Styles.renderPlaneXContent, (m_RenderPlane & Axis.X) == Axis.X && !FullGridEnabled, Styles.gridButtonStyle, EditorStyles.miniButton)) { SetRenderPlane(Axis.X); } menuRect.y += menuRect.height + k_MenuItemPadding; if (ToggleContent.ToggleButton(menuRect, Styles.renderPlaneYContent, (m_RenderPlane & Axis.Y) == Axis.Y && !FullGridEnabled, Styles.gridButtonStyle, EditorStyles.miniButton)) { SetRenderPlane(Axis.Y); } menuRect.y += menuRect.height + k_MenuItemPadding; if (ToggleContent.ToggleButton(menuRect, Styles.renderPlaneZContent, (m_RenderPlane & Axis.Z) == Axis.Z && !FullGridEnabled, Styles.gridButtonStyle, EditorStyles.miniButton)) { SetRenderPlane(Axis.Z); } menuRect.y += menuRect.height + k_MenuItemPadding; if (ToggleContent.ToggleButton(menuRect, Styles.renderPerspectiveGridContent, FullGridEnabled, Styles.gridButtonStyle, EditorStyles.miniButton)) { FullGridEnabled = !FullGridEnabled; EditorPrefs.SetBool(PreferenceKeys.PerspGrid, FullGridEnabled); ProGridsEditor.DoGridRepaint(); } menuRect.y += menuRect.height + k_MenuItemPadding; extendoButtonRect.x = menuRect.x; extendoButtonRect.y = menuRect.y; extendoButtonRect.width = menuRect.width; extendoButtonRect.height = menuRect.height; GUI.backgroundColor = extendoButtonHovering ? extendoHoverColor : extendoNormalColor; Styles.extendMenuContent.text = extendoOpen == null ? (menuOpen ? "Close" : "Open") : ""; if (GUI.Button(menuRect, Styles.extendMenuContent, extendoOpen ? Styles.extendoStyle : Styles.gridButtonStyleBlank)) { ToggleMenuVisibility(); extendoButtonHovering = false; } GUI.backgroundColor = Color.white; GL.sRGBWrite = srgb; }