public void Start()
    {
        joints = SmartJoint2D.GetJoints(gameObject);

        Max2D.Check();
        material = new Material(Max2D.lineMaterial);
    }
Exemple #2
0
    public static List <SmartJoint2D> GetJoints(GameObject gameObject)
    {
        List <SmartJoint2D> result = new List <SmartJoint2D>();

        foreach (DistanceJoint2D joint in gameObject.GetComponents <DistanceJoint2D>())
        {
            SmartJoint2D joint2D = new SmartJoint2D(Type.DistanceJoint2D);
            joint2D.distanceJoint2D = joint;
            joint2D.anchoredJoint2D = (AnchoredJoint2D)joint;
            joint2D.gameObject      = joint.gameObject;
            result.Add(joint2D);
        }

        foreach (FixedJoint2D joint in gameObject.GetComponents <FixedJoint2D>())
        {
            SmartJoint2D joint2D = new SmartJoint2D(Type.FixedJoint2D);
            joint2D.fixedJoint2D    = joint;
            joint2D.anchoredJoint2D = (AnchoredJoint2D)joint;
            joint2D.gameObject      = joint.gameObject;
            result.Add(joint2D);
        }

        foreach (FrictionJoint2D joint in gameObject.GetComponents <FrictionJoint2D>())
        {
            SmartJoint2D joint2D = new SmartJoint2D(Type.FrictionJoint2D);
            joint2D.frictionJoint2D = joint;
            joint2D.anchoredJoint2D = (AnchoredJoint2D)joint;
            joint2D.gameObject      = joint.gameObject;
            result.Add(joint2D);
        }

        foreach (HingeJoint2D joint in gameObject.GetComponents <HingeJoint2D>())
        {
            SmartJoint2D joint2D = new SmartJoint2D(Type.HingeJoint2D);
            joint2D.hingeJoint2D    = joint;
            joint2D.anchoredJoint2D = (AnchoredJoint2D)joint;
            joint2D.gameObject      = joint.gameObject;
            result.Add(joint2D);
        }

        foreach (SliderJoint2D joint in gameObject.GetComponents <SliderJoint2D>())
        {
            SmartJoint2D joint2D = new SmartJoint2D(Type.SliderJoint2D);
            joint2D.sliderJoint2D   = joint;
            joint2D.anchoredJoint2D = (AnchoredJoint2D)joint;
            joint2D.gameObject      = joint.gameObject;
            result.Add(joint2D);
        }

        foreach (SpringJoint2D joint in gameObject.GetComponents <SpringJoint2D>())
        {
            SmartJoint2D joint2D = new SmartJoint2D(Type.SpringJoint2D);
            joint2D.springJoint2D   = joint;
            joint2D.anchoredJoint2D = (AnchoredJoint2D)joint;
            joint2D.gameObject      = joint.gameObject;
            result.Add(joint2D);
        }

        foreach (WheelJoint2D joint in gameObject.GetComponents <WheelJoint2D>())
        {
            SmartJoint2D joint2D = new SmartJoint2D(Type.WheelJoint2D);
            joint2D.wheelJoint2D    = joint;
            joint2D.anchoredJoint2D = (AnchoredJoint2D)joint;
            result.Add(joint2D);
            joint2D.gameObject = joint.gameObject;
        }

        foreach (TargetJoint2D joint in gameObject.GetComponents <TargetJoint2D>())
        {
            SmartJoint2D joint2D = new SmartJoint2D(Type.SpringJoint2D);
            joint2D.targetJoint2D = joint;
            joint2D.gameObject    = joint.gameObject;
            result.Add(joint2D);
        }

        //foreach(RelativeJoint2D joint in gameObject.GetComponents<RelativeJoint2D>()) {
        //	Joint2D joint2D = new Joint2D(Type.RelativeJoint2D);
        //	joint2D.relativeJoint2D = joint;
        //	joint2D.gameObject = joint.gameObject;
        //	result.Add(joint2D);
        //}


        return(result);
    }
Exemple #3
0
    public static List <SmartJoint2D> GetJointsConnected()
    {
        List <SmartJoint2D> result = new List <SmartJoint2D>();

        foreach (AnchoredJoint2D anchoredJoint in Object.FindObjectsOfType <AnchoredJoint2D>())
        {
            if (anchoredJoint.connectedBody != null)
            {
                foreach (DistanceJoint2D joint in anchoredJoint.gameObject.GetComponents <DistanceJoint2D>())
                {
                    if (joint.connectedBody != null)
                    {
                        SmartJoint2D joint2D = new SmartJoint2D(Type.DistanceJoint2D);
                        joint2D.distanceJoint2D = joint;
                        joint2D.anchoredJoint2D = (AnchoredJoint2D)joint;
                        joint2D.gameObject      = joint.gameObject;
                        result.Add(joint2D);
                    }
                }

                foreach (FixedJoint2D joint in anchoredJoint.gameObject.GetComponents <FixedJoint2D>())
                {
                    if (joint.connectedBody != null)
                    {
                        SmartJoint2D joint2D = new SmartJoint2D(Type.FixedJoint2D);
                        joint2D.fixedJoint2D    = joint;
                        joint2D.anchoredJoint2D = (AnchoredJoint2D)joint;
                        joint2D.gameObject      = joint.gameObject;
                        result.Add(joint2D);
                    }
                }

                foreach (FrictionJoint2D joint in anchoredJoint.gameObject.GetComponents <FrictionJoint2D>())
                {
                    if (joint.connectedBody != null)
                    {
                        SmartJoint2D joint2D = new SmartJoint2D(Type.FrictionJoint2D);
                        joint2D.frictionJoint2D = joint;
                        joint2D.anchoredJoint2D = (AnchoredJoint2D)joint;
                        joint2D.gameObject      = joint.gameObject;
                        result.Add(joint2D);
                    }
                }

                foreach (HingeJoint2D joint in anchoredJoint.gameObject.GetComponents <HingeJoint2D>())
                {
                    if (joint.connectedBody != null)
                    {
                        SmartJoint2D joint2D = new SmartJoint2D(Type.HingeJoint2D);
                        joint2D.hingeJoint2D    = joint;
                        joint2D.anchoredJoint2D = (AnchoredJoint2D)joint;
                        joint2D.gameObject      = joint.gameObject;
                        result.Add(joint2D);
                    }
                }

                foreach (SliderJoint2D joint in anchoredJoint.gameObject.GetComponents <SliderJoint2D>())
                {
                    if (joint.connectedBody != null)
                    {
                        SmartJoint2D joint2D = new SmartJoint2D(Type.SliderJoint2D);
                        joint2D.sliderJoint2D   = joint;
                        joint2D.anchoredJoint2D = (AnchoredJoint2D)joint;
                        joint2D.gameObject      = joint.gameObject;
                        result.Add(joint2D);
                    }
                }

                foreach (SpringJoint2D joint in anchoredJoint.gameObject.GetComponents <SpringJoint2D>())
                {
                    if (joint.connectedBody != null)
                    {
                        SmartJoint2D joint2D = new SmartJoint2D(Type.SpringJoint2D);
                        joint2D.springJoint2D   = joint;
                        joint2D.anchoredJoint2D = (AnchoredJoint2D)joint;
                        joint2D.gameObject      = joint.gameObject;
                        result.Add(joint2D);
                    }
                }

                foreach (WheelJoint2D joint in anchoredJoint.gameObject.GetComponents <WheelJoint2D>())
                {
                    if (joint.connectedBody != null)
                    {
                        SmartJoint2D joint2D = new SmartJoint2D(Type.WheelJoint2D);
                        joint2D.wheelJoint2D    = joint;
                        joint2D.anchoredJoint2D = (AnchoredJoint2D)joint;
                        joint2D.gameObject      = joint.gameObject;
                        result.Add(joint2D);
                    }
                }
            }
        }

        //foreach(RelativeJoint2D joint in Object.FindObjectsOfType<RelativeJoint2D>()) {
        //	if (joint.connectedBody == connected) {
        //		Joint2D joint2D = new Joint2D(Type.RelativeJoint2D);
        //		joint2D.relativeJoint2D = joint;
        //		result.Add(joint2D);
        //	}
        //}

        //foreach(TargetJoint2D joint in Object.FindObjectsOfType<TargetJoint2D>()) {
        //	if (joint.connectedBody == connected) {
        //		Joint2D joint2D = new Joint2D(Type.SpringJoint2D);
        //		joint2D.targetJoint2D = joint;
        //		result.Add(joint2D);
        //	}
        //}

        return(result);
    }