/// <summary> /// コンストラクタ /// </summary> /// <param name="color">色</param> /// <param name="cursor">マウスカーソル</param> /// <param name="size">サイズ</param> /// <param name="getAnchor">表示位置取得デリゲート</param> /// <param name="alignment">ハンドルの配置</param> public ResizeHandle(Color color, Cursor cursor, Size size, Func<Point> getAnchor, HandleAlignment alignment) { this.Bounds = new Rectangle(new Point(), size); this.GetAnchor = getAnchor; this.Cursor = cursor; this.Color = color; this.Alignment = alignment; }
/// <summary> /// コンストラクタ /// </summary> /// <param name="color">色</param> /// <param name="cursor">マウスカーソル</param> /// <param name="size">サイズ</param> /// <param name="getAnchor">表示位置取得デリゲート</param> /// <param name="alignment">ハンドルの配置</param> public ResizeHandle(Color color, Cursor cursor, Size size, Func <Point> getAnchor, HandleAlignment alignment) { this.Bounds = new Rectangle(new Point(), size); this.GetAnchor = getAnchor; this.Cursor = cursor; this.Color = color; this.Alignment = alignment; }
public static void DrawTexture(Texture2D texture, Vector2 position, HandleAlignment alignment) { Vector2 offset = position; switch (alignment) { case HandleAlignment.TopCenter: offset -= new Vector2(texture.width / 2, 0); break; case HandleAlignment.TopRight: offset -= new Vector2(texture.width, 0); break; case HandleAlignment.Left: offset -= new Vector2(0, texture.height / 2); break; case HandleAlignment.Center: offset -= new Vector2(texture.width / 2, texture.height / 2); break; case HandleAlignment.Right: offset -= new Vector2(texture.width, texture.height / 2); break; case HandleAlignment.BottomLeft: offset -= new Vector2(0, texture.height); break; case HandleAlignment.BottomCenter: offset -= new Vector2(texture.width / 2, texture.height); break; case HandleAlignment.BottomRight: offset -= new Vector2(texture.width, texture.height); break; } GUI.DrawTexture(new Rect(offset.x, offset.y, texture.width, texture.height), texture); }
void OnGUI() { Event e = Event.current; /// Different than OnSceneGUI currentEvent ? switch(e.type) { case EventType.ContextClick: OpenContextMenu(); break; } if(!guiInitialized) { eye_style = new GUIStyle( EditorStyles.miniButtonRight ); eye_style.padding = new RectOffset(0,0,0,0); } if(!pref_showToolbar) { int t_selectionMode = editLevel != EditLevel.Top ? (int)selectionMode : -1; elementModeToolbarRect.x = (Screen.width/2 - 48) + (isFloatingWindow ? 1 : -1); EditorGUI.BeginChangeCheck(); t_selectionMode = GUI.Toolbar(elementModeToolbarRect, (int)t_selectionMode, EditModeIcons, "Command"); if(EditorGUI.EndChangeCheck()) { if(t_selectionMode == (int)selectionMode && editLevel != EditLevel.Top) { SetEditLevel( EditLevel.Top ); } else { if(editLevel == EditLevel.Top) SetEditLevel( EditLevel.Geometry ); SetSelectionMode( (SelectMode)t_selectionMode ); selectionMode = (SelectMode)t_selectionMode; } } #if UNITY_5 GUILayout.Space( isFloatingWindow ? 30 : 34 ); #else GUILayout.Space( isFloatingWindow ? 28 : 34 ); #endif GUI.backgroundColor = pb_Constant.ProBuilderDarkGray; pb_GUI_Utility.DrawSeparator(2); GUI.backgroundColor = Color.white; } if(editLevel == EditLevel.Geometry) { GUILayout.Label("Selection", EditorStyles.boldLabel); EditorGUI.BeginChangeCheck(); handleAlignment = (HandleAlignment)EditorGUILayout.EnumPopup(new GUIContent("", "Toggle between Global, Local, and Plane Coordinates"), handleAlignment); if(EditorGUI.EndChangeCheck()) SetHandleAlignment(handleAlignment); EditorGUI.BeginChangeCheck(); if( GUILayout.Button(pref_backfaceSelect ? "Select All" : "Select Visible", EditorStyles.miniButton) ) pref_backfaceSelect = !pref_backfaceSelect; if(EditorGUI.EndChangeCheck()) EditorPrefs.SetBool(pb_Constant.pbEnableBackfaceSelection, pref_backfaceSelect); } scroll = GUILayout.BeginScrollView(scroll); #region Tools GUILayout.Label("Tools", EditorStyles.boldLabel); GUI.backgroundColor = pb_Constant.ProBuilderDarkGray; pb_GUI_Utility.DrawSeparator(1); GUI.backgroundColor = Color.white; if(GUILayout.Button(new GUIContent("Shape", "Open Shape Creation Panel"), EditorStyles.miniButton)) pb_Geometry_Interface.MenuOpenShapeCreator(); #if !PROTOTYPE if(GUILayout.Button(new GUIContent("Material", "Open Material Editor Window. You can also Drag and Drop materials or textures to selected faces."), EditorStyles.miniButton)) pb_Material_Editor.MenuOpenMaterialEditor(); #endif #if !PROTOTYPE if(GUILayout.Button(new GUIContent("UV Editor", "Open UV Editor Window"), EditorStyles.miniButton)) pb_UV_Editor.MenuOpenUVEditor(); #endif tool_vertexColors = pb_GUI_Utility.ToolSettingsGUI("Vertex Colors", "Open the vertex color editor. Assign colors by face and selection with the Color Palette, or paint with a brush using the Color Painter.", tool_vertexColors, pb_Menu_Commands.MenuOpenVertexColorsEditor, pb_Menu_Commands.VertexColorsGUI, Screen.width, 36, selection); #if !PROTOTYPE if(GUILayout.Button("Smoothing", EditorStyles.miniButton)) pb_Smoothing_Editor.Init(); #endif #endregion GUILayout.Label("Actions", EditorStyles.boldLabel); GUILayout.Space(2); GUI.backgroundColor = pb_Constant.ProBuilderDarkGray; pb_GUI_Utility.DrawSeparator(1); GUI.backgroundColor = Color.white; GUILayout.Space(2); #region Top if(editLevel == EditLevel.Top) { #if !PROTOTYPE GUI.enabled = true; if(GUILayout.Button(new GUIContent("Merge", "Combine all selected ProBuilder objects into a single object."), EditorStyles.miniButton)) pb_Menu_Commands.MenuMergeObjects(selection); if(GUILayout.Button(new GUIContent("Mirror", "Open the Mirror Tool panel."), EditorStyles.miniButton)) EditorWindow.GetWindow<pb_Mirror_Tool>(true, "Mirror Tool", true).Show(); #endif if(GUILayout.Button(new GUIContent("Flip Normal", "If Top level, entire object normals are reversed. Else only selected face normals are flipped."), EditorStyles.miniButton)) pb_Menu_Commands.MenuFlipNormals(selection); #if !PROTOTYPE if(GUILayout.Button("Subdivide", EditorStyles.miniButton)) pb_Menu_Commands.MenuSubdivide(selection); if(GUILayout.Button("Set Pivot", EditorStyles.miniButton)) pb_Menu_Commands.MenuSetPivot(selection); GUILayout.Space(2); GUI.backgroundColor = pb_Constant.ProBuilderDarkGray; pb_GUI_Utility.DrawSeparator(1); GUI.backgroundColor = Color.white; GUILayout.Space(2); // Boolean operations // @todo Remove! // if(GUILayout.Button("Union")) // pb_Menu_Commands.MenuUnion(selection); // if(GUILayout.Button("Subtract")) // pb_Menu_Commands.MenuSubtract(selection); // if(GUILayout.Button("Intersect")) // pb_Menu_Commands.MenuIntersect(selection); #endif GUI.enabled = !EditorApplication.isPlaying; GUILayout.BeginHorizontal(); if(GUILayout.Button("Set Detail", EditorStyles.miniButtonLeft)) { pb_Menu_Commands.MenuSetEntityType(selection, EntityType.Detail); ToggleEntityVisibility(EntityType.Detail, show_Detail); } if(GUILayout.Button( show_Detail ? eye_on : eye_off, eye_style, GUILayout.MinWidth(28), GUILayout.MaxWidth(28), GUILayout.MaxHeight(15) )) { show_Detail = !show_Detail; EditorPrefs.SetBool(pb_Constant.pbShowDetail, show_Detail); ToggleEntityVisibility(EntityType.Detail, show_Detail); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); if(GUILayout.Button("Set Mover", EditorStyles.miniButtonLeft)) { pb_Menu_Commands.MenuSetEntityType(selection, EntityType.Mover); ToggleEntityVisibility(EntityType.Mover, show_Mover); } if(GUILayout.Button( show_Mover ? eye_on : eye_off, eye_style, GUILayout.MinWidth(28), GUILayout.MaxWidth(28), GUILayout.MaxHeight(15) )) { show_Mover = !show_Mover; EditorPrefs.SetBool(pb_Constant.pbShowMover, show_Mover); ToggleEntityVisibility(EntityType.Mover, show_Mover); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); if(GUILayout.Button("Set Collider", EditorStyles.miniButtonLeft)) { pb_Menu_Commands.MenuSetEntityType(selection, EntityType.Collider); ToggleEntityVisibility(EntityType.Collider, show_Collider); } if(GUILayout.Button( show_Collider ? eye_on : eye_off, eye_style, GUILayout.MinWidth(28), GUILayout.MaxWidth(28), GUILayout.MaxHeight(15) )) { show_Collider = !show_Collider; EditorPrefs.SetBool(pb_Constant.pbShowCollider, show_Collider); ToggleEntityVisibility(EntityType.Collider, show_Collider); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); if(GUILayout.Button("Set Trigger", EditorStyles.miniButtonLeft)) { pb_Menu_Commands.MenuSetEntityType(selection, EntityType.Trigger); ToggleEntityVisibility(EntityType.Trigger, show_Trigger); } if(GUILayout.Button( show_Trigger ? eye_on : eye_off, eye_style, GUILayout.MinWidth(28), GUILayout.MaxWidth(28), GUILayout.MaxHeight(15) )) { show_Trigger = !show_Trigger; EditorPrefs.SetBool(pb_Constant.pbShowTrigger, show_Trigger); ToggleEntityVisibility(EntityType.Trigger, show_Trigger); } GUILayout.EndHorizontal(); GUILayout.Space(3); GUI.backgroundColor = pb_Constant.ProBuilderDarkGray; pb_GUI_Utility.DrawSeparator(1); GUI.backgroundColor = Color.white; GUILayout.Space(3); GUI.enabled = true; } #endregion #region Geometry // Soft Select // Soft Selection Distance Value // Soft Selection Falloff Value // Use Angle // Angle Value GUI.enabled = true; if(editLevel != EditLevel.Top) { /******************************************************** * Selection * ********************************************************/ GUI.enabled = selectedVertexCount > 0; tool_growSelection = pb_GUI_Utility.ToolSettingsGUI("Grow", "Adds adjacent faces to the current selection. Optionally can restrict augmentation to faces within a restricted angle difference.", tool_growSelection, pb_Menu_Commands.MenuGrowSelection, pb_Menu_Commands.GrowSelectionGUI, selectionMode == SelectMode.Face, Screen.width, 54, selection); if(GUILayout.Button("Shrink", EditorStyles.miniButton)) pb_Menu_Commands.MenuShrinkSelection(selection); if(GUILayout.Button("Invert", EditorStyles.miniButton)) pb_Menu_Commands.MenuInvertSelection(selection); /******************************************************** * Edge Level * ********************************************************/ if(selectionMode == SelectMode.Edge) { GUI.enabled = selectedEdgeCount > 0; if(GUILayout.Button("Loop", EditorStyles.miniButton)) pb_Menu_Commands.MenuLoopSelection(selection); if(GUILayout.Button("Ring", EditorStyles.miniButton)) pb_Menu_Commands.MenuRingSelection(selection); } /******************************************************** * Face Level * ********************************************************/ if(editLevel == EditLevel.Geometry) { GUI.backgroundColor = pb_Constant.ProBuilderDarkGray; GUILayout.Space(2); pb_GUI_Utility.DrawSeparator(1); GUILayout.Space(2); GUI.backgroundColor = Color.white; /******************************************************** * Always Show * ********************************************************/ GUI.enabled = selectedVertexCount > 0; if(GUILayout.Button(new GUIContent("Set Pivot", "Set the pivot of selected geometry to the center of the current element selection."), EditorStyles.miniButton)) pb_Menu_Commands.MenuSetPivot(selection); GUI.enabled = selectedFaceCount > 0 || selectedEdgeCount > 0; tool_extrudeButton = pb_GUI_Utility.ToolSettingsGUI("Extrude", "Extrude the currently selected elements by a set amount. Also try holding 'Shift' while moving the handle tool.", tool_extrudeButton, pb_Menu_Commands.MenuExtrude, pb_Menu_Commands.ExtrudeButtonGUI, Screen.width, 36, selection); GUI.enabled = selectedFaceCount > 0; #if !PROTOTYPE if(GUILayout.Button("Flip Normals", EditorStyles.miniButton)) pb_Menu_Commands.MenuFlipNormals(selection); if(GUILayout.Button("Delete", EditorStyles.miniButton)) pb_Menu_Commands.MenuDeleteFace(selection); if(GUILayout.Button("Detach", EditorStyles.miniButton)) pb_Menu_Commands.MenuDetachFacesContext(selection); GUI.enabled = selectedFaceCount > 1; if(GUILayout.Button("Merge Faces", EditorStyles.miniButton)) pb_Menu_Commands.MenuMergeFaces(selection); switch(selectionMode) { case SelectMode.Face: GUI.enabled = selectedFaceCount > 0; if(GUILayout.Button("Subdiv Face", EditorStyles.miniButton)) pb_Menu_Commands.MenuSubdivideFace(selection); break; case SelectMode.Edge: GUI.enabled = selectedEdgeCount == 2; if(GUILayout.Button("Bridge", EditorStyles.miniButton)) pb_Menu_Commands.MenuBridgeEdges(selection); GUI.enabled = selectedEdgeCount > 1; if(GUILayout.Button("Connect", EditorStyles.miniButton)) pb_Menu_Commands.MenuConnectEdges(selection); GUI.enabled = selectedEdgeCount > 0; if(GUILayout.Button(new GUIContent("Insert Loop", "Inserts an Edge loop by selecting the edge ring, then connecting the centers of all edges."), EditorStyles.miniButton)) pb_Menu_Commands.MenuInsertEdgeLoop(selection); break; case SelectMode.Vertex: GUI.enabled = per_object_vertexCount_distinct > 1; if(GUILayout.Button("Connect", EditorStyles.miniButton)) pb_Menu_Commands.MenuConnectVertices(selection); tool_weldButton = pb_GUI_Utility.ToolSettingsGUI("Weld", "Merge selected vertices that are within a specified distance of one another.", tool_weldButton, pb_Menu_Commands.MenuWeldVertices, pb_Menu_Commands.WeldButtonGUI, Screen.width, 20, selection); if(GUILayout.Button("Collapse", EditorStyles.miniButton)) pb_Menu_Commands.MenuCollapseVertices(selection); GUI.enabled = per_object_vertexCount_distinct > 0; if(GUILayout.Button("Split", EditorStyles.miniButton)) pb_Menu_Commands.MenuSplitVertices(selection); break; } #endif } } GUI.enabled = true; #if PB_DEBUG && BUGGER GUILayout.Space(4); GUI.backgroundColor = pb_Constant.ProBuilderDarkGray; pb_GUI_Utility.DrawSeparator(2); GUI.backgroundColor = Color.white; GUILayout.Space(4); if(GUILayout.Button("times",GUILayout.MinWidth(20))) { } if(GUILayout.Button("reset",GUILayout.MinWidth(20))) { } #endif #endregion GUILayout.EndScrollView(); }
/** * Changes the current Editor level - switches between Object, Sub-object, and Texture (hidden). */ public void SetEditLevel(EditLevel el) { previousEditLevel = editLevel; editLevel = el; switch(el) { case EditLevel.Top: ClearFaceSelection(); UpdateSelection(true); SetSelection(Selection.gameObjects); break; case EditLevel.Geometry: Tools.current = Tool.None; UpdateSelection(false); SceneView.RepaintAll(); break; case EditLevel.Plugin: UpdateSelection(false); SceneView.RepaintAll(); break; #if !PROTOTYPE case EditLevel.Texture: previousHandleAlignment = handleAlignment; previousSelectMode = selectionMode; SetHandleAlignment(HandleAlignment.Plane); break; #endif } #if !PROTOTYPE if(previousEditLevel == EditLevel.Texture && el != EditLevel.Texture) { SetSelectionMode(previousSelectMode); SetHandleAlignment(previousHandleAlignment); } #endif if(editLevel != EditLevel.Texture) EditorPrefs.SetInt(pb_Constant.pbDefaultEditLevel, (int)editLevel); }
public void SetHandleAlignment(HandleAlignment ha) { if(editLevel == EditLevel.Texture) ha = HandleAlignment.Plane; else EditorPrefs.SetInt(pb_Constant.pbHandleAlignment, (int)ha); handleAlignment = ha; UpdateHandleRotation(); currentHandleRotation = handleRotation; SceneView.RepaintAll(); // todo Repaint(); }
private void LoadPrefs() { // this exists to force update preferences when updating packages if(!EditorPrefs.HasKey(pb_Constant.pbEditorPrefVersion) || EditorPrefs.GetInt(pb_Constant.pbEditorPrefVersion) != EDITOR_PREF_VERSION ) { EditorPrefs.SetInt(pb_Constant.pbEditorPrefVersion, EDITOR_PREF_VERSION); EditorPrefs.DeleteKey(pb_Constant.pbVertexHandleSize); EditorPrefs.DeleteKey(pb_Constant.pbDefaultFaceColor); EditorPrefs.DeleteKey(pb_Constant.pbDefaultEdgeColor); EditorPrefs.DeleteKey(pb_Constant.pbDefaultSelectedVertexColor); EditorPrefs.DeleteKey(pb_Constant.pbDefaultVertexColor); } editLevel = pb_Preferences_Internal.GetEnum<EditLevel>(pb_Constant.pbDefaultEditLevel); selectionMode = pb_Preferences_Internal.GetEnum<SelectMode>(pb_Constant.pbDefaultSelectionMode); handleAlignment = pb_Preferences_Internal.GetEnum<HandleAlignment>(pb_Constant.pbHandleAlignment); pref_showSceneInfo = pb_Preferences_Internal.GetBool(pb_Constant.pbShowSceneInfo); pref_backfaceSelect = pb_Preferences_Internal.GetBool(pb_Constant.pbEnableBackfaceSelection); pref_snapEnabled = pb_ProGrids_Interface.SnapEnabled(); pref_snapValue = pb_ProGrids_Interface.SnapValue(); pref_snapAxisConstraints = pb_ProGrids_Interface.UseAxisConstraints(); shortcuts = pb_Shortcut.ParseShortcuts(EditorPrefs.GetString(pb_Constant.pbDefaultShortcuts)).ToArray(); limitFaceDragCheckToSelection = pb_Preferences_Internal.GetBool(pb_Constant.pbDragCheckLimit); pref_showToolbar = pb_Preferences_Internal.GetBool(pb_Constant.pbShowSceneToolbar); pref_sceneToolbarLocation = pb_Preferences_Internal.GetEnum<SceneToolbarLocation>(pb_Constant.pbToolbarLocation); }