void Initialize() { s_Instance = this; RegisterDelegates(); // this can fail on the first import to a new project when the toolbar was opened in a previous project. // the editor scripts compile and run before unity has a chance to load the resources, resulting in no assets // being loaded and the toolbar not rendering properly. don't throw an error because it only occurs in a very // specific scenario, and recovers immediately (it will reload correctly after the assets finish importing) if (!GridRenderer.Init()) { Destroy(); return; } LoadPreferences(); lastTime = Time.realtimeSinceStartup; SetMenuIsExtended(menuOpen); OnSelectionChange(); if (m_DrawGrid) { EditorUtility.SetUnityGridEnabled(false); } DoGridRepaint(); }
void Destroy() { GridRenderer.Destroy(); UnregisterDelegates(); foreach (Action <bool> listener in toolbarEventSubscribers) { listener(false); } EditorUtility.SetUnityGridEnabled(true); s_Instance = null; SceneView.RepaintAll(); }
public static void SetPreferences() { EditorPrefs.SetString(PreferenceKeys.GridColorX, JsonUtility.ToJson(s_GridColorX)); EditorPrefs.SetString(PreferenceKeys.GridColorY, JsonUtility.ToJson(s_GridColorY)); EditorPrefs.SetString(PreferenceKeys.GridColorZ, JsonUtility.ToJson(s_GridColorZ)); EditorPrefs.SetFloat(PreferenceKeys.AlphaBump, s_AlphaBump); EditorPrefs.SetFloat(PreferenceKeys.BracketIncreaseValue, s_BracketIncreaseValue); EditorPrefs.SetInt(PreferenceKeys.GridUnit, (int)s_GridUnits); EditorPrefs.SetBool(PreferenceKeys.SyncUnitySnap, s_SyncUnitySnap); EditorPrefs.SetInt(PreferenceKeys.IncreaseGridSize, (int)s_IncreaseGridSize); EditorPrefs.SetInt(PreferenceKeys.DecreaseGridSize, (int)s_DecreaseGridSize); EditorPrefs.SetInt(PreferenceKeys.NudgePerspectiveBackward, (int)s_NudgePerspectiveBackward); EditorPrefs.SetInt(PreferenceKeys.NudgePerspectiveForward, (int)s_NudgePerspectiveForward); EditorPrefs.SetInt(PreferenceKeys.ResetGridShortcutModifiers, (int)s_NudgePerspectiveReset); EditorPrefs.SetInt(PreferenceKeys.CyclePerspective, (int)s_CyclePerspective); EditorPrefs.SetInt(PreferenceKeys.SnapMethod, (int)s_SnapMethod); if (ProGridsEditor.Instance != null) { GridRenderer.LoadPreferences(); ProGridsEditor.Instance.LoadPreferences(); ProGridsEditor.DoGridRepaint(); } }
public static void InitProGrids() { ProGridsEditor.Init(); SceneView.RepaintAll(); }
public static void MenuNudgePerspectiveReset() { ProGridsEditor.MenuNudgePerspectiveReset(); }
public static void MenuNudgePerspectiveForward() { ProGridsEditor.MenuNudgePerspectiveForward(); }
public static bool VerifyMenuNudgePerspective() { return(ProGridsEditor.IsEnabled() && !ProGridsEditor.Instance.FullGridEnabled && !ProGridsEditor.Instance.gridIsOrthographic && ProGridsEditor.Instance.GridIsLocked); }
public static void IncreaseGridSize() { ProGridsEditor.IncreaseGridSize(); }
public static void DecreaseGridSize() { ProGridsEditor.DecreaseGridSize(); }
public static void CyclePerspective() { ProGridsEditor.CyclePerspective(); }
public static void CloseProGrids() { ProGridsEditor.Close(); }
public static bool VerifyCloseProGrids() { return(ProGridsEditor.IsEnabled()); }
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; }
/// <summary> /// Remembers whether or not ProGrids was open when Unity was shut down last. This happens when Unity opens. /// </summary> static ProGridsInitializer() { ProGridsEditor.InitIfEnabled(); PlayModeStateListener.onEnterEditMode += ProGridsEditor.InitIfEnabled; PlayModeStateListener.onEnterPlayMode += ProGridsEditor.DestroyIfEnabled; }
void OnGUI() { if (editor == null) { editor = ProGridsEditor.Instance; if (editor == null) { Close(); return; } } GUILayout.Label("Snap Settings", EditorStyles.boldLabel); float snap = editor.SnapValueInGridUnits * editor.SnapMultiplier; EditorGUI.BeginChangeCheck(); string previousControl = GUI.GetNameOfFocusedControl(); GUI.SetNextControlName(k_SnapFieldControlName); snap = EditorGUILayout.FloatField("Snap Value", snap); if (EditorGUI.EndChangeCheck() || (GUI.GetNameOfFocusedControl().Equals(k_SnapFieldControlName) && !previousControl.Equals(k_SnapFieldControlName))) { editor.SnapModifier = Defaults.DefaultSnapMultiplier; editor.SnapValueInGridUnits = snap; } editor.ScaleSnapEnabled = EditorGUILayout.Toggle("Snap On Scale", editor.ScaleSnapEnabled); bool snapAsGroup = editor.SnapAsGroupEnabled; snapAsGroup = EditorGUILayout.Toggle(m_SnapAsGroup, snapAsGroup); if (snapAsGroup != editor.SnapAsGroupEnabled) { editor.SnapAsGroupEnabled = snapAsGroup; } EditorGUI.BeginChangeCheck(); EditorGUI.BeginChangeCheck(); editor.AngleValue = EditorGUILayout.Slider("Angle", editor.AngleValue, 0f, 180f); if (EditorGUI.EndChangeCheck()) { SceneView.RepaintAll(); } bool tmp = editor.PredictiveGrid; tmp = EditorGUILayout.Toggle(m_PredictiveGrid, tmp); if (tmp != editor.PredictiveGrid) { editor.PredictiveGrid = tmp; EditorPrefs.SetBool(PreferenceKeys.PredictiveGrid, tmp); } GUILayout.FlexibleSpace(); if (GUILayout.Button("Done")) { Close(); } }