public override sealed void OnSceneGUI()
        {
            var sliderJoint2D = (SliderJoint2DExt)target;

            if (!sliderJoint2D.enabled)
            {
                return;
            }
            Vector3 vector  = Joint2DExtInspector.TransformPoint(sliderJoint2D.transform, sliderJoint2D.anchor);
            Vector3 vector2 = vector;
            Vector3 vector3 = vector;
            Vector3 vector4 = Joint2DExtInspector.RotateVector2(Vector3.right, sliderJoint2D.transform.eulerAngles.z);

            vector4       = Joint2DExtInspector.RotateVector2(vector4, -sliderJoint2D.angle);
            Handles.color = Color.green;
            if (sliderJoint2D.useLimits)
            {
                vector2 = vector + vector4 * sliderJoint2D.limits.max;
                vector3 = vector + vector4 * sliderJoint2D.limits.min;
                Vector3 a  = Vector3.Cross(vector4, Vector3.forward);
                float   d  = HandleUtility.GetHandleSize(vector2) * 0.16f;
                float   d2 = HandleUtility.GetHandleSize(vector3) * 0.16f;
                Joint2DExtInspector.DrawAALine(vector2 + a * d, vector2 - a * d);
                Joint2DExtInspector.DrawAALine(vector3 + a * d2, vector3 - a * d2);
            }
            else
            {
                vector4 *= HandleUtility.GetHandleSize(vector) * 0.3f;
                vector2 += vector4;
                vector3 -= vector4;
            }
            Joint2DExtInspector.DrawAALine(vector2, vector3);
            base.OnSceneGUI();
        }
        public override sealed void OnSceneGUI()
        {
            DistanceJointBase2DExt distanceJoint2D = (DistanceJointBase2DExt)this.target;

            if (!distanceJoint2D.enabled)
            {
                return;
            }
            Vector3 anchor = Joint2DExtInspector.TransformPoint(distanceJoint2D.transform, distanceJoint2D.anchor);
            Vector3 vector = distanceJoint2D.connectedAnchor;

            if (distanceJoint2D.connectedBody)
            {
                vector = Joint2DExtInspector.TransformPoint(distanceJoint2D.connectedBody.transform, vector);
            }
            Joint2DExtInspector.DrawDistanceGizmo(anchor, vector, distanceJoint2D.distance);
            bool autoConfigure = distanceJoint2D.autoConfigureConnectedAnchor;

            base.OnSceneGUI();
            if (autoConfigure && !distanceJoint2D.autoConfigureConnectedAnchor)
            {
                distanceJoint2D.autoConfigureDistance = false;
                EditorUtility.SetDirty(distanceJoint2D);
            }
        }
Example #3
0
        public override void OnSceneGUI()
        {
            var pulleyJoint2D = (PulleyJoint2DExt)target;

            anchorJoint2D = pulleyJoint2D;
            pulleyJoint2D.SetConnectedAnchorEditor();
            Vector3 vector    = Joint2DExtInspector.TransformPoint(pulleyJoint2D.transform, pulleyJoint2D.anchor);
            Vector3 vector2   = pulleyJoint2D.groundAnchorA ? pulleyJoint2D.groundAnchorA.position : Vector3.zero;
            Vector3 vector3   = pulleyJoint2D.groundAnchorB ? pulleyJoint2D.groundAnchorB.position : Vector3.zero;
            Vector3 vector4   = pulleyJoint2D.connectedAnchor;
            bool    twoPoints = !pulleyJoint2D.groundAnchorA || !pulleyJoint2D.groundAnchorB;

            if (pulleyJoint2D.connectedBody)
            {
                vector4 = Joint2DExtInspector.TransformPoint(pulleyJoint2D.connectedBody.transform, vector4);
            }
            Vector3 vector5 = vector + (vector2 - vector).normalized * HandleUtility.GetHandleSize(vector) * 0.1f;

            Handles.color = Color.green;
            if (twoPoints)
            {
                Handles.DrawAAPolyLine(new Vector3[] {
                    vector5,
                    vector4
                });
            }
            else
            {
                Handles.DrawAAPolyLine(new Vector3[] {
                    vector5,
                    vector2,
                    vector3,
                    vector4
                });
            }
            if (HandleAnchor(ref vector4, true))
            {
                vector4 = SnapToSprites(vector4);
                vector4 = Joint2DExtInspector.SnapToPoint(vector4, vector, k_SnapDistance);
                if (pulleyJoint2D.connectedBody)
                {
                    vector4 = Joint2DExtInspector.InverseTransformPoint(pulleyJoint2D.connectedBody.transform, vector4);
                }
                pulleyJoint2D.autoConfigureConnectedAnchor = false;
                pulleyJoint2D.connectedAnchor = vector4;
                EditorUtility.SetDirty(pulleyJoint2D);
            }
            if (HandleAnchor(ref vector, false))
            {
                vector = SnapToSprites(vector);
                vector = Joint2DExtInspector.SnapToPoint(vector, vector4, k_SnapDistance);
                pulleyJoint2D.anchor = Joint2DExtInspector.InverseTransformPoint(pulleyJoint2D.transform, vector);
                EditorUtility.SetDirty(pulleyJoint2D);
            }
        }
Example #4
0
 public static void ConnectedAnchorCap(int controlID, Vector3 position, Quaternion rotation, float size)
 {
     if (controlID == GUIUtility.keyboardControl)
     {
         Joint2DExtInspector.DrawCap(controlID, position, Joint2DExtInspector.s_Styles.connectedAnchorActive);
     }
     else
     {
         Joint2DExtInspector.DrawCap(controlID, position, Joint2DExtInspector.s_Styles.connectedAnchor);
     }
 }
Example #5
0
        public static void DrawDistanceGizmo(Vector3 anchor, Vector3 connectedAnchor, float distance)
        {
            Vector3 normalized = (anchor - connectedAnchor).normalized;
            Vector3 vector     = connectedAnchor + normalized * distance;
            Vector3 vector2    = Vector3.Cross(normalized, Vector3.forward);

            vector2      *= HandleUtility.GetHandleSize(connectedAnchor) * 0.16f;
            Handles.color = Color.green;
            Joint2DExtInspector.DrawAALine(anchor, vector);
            Joint2DExtInspector.DrawAALine(connectedAnchor + vector2, connectedAnchor - vector2);
            Joint2DExtInspector.DrawAALine(vector + vector2, vector - vector2);
        }
        protected Vector3 SnapToSprites(Vector3 position)
        {
            SpriteRenderer component = anchorJoint2D.GetComponent <SpriteRenderer>();

            position = Joint2DExtInspector.SnapToSprite(component, position, k_SnapDistance);
            if (anchorJoint2D.connectedBody)
            {
                component = anchorJoint2D.connectedBody.GetComponent <SpriteRenderer>();
                position  = Joint2DExtInspector.SnapToSprite(component, position, k_SnapDistance);
            }
            return(position);
        }
        public virtual void OnSceneGUI()
        {
            anchorJoint2D = (AnchoredJoint2DExt)target;
            anchorJoint2D.SetConnectedAnchorEditor();
            Vector3 vector              = Joint2DExtInspector.TransformPoint(anchorJoint2D.transform, anchorJoint2D.anchor);
            Vector3 vector2             = anchorJoint2D.connectedAnchor;
            bool    hideConnectedAnchor = false;

            if (anchorJoint2D.connectedBody)
            {
                vector2 = Joint2DExtInspector.TransformPoint(anchorJoint2D.connectedBody.transform, vector2);
            }
            else
            {
                hideConnectedAnchor = anchorJoint2D.autoConfigureConnectedAnchor;
            }
            Vector3 vector3 = vector + (vector2 - vector).normalized * HandleUtility.GetHandleSize(vector) * 0.1f;

            Handles.color = Color.green;
            if (!hideConnectedAnchor)
            {
                Handles.DrawAAPolyLine(new Vector3[] {
                    vector3,
                    vector2
                });
            }
            if (!hideConnectedAnchor)
            {
                if (HandleAnchor(ref vector2, true))
                {
                    vector2 = SnapToSprites(vector2);
                    vector2 = Joint2DExtInspector.SnapToPoint(vector2, vector, k_SnapDistance);
                    if (anchorJoint2D.connectedBody)
                    {
                        vector2 = Joint2DExtInspector.InverseTransformPoint(anchorJoint2D.connectedBody.transform, vector2);
                    }
                    anchorJoint2D.autoConfigureConnectedAnchor = false;
                    anchorJoint2D.connectedAnchor = vector2;
                    EditorUtility.SetDirty(anchorJoint2D);
                }
            }
            if (HandleAnchor(ref vector, false))
            {
                vector = SnapToSprites(vector);
                vector = Joint2DExtInspector.SnapToPoint(vector, vector2, k_SnapDistance);
                anchorJoint2D.anchor = Joint2DExtInspector.InverseTransformPoint(anchorJoint2D.transform, vector);
                EditorUtility.SetDirty(anchorJoint2D);
            }
        }
Example #8
0
        public void OnSceneGUI()
        {
            var angleJoint2D = (AngleJoint2DExt)target;

            if (!angleJoint2D.enabled)
            {
                return;
            }
            Vector3 vector  = angleJoint2D.transform.position;
            Vector3 vector2 = vector;
            Vector3 vector3 = vector;
            Vector3 vector4 = Joint2DExtInspector.RotateVector2(Vector3.right, -angleJoint2D.targetAngle);

            Handles.color = Color.green;
            vector4      *= HandleUtility.GetHandleSize(vector) * 0.6f;
            vector2      += vector4;
            Joint2DExtInspector.DrawAALine(vector2, vector3);
        }
Example #9
0
        public override sealed void OnSceneGUI()
        {
            var wheelJoint2D = (WheelJoint2DExt)this.target;

            if (!wheelJoint2D.enabled)
            {
                return;
            }
            Vector3 vector  = Joint2DExtInspector.TransformPoint(wheelJoint2D.transform, wheelJoint2D.anchor);
            Vector3 vector2 = vector;
            Vector3 vector3 = vector;
            Vector3 vector4 = Joint2DExtInspector.RotateVector2(Vector3.right, -wheelJoint2D.suspension.angle);

            Handles.color = Color.green;
            vector4      *= HandleUtility.GetHandleSize(vector) * 0.3f;
            vector2      += vector4;
            vector3      -= vector4;
            Joint2DExtInspector.DrawAALine(vector2, vector3);
            base.OnSceneGUI();
        }
        void DrawTick(Vector3 center, float radius, float angle, Vector3 up, float length)
        {
            Vector3 a          = Joint2DExtInspector.RotateVector2(up, angle).normalized;
            Vector3 vector     = center + a * radius;
            Vector3 vector2    = vector + (center - vector).normalized * radius * length;
            var     methodInfo = typeof(Handles).GetMethod("DrawAAPolyLine", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static, null, new System.Type[] { typeof(Color[]), typeof(Vector3[]) }, null);
            var     args       = new object[]
            {
                new Color[]
                {
                    new Color(0.0f, 1.0f, 0.0f, 0.7f),
                    new Color(0.0f, 1.0f, 0.0f, 0.0f)
                },
                new Vector3[] {
                    vector,
                    vector2
                }
            };

            methodInfo.Invoke(null, args);
        }
        public override sealed void OnSceneGUI()
        {
            HingeJoint2DExt hingeJoint2D = (HingeJoint2DExt)target;

            if (!hingeJoint2D.enabled)
            {
                return;
            }
            if (hingeJoint2D.useLimits)
            {
                Vector3 vector  = Joint2DExtInspector.TransformPoint(hingeJoint2D.transform, hingeJoint2D.anchor);
                Vector3 vector2 = Vector2.up;
                if (Application.isPlaying)
                {
                    vector2 = Joint2DExtInspector.RotateVector2(Vector2.up, hingeJoint2D.referenceAngle + hingeJoint2D.limits.min);
                }
                else
                {
                    vector2 = Joint2DExtInspector.RotateVector2(hingeJoint2D.transform.up, hingeJoint2D.limits.min);
                }
                float   angle   = hingeJoint2D.limits.max - hingeJoint2D.limits.min;
                float   num     = HandleUtility.GetHandleSize(vector) * 0.8f;
                float   d       = HandleUtility.GetHandleSize(vector) * 0.1f;
                Vector3 vector3 = vector + hingeJoint2D.transform.up * num;
                Vector3 start   = vector + (vector3 - vector).normalized * d;
                Handles.color = new Color(0.0f, 1.0f, 0.0f, 0.7f);
                Joint2DExtInspector.DrawAALine(start, vector3);
                Handles.color = new Color(0.0f, 1.0f, 0.0f, 0.03f);
                Handles.DrawSolidArc(vector, Vector3.back, vector2, angle, num);
                Handles.color = new Color(0.0f, 1.0f, 0.0f, 0.7f);
                Handles.DrawWireArc(vector, Vector3.back, vector2, angle, num);
                DrawTick(vector, num, 0.0f, vector2, 1.0f);
                DrawTick(vector, num, angle, vector2, 1.0f);
            }
            base.OnSceneGUI();
        }
Example #12
0
 protected static Vector3 InverseTransformPoint(Transform transform, Vector3 position)
 {
     return(Joint2DExtInspector.GetAnchorSpaceMatrix(transform).inverse.MultiplyPoint(position));
 }