public virtual void CopyToSpringBody(JelloBody oldBody, JelloSpringBody newBody)
    {
        newBody.affectedByGravity    = oldBody.affectedByGravity;
        newBody.disabled             = oldBody.disabled;
        newBody.gravity              = oldBody.gravity;
        newBody.IsAwake              = oldBody.IsAwake;
        newBody.IsKinematic          = oldBody.IsKinematic;
        newBody.IsStatic             = false;
        newBody.IsTrigger            = oldBody.IsTrigger;
        newBody.overrideWorldGravity = oldBody.overrideWorldGravity;
        newBody.pivotOffset          = oldBody.pivotOffset;
        newBody.setComponentReferences();
        newBody.polyCollider = oldBody.polyCollider;

        if (oldBody.meshLink != null)
        {
            newBody.meshLink      = oldBody.meshLink;
            newBody.meshLink.body = newBody;
        }

        if (oldBody.Shape != null)
        {
            newBody.setShape(oldBody.Shape, shapeSettingOptions);
            newBody.Mass = oldBody.Mass != Mathf.Infinity ? oldBody.Mass : 1f;
        }

        for (int i = 0; i < oldBody.EdgePointMassCount; i++)
        {
            newBody.setEdgePointMass(oldBody.getEdgePointMass(i), i);
            newBody.getEdgePointMass(i).body = newBody;

            if (oldBody.Mass == Mathf.Infinity)
            {
                newBody.getEdgePointMass(i).Mass = 1f;
            }
        }
        for (int i = 0; i < oldBody.InternalPointMassCount; i++)
        {
            newBody.setInternalPointMass(oldBody.getInternalPointMass(i), i);
            newBody.getInternalPointMass(i).body = newBody;

            if (oldBody.Mass == Mathf.Infinity)
            {
                newBody.getInternalPointMass(i).Mass = 1f;
            }
        }
        for (int i = 0; i < oldBody.AttachPointCount; i++)
        {
            newBody.AddAttachPoint(oldBody.GetAttachPoint(i));
            newBody.GetAttachPoint(i).body = newBody;
        }
        for (int i = 0; i < oldBody.JointCount; i++)
        {
            newBody.AddJoint(oldBody.GetJoint(i));
            newBody.GetJoint(i).bodyA = newBody;
        }

        EditorUtility.SetDirty(newBody);
    }
示例#2
0
    public virtual void CopyToSpringBody(JelloBody oldBody, JelloSpringBody newBody)
    {
        newBody.affectedByGravity = oldBody.affectedByGravity;
        newBody.disabled = oldBody.disabled;
        newBody.gravity = oldBody.gravity;
        newBody.IsAwake = oldBody.IsAwake;
        newBody.IsKinematic = oldBody.IsKinematic;
        newBody.IsStatic = false;
        newBody.IsTrigger = oldBody.IsTrigger;
        newBody.overrideWorldGravity = oldBody.overrideWorldGravity;
        newBody.pivotOffset = oldBody.pivotOffset;
        newBody.setComponentReferences();
        newBody.polyCollider = oldBody.polyCollider;

        if(oldBody.meshLink != null)
        {
            newBody.meshLink = oldBody.meshLink;
            newBody.meshLink.body = newBody;
        }

        if(oldBody.Shape != null)
        {
            newBody.setShape(oldBody.Shape, shapeSettingOptions);
            newBody.Mass = oldBody.Mass != Mathf.Infinity ? oldBody.Mass : 1f;
        }

        for(int i = 0; i < oldBody.EdgePointMassCount; i++)
        {
            newBody.setEdgePointMass(oldBody.getEdgePointMass(i), i);
            newBody.getEdgePointMass(i).body = newBody;

            if(oldBody.Mass == Mathf.Infinity)
                newBody.getEdgePointMass(i).Mass = 1f;
        }
        for(int i = 0; i < oldBody.InternalPointMassCount; i++)
        {
            newBody.setInternalPointMass(oldBody.getInternalPointMass(i), i);
            newBody.getInternalPointMass(i).body = newBody;

            if(oldBody.Mass == Mathf.Infinity)
                newBody.getInternalPointMass(i).Mass = 1f;
        }
        for(int i = 0; i < oldBody.AttachPointCount; i++)
        {
            newBody.AddAttachPoint(oldBody.GetAttachPoint(i));
            newBody.GetAttachPoint(i).body = newBody;
        }
        for(int i = 0; i < oldBody.JointCount; i++)
        {
            newBody.AddJoint(oldBody.GetJoint(i));
            newBody.GetJoint(i).bodyA = newBody;
        }

        EditorUtility.SetDirty(newBody);
    }