private void OnSelectionChange() { if (m_target != null) { m_target.edited = m_target.editing; m_target.editing = false; } m_target = null; m_active = null; if (Selection.activeGameObject != null) { m_target = Selection.activeGameObject.GetComponent <NormalPainter>(); if (m_target) { m_target.editing = m_target.edited; } else { var activeGameObject = Selection.activeGameObject; if (Selection.activeGameObject.GetComponent <MeshRenderer>() != null || Selection.activeGameObject.GetComponent <SkinnedMeshRenderer>() != null) { m_active = activeGameObject; } } } Repaint(); }
void DrawEditPanel() { var settings = m_target.settings; EditorGUILayout.BeginHorizontal(); EditorGUILayout.BeginVertical(GUILayout.Width(indentSize)); EditorGUILayout.Space(); EditorGUILayout.EndVertical(); EditorGUILayout.BeginVertical(GUILayout.Width(c1Width)); { var prev = settings.editMode; settings.editMode = (EditMode)GUILayout.SelectionGrid((int)settings.editMode, strCommands, 1); if (settings.editMode != prev) { switch (settings.editMode) { case EditMode.Select: case EditMode.Assign: case EditMode.Move: case EditMode.Rotate: case EditMode.Scale: case EditMode.Smooth: case EditMode.Projection: case EditMode.Reset: tips = "Shift+LB: Add selection, Ctrl+LB: Subtract selection"; break; case EditMode.Brush: tips = "Shift+Wheel: Change radius, Ctrl+Wheel: Change strength"; break; } } } EditorGUILayout.EndVertical(); EditorGUILayout.BeginVertical(GUILayout.Width(spaceSize)); EditorGUILayout.Space(); EditorGUILayout.EndVertical(); EditorGUILayout.BeginVertical(); if (settings.editMode == EditMode.Select) { settings.selectMode = (SelectMode)GUILayout.SelectionGrid((int)settings.selectMode, strSelectMode, 4); EditorGUILayout.Space(); if (settings.selectMode == SelectMode.Brush) { DrawBrushPanel(); } else { if (settings.selectMode == SelectMode.Single) { GUILayout.BeginHorizontal(); settings.selectVertex = GUILayout.Toggle(settings.selectVertex, "Vertex", "Button"); settings.selectTriangle = GUILayout.Toggle(settings.selectTriangle, "Triangle", "Button"); GUILayout.EndHorizontal(); } settings.selectFrontSideOnly = EditorGUILayout.Toggle("Front Side Only", settings.selectFrontSideOnly); } EditorGUILayout.Space(); GUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Save", GUILayout.Width(50)); for (int i = 0; i < 5; ++i) { if (GUILayout.Button((i + 1).ToString())) { settings.selectionSets[i].selection = m_target.selection; } } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Load", GUILayout.Width(50)); for (int i = 0; i < 5; ++i) { if (GUILayout.Button((i + 1).ToString())) { m_target.selection = settings.selectionSets[i].selection; } } GUILayout.EndHorizontal(); EditorGUILayout.Space(); GUILayout.BeginHorizontal(); GUILayout.Space(EditorGUI.indentLevel * indentSize); if (GUILayout.Button("Select All [A]")) { if (m_target.SelectAll()) { m_target.UpdateSelection(); } } if (GUILayout.Button("Clear Selection [C]")) { if (m_target.ClearSelection()) { m_target.UpdateSelection(); } } GUILayout.EndHorizontal(); } else if (settings.editMode == EditMode.Brush) { settings.brushMode = (BrushMode)GUILayout.SelectionGrid((int)settings.brushMode, strBrushTypes, 4); EditorGUILayout.Space(); DrawBrushPanel(); EditorGUILayout.Space(); if (settings.brushMode == BrushMode.Paint) { } else if (settings.brushMode == BrushMode.Replace) { GUILayout.BeginHorizontal(); settings.primary = EditorGUILayout.ColorField(settings.primary, GUILayout.Width(35)); settings.primary = NormalPainter.ToColor(EditorGUILayout.Vector3Field("", NormalPainter.ToVector(settings.primary))); settings.pickNormal = GUILayout.Toggle(settings.pickNormal, "Pick [P]", "Button", GUILayout.Width(90)); GUILayout.EndHorizontal(); } } else if (settings.editMode == EditMode.Assign) { settings.assignValue = EditorGUILayout.Vector3Field("Value", settings.assignValue); GUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Coordinate", GUILayout.Width(EditorGUIUtility.labelWidth)); settings.coordinate = (Coordinate)GUILayout.SelectionGrid((int)settings.coordinate, strCoodinate, strCoodinate.Length); GUILayout.EndHorizontal(); if (GUILayout.Button("Assign")) { m_target.ApplyAssign(settings.assignValue, settings.coordinate); m_target.PushUndo(); } } else if (settings.editMode == EditMode.Move) { settings.moveAmount = EditorGUILayout.Vector3Field("Move Amount", settings.moveAmount); GUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Coordinate", GUILayout.Width(EditorGUIUtility.labelWidth)); settings.coordinate = (Coordinate)GUILayout.SelectionGrid((int)settings.coordinate, strCoodinate, strCoodinate.Length); GUILayout.EndHorizontal(); EditorGUILayout.Space(); settings.pivotPos = EditorGUILayout.Vector3Field("Pivot Position", settings.pivotPos); settings.pivotRot = Quaternion.Euler(EditorGUILayout.Vector3Field("Pivot Rotation", settings.pivotRot.eulerAngles)); EditorGUILayout.Space(); if (GUILayout.Button("Apply Move")) { m_target.ApplyMove(settings.moveAmount, settings.coordinate); m_target.PushUndo(); } } else if (settings.editMode == EditMode.Rotate) { settings.rotateAmount = EditorGUILayout.Vector3Field("Rotate Amount", settings.rotateAmount); GUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Coordinate", GUILayout.Width(EditorGUIUtility.labelWidth)); settings.coordinate = (Coordinate)GUILayout.SelectionGrid((int)settings.coordinate, strCoodinate, strCoodinate.Length); GUILayout.EndHorizontal(); EditorGUILayout.Space(); settings.rotatePivot = EditorGUILayout.Toggle("Rotate Around Pivot", settings.rotatePivot); settings.pivotPos = EditorGUILayout.Vector3Field("Pivot Position", settings.pivotPos); settings.pivotRot = Quaternion.Euler(EditorGUILayout.Vector3Field("Pivot Rotation", settings.pivotRot.eulerAngles)); EditorGUILayout.Space(); if (GUILayout.Button("Apply Rotate")) { if (settings.rotatePivot) { m_target.ApplyRotatePivot( Quaternion.Euler(settings.rotateAmount), settings.pivotPos, settings.pivotRot, settings.coordinate); } else { m_target.ApplyRotate(Quaternion.Euler(settings.rotateAmount), settings.pivotRot, settings.coordinate); } m_target.PushUndo(); } } else if (settings.editMode == EditMode.Scale) { settings.scaleAmount = EditorGUILayout.Vector3Field("Scale Amount", settings.scaleAmount); GUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Coordinate", GUILayout.Width(EditorGUIUtility.labelWidth)); settings.coordinate = (Coordinate)GUILayout.SelectionGrid((int)settings.coordinate, strCoodinate, strCoodinate.Length); GUILayout.EndHorizontal(); EditorGUILayout.Space(); settings.pivotPos = EditorGUILayout.Vector3Field("Pivot Position", settings.pivotPos); settings.pivotRot = Quaternion.Euler(EditorGUILayout.Vector3Field("Pivot Rotation", settings.pivotRot.eulerAngles)); EditorGUILayout.Space(); if (GUILayout.Button("Apply Scale")) { m_target.ApplyScale(settings.scaleAmount, settings.pivotPos, settings.pivotRot, settings.coordinate); m_target.PushUndo(); } } else if (settings.editMode == EditMode.Smooth) { settings.smoothRadius = EditorGUILayout.FloatField("Smooth Radius", settings.smoothRadius); settings.smoothAmount = EditorGUILayout.FloatField("Smooth Amount", settings.smoothAmount); if (GUILayout.Button("Apply Smooth")) { m_target.ApplySmooth(settings.smoothRadius, settings.smoothAmount); m_target.PushUndo(); } } else if (settings.editMode == EditMode.Projection) { settings.projectionNormalSource = EditorGUILayout.ObjectField("Normal Source", settings.projectionNormalSource, typeof(GameObject), true) as GameObject; EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Ray Direction", GUILayout.Width(EditorGUIUtility.labelWidth)); settings.projectionRayDirection = GUILayout.SelectionGrid(settings.projectionRayDirection, strRayDirection, 2); EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); if (GUILayout.Button("Apply Projection")) { m_target.ApplyProjection(settings.projectionNormalSource, settings.projectionRayDirection == 0); m_target.PushUndo(); } } else if (settings.editMode == EditMode.Reset) { EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("Reset (Selection)")) { m_target.ResetNormals(true); m_target.PushUndo(); } else if (GUILayout.Button("Reset (All)")) { m_target.ResetNormals(false); m_target.PushUndo(); } EditorGUILayout.EndHorizontal(); } EditorGUILayout.EndVertical(); EditorGUILayout.EndHorizontal(); }