예제 #1
0
        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();
                if (GUILayout.Button("Edge [E]", GUILayout.Width(100)))
                {
                    m_target.SelectEdge(m_ctrl ? -1.0f : 1.0f, !m_shift && !m_ctrl);
                    m_target.UpdateSelection();
                }
                if (GUILayout.Button("Hole [H]", GUILayout.Width(100)))
                {
                    m_target.SelectHole(m_ctrl ? -1.0f : 1.0f, !m_shift && !m_ctrl);
                    m_target.UpdateSelection();
                }
                if (GUILayout.Button("Connected [C]", GUILayout.Width(100)))
                {
                    m_target.SelectConnected(m_ctrl ? -1.0f : 1.0f, !m_shift && !m_ctrl);
                    m_target.UpdateSelection();
                }
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                if (GUILayout.Button("All [A]", GUILayout.Width(100)))
                {
                    m_target.SelectAll();
                    m_target.UpdateSelection();
                }
                if (GUILayout.Button("Clear [D]", GUILayout.Width(100)))
                {
                    m_target.ClearSelection();
                    m_target.UpdateSelection();
                }
                if (GUILayout.Button("Invert [I]", GUILayout.Width(100)))
                {
                    m_target.InvertSelection();
                    m_target.UpdateSelection();
                }
                GUILayout.EndHorizontal();

                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();
            }
            else if (settings.editMode == EditMode.Brush)
            {
                settings.brushMode = (BrushMode)GUILayout.SelectionGrid((int)settings.brushMode, strBrushTypes, 5);
                EditorGUILayout.Space();

                settings.brushMaskWithSelection = EditorGUILayout.Toggle("Mask With Selection", settings.brushMaskWithSelection); EditorGUILayout.Space();
                DrawBrushPanel();

                if (settings.brushMode == BrushMode.Replace)
                {
                    GUILayout.BeginHorizontal();
                    settings.assignValue = EditorGUILayout.Vector3Field("Value", settings.assignValue);
                    settings.pickNormal  = GUILayout.Toggle(settings.pickNormal, "Pick [P]", "Button", GUILayout.Width(100));
                    GUILayout.EndHorizontal();
                }
                else if (settings.brushMode == BrushMode.Projection)
                {
                    DrawProjectionPanel();
                }
            }
            else if (settings.editMode == EditMode.Assign)
            {
                settings.assignValue = EditorGUILayout.Vector3Field("Value", settings.assignValue);
                GUILayout.BeginHorizontal();
                if (GUILayout.Button("Copy Selected Normal [Shift+C]", GUILayout.Width(200)))
                {
                    settings.assignValue = m_target.selectionNormal;
                }
                settings.pickNormal = GUILayout.Toggle(settings.pickNormal, "Pick [P]", "Button", GUILayout.Width(90));
                GUILayout.EndHorizontal();

                EditorGUILayout.Space();

                GUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("Coordinate", GUILayout.Width(EditorGUIUtility.labelWidth));
                settings.coordinate = (Coordinate)GUILayout.SelectionGrid((int)settings.coordinate, strCoodinate, strCoodinate.Length);
                GUILayout.EndHorizontal();
                if (settings.coordinate == Coordinate.Pivot)
                {
                    EditorGUILayout.Space();
                    settings.pivotRot = Quaternion.Euler(EditorGUILayout.Vector3Field("Pivot Rotation", settings.pivotRot.eulerAngles));
                }

                if (GUILayout.Button("Assign [Shift+V]"))
                {
                    m_target.ApplyAssign(settings.assignValue, settings.coordinate, true);
                }
            }
            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();
                if (settings.coordinate == Coordinate.Pivot)
                {
                    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, true);
                }
            }
            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);
                if (settings.coordinate == Coordinate.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, true);
                    }
                    else
                    {
                        m_target.ApplyRotate(Quaternion.Euler(settings.rotateAmount), settings.pivotRot, settings.coordinate, true);
                    }
                }
            }
            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();
                if (settings.coordinate == Coordinate.Pivot)
                {
                    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, true);
                }
            }
            else if (settings.editMode == EditMode.Smooth)
            {
                settings.smoothMode = GUILayout.SelectionGrid(settings.smoothMode, strSmoothMode, 3);
                EditorGUILayout.Space();

                if (settings.smoothMode == 0)
                {
                    settings.smoothRadius = EditorGUILayout.FloatField("Smooth Radius", settings.smoothRadius);
                    settings.smoothAmount = EditorGUILayout.FloatField("Smooth Amount", settings.smoothAmount);
                    if (GUILayout.Button("Apply Smoothing [Shift+S]"))
                    {
                        m_target.ApplySmoothing(settings.smoothRadius, settings.smoothAmount, true);
                    }
                }
                else if (settings.smoothMode == 1)
                {
                    settings.weldWithSmoothing = EditorGUILayout.Toggle("Smoothing", settings.weldWithSmoothing);
                    settings.weldAngle         = EditorGUILayout.FloatField("Weld Angle", settings.weldAngle);

                    if (GUILayout.Button("Apply Welding [Shift+W]"))
                    {
                        m_target.ApplyWelding(settings.weldWithSmoothing, settings.weldAngle, true);
                    }
                }
                else if (settings.smoothMode == 2)
                {
                    EditorGUILayout.LabelField("Weld Targets");
                    EditorGUI.indentLevel++;
                    int n = EditorGUILayout.IntField("Size", settings.weldTargets.Length);
                    if (n != settings.weldTargets.Length)
                    {
                        System.Array.Resize(ref settings.weldTargets, n);
                    }

                    for (int i = 0; i < settings.weldTargets.Length; ++i)
                    {
                        settings.weldTargets[i] = (GameObject)EditorGUILayout.ObjectField(settings.weldTargets[i], typeof(GameObject), true);
                    }
                    EditorGUI.indentLevel--;

                    EditorGUILayout.Space();

                    settings.weldTargetsMode = EditorGUILayout.IntPopup("Weld Mode", settings.weldTargetsMode,
                                                                        new string[3] {
                        "Copy To Targets", "Copy From Targets", "Smoothing"
                    },
                                                                        new int[3] {
                        0, 1, 2
                    });

                    settings.weldAngle = EditorGUILayout.FloatField("Weld Angle", settings.weldAngle);

                    if (GUILayout.Button("Apply Welding"))
                    {
                        m_target.ApplyWelding2(settings.weldTargets, settings.weldTargetsMode, settings.weldAngle, true);
                    }
                }
            }
            else if (settings.editMode == EditMode.Projection)
            {
                DrawProjectionPanel();
                EditorGUILayout.Space();

                if (GUILayout.Button("Apply Projection"))
                {
                    var normalSource = settings.projectionNormalSourceData;
                    if (normalSource == null || normalSource.empty)
                    {
                        Debug.LogError("\"Normal Source\" object is not set or has no readable Mesh or Terrain.");
                    }
                    else if (settings.projectionMode == 0)
                    {
                        m_target.ApplyProjection2(normalSource, settings.projectionDir, true);
                    }
                    else
                    {
                        var rayDirs = settings.projectionRayDir == 0 ?
                                      m_target.normalsBase : m_target.normals;
                        m_target.ApplyProjection(normalSource, rayDirs, true);
                    }
                }
            }
            else if (settings.editMode == EditMode.Reset)
            {
                EditorGUILayout.BeginHorizontal();
                if (GUILayout.Button("Reset (Selection)"))
                {
                    m_target.ResetNormals(true, true);
                }
                else if (GUILayout.Button("Reset (All)"))
                {
                    m_target.ResetNormals(false, true);
                }
                EditorGUILayout.EndHorizontal();
            }
            EditorGUILayout.EndVertical();
            EditorGUILayout.EndHorizontal();
        }