Beispiel #1
0
    void VToolGUI()
    {
        VMODE = (VOLUME_MODE)EditorGUILayout.EnumPopup("Volume Mode:", VMODE);

        switch (VMODE)
        {
        case VOLUME_MODE.Box:
            volume.bounds = EditorGUILayout.BoundsField(volume.bounds);

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Snap to value: (Hold CTRL)", GUILayout.MaxWidth(175.0f));
            volume.snap = EditorGUILayout.FloatField(volume.snap);
            EditorGUILayout.EndHorizontal();
            break;

        case VOLUME_MODE.Sphere:
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Sphere Radius", GUILayout.MaxWidth(100.0f));
            volume.radius = EditorGUILayout.FloatField(volume.radius);
            EditorGUILayout.EndHorizontal();
            break;

        case VOLUME_MODE.Plane:
            EditorGUILayout.BeginHorizontal();
            volume.p1 = EditorGUILayout.Vector3Field("Points (1)", volume.p1);
            EditorGUILayout.EndHorizontal();
            break;

        default:
            break;
        }



        EditorGUILayout.Space();
    }
Beispiel #2
0
void VTool(VOLUME_MODE MODE)
{
    Handles.color = color;

    switch (MODE)
    {
    case VOLUME_MODE.Box:
        VolumeTool.DrawCube(volume.bounds.center, volume.bounds.size);


        Vector3 size    = Handles.ScaleHandle(volume.bounds.size, volume.bounds.center, Quaternion.identity, HandleUtility.GetHandleSize(volume.bounds.center) * 1.25f);
        Vector3 center  = Handles.PositionHandle(volume.bounds.center, Quaternion.identity);
        Vector3 textPos = center + new Vector3(0, -0.5f, 0);

        volume.bounds.size   = size;
        volume.bounds.center = center;

        Vector3 minCorner = Handles.FreeMoveHandle(volume.bounds.min, Quaternion.identity, 0.075f, new Vector3(volume.snap, volume.snap, volume.snap), Handles.RectangleHandleCap);
        Vector3 maxCorner = Handles.FreeMoveHandle(volume.bounds.max, Quaternion.identity, 0.075f, new Vector3(volume.snap, volume.snap, volume.snap), Handles.RectangleHandleCap);

        volume.bounds.min = minCorner;
        volume.bounds.max = maxCorner;


        GUIStyle style = new GUIStyle();
        style.normal.textColor = color;
        style.fontSize         = 20;
        style.alignment        = TextAnchor.MiddleCenter;

        float rectSize = size.x * size.y * size.z;
        rectSize = MTool.Round(rectSize, decimals);
        rectSize = Mathf.Abs(rectSize);
        string m = "m³";

        Handles.Label(textPos, rectSize.ToString() + m + '\n' + size.ToString(), style);
        break;

    case VOLUME_MODE.Sphere:
        volume.position = Handles.PositionHandle(volume.position, Quaternion.identity);
        volume.sizer    = Handles.FreeMoveHandle(volume.sizer, Quaternion.identity, 0.075f, Vector3.zero, Handles.RectangleHandleCap);
        Vector3 tPos = volume.position + new Vector3(0, -0.25f, 0);

        volume.radius = Vector3.Distance(volume.position, volume.sizer);
        Handles.DrawLine(volume.sizer, volume.position);

        Vector3    norm      = (volume.position - volume.sizer).normalized;
        Quaternion rotFacing = Quaternion.identity;

        if (norm.magnitude > 0.001f)
        {
            rotFacing = Quaternion.LookRotation(norm);
        }

        Quaternion rotOpposite = rotFacing * Quaternion.Euler(0, 90.0f, 0);

        Handles.CircleHandleCap(0, volume.position, rotFacing, volume.radius, EventType.Repaint);
        Handles.CircleHandleCap(0, volume.position, rotOpposite, volume.radius, EventType.Repaint);

        float r = volume.radius * 4 * Mathf.PI;
        r = MTool.Round(r, decimals);
        m = "m²";

        style = new GUIStyle();
        style.normal.textColor = color;
        style.fontSize         = 20;
        style.alignment        = TextAnchor.MiddleCenter;

        Handles.Label(tPos, r.ToString() + m, style);

        break;

    case VOLUME_MODE.Plane:

        volume.p1 = Handles.FreeMoveHandle(volume.p1, Quaternion.identity, 0.075f, Vector3.zero, Handles.RectangleHandleCap);
        volume.p2 = Handles.FreeMoveHandle(volume.p2, Quaternion.identity, 0.075f, Vector3.zero, Handles.RectangleHandleCap);
        volume.p3 = Handles.FreeMoveHandle(volume.p3, Quaternion.identity, 0.075f, Vector3.zero, Handles.RectangleHandleCap);
        volume.p4 = Handles.FreeMoveHandle(volume.p4, Quaternion.identity, 0.075f, Vector3.zero, Handles.RectangleHandleCap);

        Handles.DrawLine(volume.p1, volume.p2);
        Handles.DrawLine(volume.p2, volume.p3);
        Handles.DrawLine(volume.p3, volume.p4);
        Handles.DrawLine(volume.p4, volume.p1);

        Handles.DrawDottedLine(volume.p1, volume.p3, 10f);

        float area1 = VolumeTool.FindArea(volume.p1, volume.p3, volume.p4);
        float area2 = VolumeTool.FindArea(volume.p1, volume.p2, volume.p3);

        float total = area1 + area2;
        total = MTool.Round(total, decimals);
        m     = "m²";

        style = new GUIStyle();
        style.normal.textColor = color;
        style.fontSize         = 20;
        style.alignment        = TextAnchor.MiddleCenter;

        Vector3 t1 = (volume.p1 + volume.p3 + volume.p4) / 3;
        Vector3 t2 = (volume.p1 + volume.p2 + volume.p3) / 3;

        Handles.Label((t1 + t2) / 2, total.ToString() + m, style);
        break;

    default:
        break;
    }
}