Esempio n. 1
0
    public void AttachObject(GameObject obj, int jointIndex, RopeAttachmentJointType jointType, Vector3 hingeAxis, bool centerOnIndex)
    {
        if (gameObject.GetComponent <QuickRope2Cloth>())
        {
            Debug.LogError("You must use the \"Cloth\" component to attach objects when using the Cloth mesh type.");
            return;
        }

        RopeAttachedObject rao = new RopeAttachedObject();

        rao.go         = obj;
        rao.jointIndex = jointIndex;
        rao.jointType  = jointType;
        rao.hingeAxis  = hingeAxis;

        if (centerOnIndex)
        {
            rao.go.transform.position = Joints[rao.jointIndex].transform.position;
        }

        attachedObjects.Add(rao);

        if (Application.isPlaying)
        {
            if (rao.go == null)
            {
                return;
            }

            switch (rao.jointType)
            {
            case RopeAttachmentJointType.Fixed:
                rao.jointRef = Joints[rao.jointIndex].AddComponent <FixedJoint>();
                rao.jointRef.connectedBody = rao.go.rigidbody;
                break;

            case RopeAttachmentJointType.Hinge:
                //rao.jointRef = Joints[rao.jointIndex].AddComponent<HingeJoint>();
                //(rao.jointRef as HingeJoint).axis = rao.hingeAxis;
                //rao.jointRef.connectedBody = rao.go.rigidbody;

                rao.jointRef = rao.go.AddComponent <HingeJoint>();                    //ao.jointRef = Joints[ao.jointIndex].AddComponent<HingeJoint>();
                (rao.jointRef as HingeJoint).axis = rao.hingeAxis;
                rao.jointRef.connectedBody        = Joints[rao.jointIndex].rigidbody; //ao.jointRef.connectedBody = ao.go.rigidbody;

                break;
            }
        }
    }
Esempio n. 2
0
 public void AttachObject(GameObject obj, int jointIndex, RopeAttachmentJointType jointType, bool centerOnIndex)
 {
     AttachObject(obj, jointIndex, jointType, Vector3.forward, centerOnIndex);
 }
Esempio n. 3
0
 public void AttachObject(GameObject obj, int jointIndex, RopeAttachmentJointType jointType, bool centerOnIndex)
 {
     AttachObject(obj, jointIndex, jointType, Vector3.forward, centerOnIndex);
 }
Esempio n. 4
0
    public void AttachObject(GameObject obj, int jointIndex, RopeAttachmentJointType jointType, Vector3 hingeAxis, bool centerOnIndex)
    {
        if (gameObject.GetComponent<QuickRope2Cloth>())
        {
            Debug.LogError("You must use the \"Cloth\" component to attach objects when using the Cloth mesh type.");
            return;
        }

        RopeAttachedObject rao = new RopeAttachedObject();
        rao.go = obj;
        rao.jointIndex = jointIndex;
        rao.jointType = jointType;
        rao.hingeAxis = hingeAxis;

        if (centerOnIndex)
            rao.go.transform.position = Joints[rao.jointIndex].transform.position;

        attachedObjects.Add(rao);

        if (Application.isPlaying)
        {
            if (rao.go == null)
                return;

            switch (rao.jointType)
            {
                case RopeAttachmentJointType.Fixed:
                    rao.jointRef = Joints[rao.jointIndex].AddComponent<FixedJoint>();
                    rao.jointRef.connectedBody = rao.go.rigidbody;
                    break;
                case RopeAttachmentJointType.Hinge:
                    //rao.jointRef = Joints[rao.jointIndex].AddComponent<HingeJoint>();
                    //(rao.jointRef as HingeJoint).axis = rao.hingeAxis;
                    //rao.jointRef.connectedBody = rao.go.rigidbody;

                    rao.jointRef = rao.go.AddComponent<HingeJoint>();//ao.jointRef = Joints[ao.jointIndex].AddComponent<HingeJoint>();
                    (rao.jointRef as HingeJoint).axis = rao.hingeAxis;
                    rao.jointRef.connectedBody = Joints[rao.jointIndex].rigidbody;//ao.jointRef.connectedBody = ao.go.rigidbody;

                    break;
            }
        }
    }