Пример #1
0
        public static void ImageCapBase(int aControlID, Vector3 aPosition, Quaternion aRotation, float aSize, Texture2D aTex)
        {
            if (Event.current.type != EventType.Repaint)
            {
                return;
            }

            aPosition = Handles.matrix.MultiplyPoint(aPosition);
            Vector3 right = Camera.current.transform.right * aSize;
            Vector3 top   = Camera.current.transform.up * aSize;

            CapMaterial2D.mainTexture = aTex;
            CapMaterial2D.SetPass(0);

            GL.Begin(GL.QUADS);
            GL.Color(Handles.color);
            GL.TexCoord2(1, 1);
            GL.Vertex(aPosition + right + top);

            GL.TexCoord2(1, 0);
            GL.Vertex(aPosition + right - top);

            GL.TexCoord2(0, 0);
            GL.Vertex(aPosition - right - top);

            GL.TexCoord2(0, 1);
            GL.Vertex(aPosition - right + top);

            GL.End();
        }
Пример #2
0
        public static void ImageCapBase(int aControlID, Vector3 aPosition, Quaternion aRotation, float aSize, Texture2D aTex, EventType aEvent)
        {
            if (aEvent != EventType.Layout)
            {
                if (aEvent == EventType.Repaint)
                {
                    aPosition = Handles.matrix.MultiplyPoint(aPosition);
                    Vector3 right = Camera.current.transform.right * aSize;
                    Vector3 top   = Camera.current.transform.up * aSize;
                    CapMaterial2D.mainTexture = aTex;
                    CapMaterial2D.SetPass(0);

                    GL.Begin(GL.QUADS);
                    GL.Color(Handles.color);
                    GL.TexCoord2(1, 1);
                    GL.Vertex(aPosition + right + top);

                    GL.TexCoord2(1, 0);
                    GL.Vertex(aPosition + right - top);

                    GL.TexCoord2(0, 0);
                    GL.Vertex(aPosition - right - top);

                    GL.TexCoord2(0, 1);
                    GL.Vertex(aPosition - right + top);

                    GL.End();
                }
            }
            else
            {
                HandleUtility.AddControl(aControlID, HandleUtility.DistanceToRectangle(aPosition, aRotation, aSize));
            }
        }
        public static void DrawPolyLine(Vector3[] aPts, float aWidth)
        {
            if (Event.current.type != EventType.Repaint)
            {
                return;
            }
            CapMaterial2D.mainTexture = EditorGUIUtility.whiteTexture;
            CapMaterial2D.SetPass(0);

            GL.PushMatrix();
            GL.MultMatrix(Handles.matrix);
            GL.Begin(GL.TRIANGLES);
            GL.Color(Handles.color);
            for (int i = 1; i < aPts.Length; i++)
            {
                Vector3 norm = (aPts[i] - aPts[i - 1]).normalized;
                norm = new Vector3(-norm.y, norm.x, norm.z) * HandleUtility.GetHandleSize(aPts[i]) * aWidth;

                GL.Vertex(aPts[i - 1] - norm);
                GL.Vertex(aPts[i - 1] + norm);
                GL.Vertex(aPts[i] + norm);

                GL.Vertex(aPts[i] + norm);
                GL.Vertex(aPts[i] - norm);
                GL.Vertex(aPts[i - 1] - norm);
            }
            GL.End();
            GL.PopMatrix();
        }
        public static void DrawLine(Vector3 aP1, Vector3 aP2, float aWidth)
        {
            if (Event.current.type != EventType.Repaint)
            {
                return;
            }
            CapMaterial2D.mainTexture = EditorGUIUtility.whiteTexture;
            CapMaterial2D.SetPass(0);

            GL.PushMatrix();
            GL.MultMatrix(Handles.matrix);
            GL.Begin(GL.TRIANGLES);
            GL.Color(Handles.color);
            Vector3 norm = (aP2 - aP1).normalized;

            norm = new Vector3(-norm.y, norm.x, norm.z) * HandleUtility.GetHandleSize(aP2) * aWidth;

            GL.Vertex(aP1 - norm);
            GL.Vertex(aP1 + norm);
            GL.Vertex(aP2 + norm);

            GL.Vertex(aP2 + norm);
            GL.Vertex(aP2 - norm);
            GL.Vertex(aP1 - norm);
            GL.End();
            GL.PopMatrix();
        }
Пример #5
0
        public static void CircleCapBase(int aControlID, Vector3 aPosition, Quaternion aRotation, float aSize, EventType aEvent)
        {
            if (aEvent == EventType.Repaint)
            {
                aPosition = Handles.matrix.MultiplyPoint(aPosition);
                Vector3 right = Camera.current.transform.right * aSize;
                Vector3 up    = Camera.current.transform.up * aSize;
                CapMaterial2D.mainTexture = null;
                CapMaterial2D.SetPass(0);

                GL.Begin(GL.TRIANGLES);
                GL.Color(Handles.color);

                int     count = 6;
                float   step  = 1f / count * Mathf.PI * 2;
                Vector3 start = aPosition + right;
                for (int i = 1; i < count; i++)
                {
                    float p = i * step;
                    GL.Vertex(start);
                    GL.Vertex(aPosition + Mathf.Cos(p + step) * right + Mathf.Sin(p + step) * up);
                    GL.Vertex(aPosition + Mathf.Cos(p) * right + Mathf.Sin(p) * up);
                }
                GL.End();
            }
            else if (aEvent == EventType.Layout)
            {
                HandleUtility.AddControl(aControlID, HandleUtility.DistanceToRectangle(aPosition, aRotation, aSize));
            }
        }
        public static void CircleCapBase(int aControlID, Vector3 aPosition, Quaternion aRotation, float aSize, EventType aEvent)
        {
            if (aEvent == EventType.Repaint)
            {
                aPosition = Handles.matrix.MultiplyPoint(aPosition);
                Vector3 right = Camera.current.transform.right * aSize;
                Vector3 up    = Camera.current.transform.up * aSize;
                CapMaterial2D.mainTexture = null;
                CapMaterial2D.SetPass(0);

                GL.Begin(GL.QUADS);
                GL.Color(Handles.color);
                GL.Vertex(aPosition + up);
                GL.Vertex(aPosition + right);
                GL.Vertex(aPosition - up);
                GL.Vertex(aPosition - right);

                GL.End();
            }
            else if (aEvent == EventType.Layout)
            {
                HandleUtility.AddControl(aControlID, HandleUtility.DistanceToRectangle(aPosition, aRotation, aSize));
            }
        }