Exemplo n.º 1
0
    void CenterHandle()
    {
        Vector3 center = model.transform.position;

        Handles.color = Color.yellow;

        if (m_EditorStae != EditorStae.CenterHandel)
        {
            float hsize = HandlesExtension.CalculateButtonRadius(center, handleSize);
            if (Handles.Button(center, Quaternion.identity, hsize, hsize, Handles.SphereCap))
            {
                m_EditorStae = EditorStae.CenterHandel;
            }
        }

        if (m_EditorStae == EditorStae.CenterHandel)
        {
            Vector3 newCenter = Handles.PositionHandle(center, Quaternion.identity);
            if (newCenter != center)
            {
                model.transform.position = newCenter;
            }
        }
    }
Exemplo n.º 2
0
    void OnSceneGUI()
    {
        if (!model.showHandles)
        {
            return;
        }

        const float handleSize = 10f;
        Camera      camera     = SceneView.lastActiveSceneView.camera;
        Vector3     center     = model.ScrollViewPosition;


        Handles.color = model.GizmosCubeColor;

        if (m_EditorStae != EditorStae.CenterHandel)
        {
            float hsize = HandlesExtension.CalculateButtonRadius(center, handleSize);
            if (Handles.Button(center, Quaternion.identity, hsize, hsize, Handles.SphereCap))
            {
                m_EditorStae = EditorStae.CenterHandel;
            }
        }

        if (m_EditorStae != EditorStae.MinHandel)
        {
            float hsize = HandlesExtension.CalculateButtonRadius(center + model.Cube.min, handleSize);
            if (Handles.Button(center + model.Cube.min, Quaternion.identity, hsize, hsize, Handles.SphereCap))
            {
                m_EditorStae = EditorStae.MinHandel;
            }
        }

        if (m_EditorStae != EditorStae.MaxHandel)
        {
            float hsize = HandlesExtension.CalculateButtonRadius(center + model.Cube.max, handleSize);
            if (Handles.Button(center + model.Cube.max, Quaternion.identity, hsize, hsize, Handles.SphereCap))
            {
                m_EditorStae = EditorStae.MaxHandel;
            }
        }

        switch (m_EditorStae)
        {
        case EditorStae.CenterHandel:
        {
            Vector3 newCenter = Handles.PositionHandle(center, Quaternion.identity);
            if (newCenter != center)
            {
                model.JumpTo(newCenter);
            }
        }
        break;

        case EditorStae.MaxHandel:
        {
            Vector3 newMax = Handles.PositionHandle(center + model.Cube.max, Quaternion.identity);
            if (newMax != center + model.Cube.max)
            {
                Vector3 areamax = model.Owner.transform.position + model.Owner.Area.max;
                if (newMax.x > areamax.x)
                {
                    newMax.x = areamax.x;
                }
                if (newMax.y > areamax.y)
                {
                    newMax.y = areamax.y;
                }
                if (newMax.z > areamax.z)
                {
                    newMax.z = areamax.z;
                }

                Vector3 min = center + model.Cube.min;
                float   ex  = (newMax.x - min.x) / 2;
                float   ey  = (newMax.y - min.y) / 2;
                float   ez  = (newMax.z - min.z) / 2;
                if (ex < 0)
                {
                    ex = 0;
                }
                if (ey < 0)
                {
                    ey = 0;
                }
                if (ez < 0)
                {
                    ez = 0;
                }

                model.Cube = new Bounds(model.Cube.min + new Vector3(ex, ey, ez), new Vector3(ex, ey, ez) * 2);
            }
        }
        break;

        case EditorStae.MinHandel:
        {
            Vector3 newMin = Handles.PositionHandle(center + model.Cube.min, Quaternion.identity);
            if (newMin != center + model.Cube.min)
            {
                Vector3 areamin = model.Owner.transform.position + model.Owner.Area.min;
                if (newMin.x < areamin.x)
                {
                    newMin.x = areamin.x;
                }
                if (newMin.y < areamin.y)
                {
                    newMin.y = areamin.y;
                }
                if (newMin.z < areamin.z)
                {
                    newMin.z = areamin.z;
                }


                Vector3 max = center + model.Cube.max;
                float   ex  = (max.x - newMin.x) / 2;
                float   ey  = (max.y - newMin.y) / 2;
                float   ez  = (max.z - newMin.z) / 2;
                if (ex < 0)
                {
                    ex = 0;
                }
                if (ey < 0)
                {
                    ey = 0;
                }
                if (ez < 0)
                {
                    ez = 0;
                }

                model.Cube = new Bounds(model.Cube.max - new Vector3(ex, ey, ez), new Vector3(ex, ey, ez) * 2);
            }
        }
        break;
        }
    }
Exemplo n.º 3
0
    void OnSceneGUI(SceneView sceneView)
    {
        //HandleUtility.AddDefaultControl(GUIUtility.GetControlID(FocusType.Passive));
        EditorGUI.BeginChangeCheck();
        if (_dimension == DimensionType._2D)
        {
            Vector2 center    = (_boundVertices2D_triangle[0] + _boundVertices2D_triangle[1] + _boundVertices2D_triangle[2]) / 3;
            Vector2 newCenter = Handles.FreeMoveHandle(center, Quaternion.identity, HandleUtility.GetHandleSize(center) * 0.1f, Vector3.zero, Handles.DotCap);
            if (center != newCenter)
            {
                for (int i = 0; i < 3; ++i)
                {
                    _boundVertices2D_triangle[i] += (Vector3)(newCenter - center);
                }
            }
            _boundPosition2D_A = newCenter;

            switch (_bound2d)
            {
            case BoundType2D.Line:
                Handles.DrawLine(_boundPosition2D_A, _boundPosition2D_B);
                _boundPosition2D_B = Handles.FreeMoveHandle(_boundPosition2D_B, Quaternion.identity, HandleUtility.GetHandleSize(_boundPosition2D_B) * 0.1f, Vector3.zero, Handles.DotCap);
                break;

            case BoundType2D.Box:
                Handles.matrix = Matrix4x4.TRS(_boundPosition2D_A, Quaternion.identity, _boundSize2D);
                HandlesExtension.DrawSquare();
                Handles.matrix = Matrix4x4.identity;
                break;

            case BoundType2D.Circle:
                Handles.matrix = Matrix4x4.TRS(_boundPosition2D_A, Quaternion.identity, _boundSize2D);
                HandlesExtension.DrawCircle();
                Handles.matrix = Matrix4x4.identity;
                break;

            case BoundType2D.Sector:
                Handles.matrix = Matrix4x4.TRS(_boundPosition2D_A, Quaternion.identity, _boundSize2D);
                HandlesExtension.DrawSector(_boundAngle);
                Handles.matrix = Matrix4x4.identity;
                break;

            case BoundType2D.Triangle:
                _boundVertices2D_triangle[0] = Handles.FreeMoveHandle(_boundVertices2D_triangle[0]
                                                                      , Quaternion.identity, HandleUtility.GetHandleSize(_boundVertices2D_triangle[0]) * 0.08f, Vector3.zero, Handles.SphereCap);
                _boundVertices2D_triangle[1] = Handles.FreeMoveHandle(_boundVertices2D_triangle[1]
                                                                      , Quaternion.identity, HandleUtility.GetHandleSize(_boundVertices2D_triangle[1]) * 0.08f, Vector3.zero, Handles.SphereCap);
                _boundVertices2D_triangle[2] = Handles.FreeMoveHandle(_boundVertices2D_triangle[2]
                                                                      , Quaternion.identity, HandleUtility.GetHandleSize(_boundVertices2D_triangle[2]) * 0.08f, Vector3.zero, Handles.SphereCap);
                Handles.DrawPolyLine(_boundVertices2D_triangle);
                Handles.DrawLine(_boundVertices2D_triangle[2], _boundVertices2D_triangle[0]);
                Handles.DrawLine(_boundPosition2D_A, new Vector3(_boundPosition2D_A.x, _boundPosition2D_A.y) + Vector3.Cross(_boundVertices2D_triangle[1] - _boundVertices2D_triangle[0], _boundVertices2D_triangle[2] - _boundVertices2D_triangle[0]));
                break;
            }

            center    = (_checkerVertices2D_triangle[0] + _checkerVertices2D_triangle[1] + _checkerVertices2D_triangle[2]) / 3;
            newCenter = Handles.FreeMoveHandle(center, Quaternion.identity, HandleUtility.GetHandleSize(center) * 0.1f, Vector3.zero, Handles.DotCap);
            if (center != newCenter)
            {
                for (int i = 0; i < 3; ++i)
                {
                    _checkerVertices2D_triangle[i] += (Vector3)(newCenter - center);
                }
            }
            _checkerPosition2D_A = newCenter;
            switch (_checker2d)
            {
            //case CheckerType2D.Dot:
            //    break;
            case CheckerType2D.Line:
                _checkerPosition2D_B = Handles.FreeMoveHandle(_checkerPosition2D_B, Quaternion.identity, HandleUtility.GetHandleSize(_checkerPosition2D_B) * 0.1f, Vector3.zero, Handles.DotCap);
                Handles.DrawLine(_checkerPosition2D_A, _checkerPosition2D_B);
                break;

            case CheckerType2D.Ray:
                _checkerPosition2D_B = Handles.FreeMoveHandle(_checkerPosition2D_B, Quaternion.identity, HandleUtility.GetHandleSize(_checkerPosition2D_B) * 0.1f, Vector3.zero, Handles.DotCap);
                Vector3 dirTmp = _checkerPosition2D_B - _checkerPosition2D_A;
                Handles.ArrowCap(0, _checkerPosition2D_A, Quaternion.FromToRotation(Vector3.forward, dirTmp), HandleUtility.GetHandleSize(_checkerPosition2D_A) * 1.1f);
                Handles.DrawLine(_checkerPosition2D_A, (Vector3)_checkerPosition2D_A + dirTmp * 100f);
                break;

            case CheckerType2D.Box:
                Handles.matrix = Matrix4x4.TRS(_checkerPosition2D_A, Quaternion.identity, _checkerSize2D);
                HandlesExtension.DrawSquare();
                Handles.matrix = Matrix4x4.identity;
                break;

            case CheckerType2D.LerpBox:
                break;

            case CheckerType2D.Circle:
                Handles.matrix = Matrix4x4.TRS(_checkerPosition2D_A, Quaternion.identity, _checkerSize2D);
                HandlesExtension.DrawCircle();
                Handles.matrix = Matrix4x4.identity;
                break;

            case CheckerType2D.Sector:
                Handles.matrix = Matrix4x4.TRS(_checkerPosition2D_A, Quaternion.identity, _checkerSize2D);
                HandlesExtension.DrawSector(_checkerAngle);
                Handles.matrix = Matrix4x4.identity;
                break;

            case CheckerType2D.Triangle:
                _checkerVertices2D_triangle[0] = Handles.FreeMoveHandle(_checkerVertices2D_triangle[0]
                                                                        , Quaternion.identity, HandleUtility.GetHandleSize(_checkerVertices2D_triangle[0]) * 0.08f, Vector3.zero, Handles.SphereCap);
                _checkerVertices2D_triangle[1] = Handles.FreeMoveHandle(_checkerVertices2D_triangle[1]
                                                                        , Quaternion.identity, HandleUtility.GetHandleSize(_checkerVertices2D_triangle[1]) * 0.08f, Vector3.zero, Handles.SphereCap);
                _checkerVertices2D_triangle[2] = Handles.FreeMoveHandle(_checkerVertices2D_triangle[2]
                                                                        , Quaternion.identity, HandleUtility.GetHandleSize(_checkerVertices2D_triangle[2]) * 0.08f, Vector3.zero, Handles.SphereCap);
                Handles.DrawPolyLine(_checkerVertices2D_triangle);
                Handles.DrawLine(_checkerVertices2D_triangle[2], _checkerVertices2D_triangle[0]);
                break;
            }
        }
        else //if(_dimension == DimensionType._3D)
        {
        }
        if (EditorGUI.EndChangeCheck())
        {
            Repaint();
        }
    }
Exemplo n.º 4
0
    void SoftAreaHandle()
    {
        Handles.color = Color.white;
        Vector3 center = model.transform.position;

        HandlesExtension.DrawWireCube(center + model.SoftArea.center, model.SoftArea.size);

        Handles.color = model.GizmosSoftCubeColor;


        if (m_EditorStae != EditorStae.SoftAreaMinHandel)
        {
            float hsize = HandlesExtension.CalculateButtonRadius(center + model.SoftArea.min, handleSize);
            if (Handles.Button(center + model.SoftArea.min, Quaternion.identity, hsize, hsize, Handles.SphereCap))
            {
                m_EditorStae = EditorStae.SoftAreaMinHandel;
            }
        }

        if (m_EditorStae != EditorStae.SoftAreaMaxHandel)
        {
            float hsize = HandlesExtension.CalculateButtonRadius(center + model.SoftArea.max, handleSize);
            if (Handles.Button(center + model.SoftArea.max, Quaternion.identity, hsize, hsize, Handles.SphereCap))
            {
                m_EditorStae = EditorStae.SoftAreaMaxHandel;
            }
        }

        switch (m_EditorStae)
        {
        case EditorStae.SoftAreaMaxHandel:
        {
            Vector3 newMax = Handles.PositionHandle(center + model.SoftArea.max, Quaternion.identity);
            if (newMax != center + model.SoftArea.max)
            {
                Vector3 min = center + model.SoftArea.min;
                float   ex  = (newMax.x - min.x) / 2;
                float   ey  = (newMax.y - min.y) / 2;
                float   ez  = (newMax.z - min.z) / 2;
                if (ex < 0)
                {
                    ex = 0;
                }
                if (ey < 0)
                {
                    ey = 0;
                }
                if (ez < 0)
                {
                    ez = 0;
                }

                model.SoftArea = new Bounds(model.SoftArea.min + new Vector3(ex, ey, ez), new Vector3(ex, ey, ez) * 2);
            }
        }
        break;

        case EditorStae.SoftAreaMinHandel:
        {
            Vector3 newMin = Handles.PositionHandle(center + model.SoftArea.min, Quaternion.identity);
            if (newMin != center + model.SoftArea.min)
            {
                Vector3 max = center + model.SoftArea.max;
                float   ex  = (max.x - newMin.x) / 2;
                float   ey  = (max.y - newMin.y) / 2;
                float   ez  = (max.z - newMin.z) / 2;
                if (ex < 0)
                {
                    ex = 0;
                }
                if (ey < 0)
                {
                    ey = 0;
                }
                if (ez < 0)
                {
                    ez = 0;
                }

                model.SoftArea = new Bounds(model.SoftArea.max - new Vector3(ex, ey, ez), new Vector3(ex, ey, ez) * 2);
            }
        }
        break;
        }
    }