void OnEnable() { m_CurrentState = InitStateMachine(); m_IconContent = new GUIContent() { image = IconUtility.GetIcon("Tools/ShapeTool/Arch"), text = "Shape Settings", tooltip = "Shape Settings" }; Undo.undoRedoPerformed += HandleUndoRedoPerformed; MeshSelection.objectSelectionChanged += OnSelectionChanged; ToolManager.activeToolChanged += OnActiveToolChanged; m_ShapePreviewMaterial = new Material(BuiltinMaterials.defaultMaterial.shader); m_ShapePreviewMaterial.hideFlags = HideFlags.HideAndDontSave; if (m_ShapePreviewMaterial.HasProperty("_MainTex")) { m_ShapePreviewMaterial.mainTexture = (Texture2D)Resources.Load("Textures/GridBox_Default"); } if (m_ShapePreviewMaterial.HasProperty("_Color")) { m_ShapePreviewMaterial.SetColor("_Color", k_PreviewColor); } }
/** * Where @group corresponds to: * - Geo * - Object * - Selection * - Tool */ private static GUIStyle GetBackgroundStyle(string group, bool isHorizontal) { GUIStyle style; string groupKey = string.Format("{0}_{1}", group, isHorizontal ? "_horizontal" : "_vertical"); if (s_IconBackgroundStyles.TryGetValue(groupKey, out style)) { return(style); } style = CreateBackgroundStyleTemplate(); style.normal.background = IconUtility.GetIcon( string.Format("Toolbar/Background/{0}_Normal_{1}", group, isHorizontal ? "Horizontal" : "Vertical")); style.hover.background = IconUtility.GetIcon( string.Format("Toolbar/Background/{0}_Hover_{1}", group, isHorizontal ? "Horizontal" : "Vertical")); style.active.background = IconUtility.GetIcon( string.Format("Toolbar/Background/{0}_Pressed_{1}", group, isHorizontal ? "Horizontal" : "Vertical")); s_IconBackgroundStyles.Add(groupKey, style); style.margin = isHorizontal ? new RectOffset(4, 4, 4, 5) : new RectOffset(4, 3, 4, 4); style.padding = isHorizontal ? new RectOffset(3, 3, 6, 3) : new RectOffset(6, 3, 3, 3); return(style); }
void OnEnable() { m_Target = target as BezierShape; Undo.undoRedoPerformed += this.UndoRedoPerformed; s_TangentModeIcons[0] = new GUIContent(IconUtility.GetIcon("Toolbar/Bezier_Free"), "Tangent Mode: Free"); s_TangentModeIcons[1] = new GUIContent(IconUtility.GetIcon("Toolbar/Bezier_Aligned"), "Tangent Mode: Aligned"); s_TangentModeIcons[2] = new GUIContent(IconUtility.GetIcon("Toolbar/Bezier_Mirrored"), "Tangent Mode: Mirrored"); if (m_Target != null) { SetIsEditing(m_Target.isEditing); } ProBuilderEditor.selectModeChanged += SelectModeChanged; }
void OnEnable() { m_OverlayTitle = new GUIContent("Poly Shape Tool"); m_IconContent = new GUIContent() { image = IconUtility.GetIcon("Tools/PolyShape/CreatePolyShape"), text = "Create PolyShape", tooltip = "Create PolyShape" }; #if !UNITY_2020_2_OR_NEWER ToolManager.activeToolChanged += OnToolChanged; #endif ProBuilderEditor.selectModeChanged += OnSelectModeChanged; MeshSelection.objectSelectionChanged += OnObjectSelectionChanged; Undo.undoRedoPerformed += UndoRedoPerformed; }
void OnEnable() { ProBuilderEditor.selectMode = SelectMode.Face; SceneView.duringSceneGui += OnSceneGUI; MeshSelection.objectSelectionChanged += OnSelectionChanged; Undo.undoRedoPerformed += OnSelectionChanged; ProBuilderMesh.elementSelectionChanged += OnElementSelectionChanged; VertexManipulationTool.beforeMeshModification += OnBeginVertexMovement; VertexManipulationTool.afterMeshModification += OnFinishVertexMovement; autoRepaintOnSceneChange = true; m_HelpIcon = new GUIContent(IconUtility.GetIcon("Toolbar/Help"), "Open Documentation"); m_BreakSmoothingContent = new GUIContent(IconUtility.GetIcon("Toolbar/Face_BreakSmoothing"), "Clear the selected faces of their smoothing groups"); m_SelectFacesWithSmoothGroupSelectionContent = new GUIContent(IconUtility.GetIcon("Toolbar/Selection_SelectBySmoothingGroup"), "Expand the face selection by selecting all faces matching the currently selected face groups"); MeshSelection.OnObjectSelectionChanged(); OnSelectionChanged(); }
public static void Init() { if (s_Init) { return; } s_Init = true; s_SelectionRect = new GUIStyle() { normal = new GUIStyleState() { background = IconUtility.GetIcon("Scene/SelectionRect") }, border = new RectOffset(1, 1, 1, 1), margin = new RectOffset(0, 0, 0, 0), padding = new RectOffset(0, 0, 0, 0) }; }
void OnEnable() { m_Actions = EditorToolbarLoader.GetActions(true); m_ActionsLength = m_Actions.Count(); ProBuilderEditor.selectionUpdated -= OnElementSelectionChange; ProBuilderEditor.selectionUpdated += OnElementSelectionChange; EditorApplication.update -= Update; EditorApplication.update += Update; tooltipTimer.item1 = ""; tooltipTimer.item2 = 0.0; showTooltipTimer = false; scrollIconUp = IconUtility.GetIcon("Toolbar/ShowNextPage_Up"); scrollIconDown = IconUtility.GetIcon("Toolbar/ShowNextPage_Down"); scrollIconRight = IconUtility.GetIcon("Toolbar/ShowNextPage_Right"); scrollIconLeft = IconUtility.GetIcon("Toolbar/ShowNextPage_Left"); isIconMode = ProBuilderEditor.s_IsIconGui; this.window = ProBuilderEditor.instance; CalculateMaxIconSize(); }
public EditorToolbar(EditorWindow parent) { m_Actions = EditorToolbarLoader.GetActions(true); m_ActionsLength = m_Actions.Count(); EditorApplication.update -= Update; EditorApplication.update += Update; tooltipTimer.item1 = ""; tooltipTimer.item2 = 0.0; showTooltipTimer = false; scrollIconUp = IconUtility.GetIcon("Toolbar/ShowNextPage_Up"); scrollIconDown = IconUtility.GetIcon("Toolbar/ShowNextPage_Down"); scrollIconRight = IconUtility.GetIcon("Toolbar/ShowNextPage_Right"); scrollIconLeft = IconUtility.GetIcon("Toolbar/ShowNextPage_Left"); isIconMode = ProBuilderEditor.s_IsIconGui; window = parent; window.wantsMouseMove = true; window.autoRepaintOnSceneChange = true; CalculateMaxIconSize(); }
/// <summary> /// Draw a menu button. Returns true if the button is active and settings are enabled, false if settings are not enabled. /// </summary> /// <param name="isHorizontal"></param> /// <param name="showOptions"></param> /// <param name="optionsRect"></param> /// <param name="layoutOptions"></param> /// <returns></returns> internal bool DoButton(bool isHorizontal, bool showOptions, ref Rect optionsRect, params GUILayoutOption[] layoutOptions) { bool wasEnabled = GUI.enabled; bool buttonEnabled = (menuActionState & MenuActionState.Enabled) == MenuActionState.Enabled; GUI.enabled = buttonEnabled; GUI.backgroundColor = Color.white; if (iconMode) { if (GUILayout.Button(buttonEnabled || !disabledIcon ? icon : disabledIcon, ToolbarGroupUtility.GetStyle(group, isHorizontal), layoutOptions)) { if (showOptions && (optionsMenuState & MenuActionState.VisibleAndEnabled) == MenuActionState.VisibleAndEnabled) { DoAlternateAction(); } else { ActionResult result = DoAction(); EditorUtility.ShowNotification(result.notification); } } if ((optionsMenuState & MenuActionState.VisibleAndEnabled) == MenuActionState.VisibleAndEnabled) { Rect r = GUILayoutUtility.GetLastRect(); r.x = r.x + r.width - 16; r.y += 0; r.width = 14; r.height = 14; GUI.Label(r, IconUtility.GetIcon("Toolbar/Options", IconSkin.Pro), GUIStyle.none); optionsRect = r; GUI.enabled = wasEnabled; return(buttonEnabled); } else { GUI.enabled = wasEnabled; return(false); } } else { GUI.backgroundColor = ToolbarGroupUtility.GetColor(group); // in text mode always use the vertical layout. isHorizontal = false; GUILayout.BeginHorizontal(MenuActionStyles.rowStyleVertical, layoutOptions); if (GUILayout.Button(menuTitle, MenuActionStyles.buttonStyleVertical)) { ActionResult res = DoAction(); EditorUtility.ShowNotification(res.notification); } MenuActionState altState = optionsMenuState; if ((altState & MenuActionState.Visible) == MenuActionState.Visible) { GUI.enabled = GUI.enabled && (altState & MenuActionState.Enabled) == MenuActionState.Enabled; if (DoAltButton(GUILayout.MaxWidth(21), GUILayout.MaxHeight(16))) { DoAlternateAction(); } } GUILayout.EndHorizontal(); GUI.backgroundColor = Color.white; GUI.enabled = wasEnabled; return(false); } }
/// <summary> /// Draw a menu button. Returns true if the button is active and settings are enabled, false if settings are not enabled. /// </summary> /// <param name="isHorizontal"></param> /// <param name="showOptions"></param> /// <param name="optionsRect"></param> /// <param name="layoutOptions"></param> /// <returns></returns> internal override bool DoButton(bool isHorizontal, bool showOptions, ref Rect optionsRect, params GUILayoutOption[] layoutOptions) { bool wasEnabled = GUI.enabled; bool buttonEnabled = (menuActionState & MenuActionState.Enabled) == MenuActionState.Enabled; bool isActiveTool = m_Tool != null && ToolManager.IsActiveTool(m_Tool); GUI.enabled = buttonEnabled; GUI.backgroundColor = Color.white; if (iconMode) { GUIStyle style = ToolbarGroupUtility.GetStyle(group, isHorizontal); Texture2D normalTex = style.normal.background; Texture2D hoverTex = style.hover.background; if (isActiveTool) { style.normal.background = hoverTex; style.hover.background = normalTex; } bool isToggled = GUILayout.Toggle(isActiveTool, buttonEnabled || !disabledIcon ? icon : disabledIcon, style, layoutOptions); if (isToggled != isActiveTool) { if (showOptions && (optionsMenuState & MenuActionState.VisibleAndEnabled) == MenuActionState.VisibleAndEnabled) { DoAlternateAction(); } else { var result = isActiveTool ? EndActivation() : StartActivation(); EditorUtility.ShowNotification(result.notification); } } style.normal.background = normalTex; style.hover.background = hoverTex; if ((optionsMenuState & MenuActionState.VisibleAndEnabled) == MenuActionState.VisibleAndEnabled) { Rect r = GUILayoutUtility.GetLastRect(); r.x = r.x + r.width - 16; r.y += 0; r.width = 14; r.height = 14; GUI.Label(r, IconUtility.GetIcon("Toolbar/Options", IconSkin.Pro), GUIStyle.none); optionsRect = r; GUI.enabled = wasEnabled; return(buttonEnabled); } else { GUI.enabled = wasEnabled; return(false); } } else { // in text mode always use the vertical layout. isHorizontal = false; GUILayout.BeginHorizontal(MenuActionStyles.rowStyleVertical, layoutOptions); GUI.backgroundColor = ToolbarGroupUtility.GetColor(group); GUIStyle style = MenuActionStyles.buttonStyleVertical; RectOffset border = new RectOffset(style.border.left, style.border.right, style.border.top, style.border.bottom); if (isActiveTool) { style.border = new RectOffset(0, 4, 0, 0); } bool isToggled = GUILayout.Toggle(isActiveTool, menuTitle, style); if (isToggled != isActiveTool) { var result = isActiveTool ? EndActivation() : StartActivation(); EditorUtility.ShowNotification(result.notification); } MenuActionState altState = optionsMenuState; if ((altState & MenuActionState.Visible) == MenuActionState.Visible) { GUI.enabled = GUI.enabled && (altState & MenuActionState.Enabled) == MenuActionState.Enabled; if (DoAltButton(GUILayout.MaxWidth(21), GUILayout.MaxHeight(16))) { DoAlternateAction(); } } style.border = border; GUILayout.EndHorizontal(); GUI.backgroundColor = Color.white; GUI.enabled = wasEnabled; return(false); } }