public virtual void CopyToPressureBody(JelloBody oldBody, JelloPressureBody 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);
    }
    public void ChangePivot(JelloBody t)
    {
        t.polyCollider.points = JelloShapeTools.RemoveDuplicatePoints(t.polyCollider.points);

        t.Shape.changeVertices(t.polyCollider.points, t.Shape.InternalVertices);

        Vector2 diff = pivot;

        diff = new Vector2(diff.x / t.Scale.x, diff.y / t.Scale.y);
        diff = JelloVectorTools.rotateVector(diff, -t.Angle);


        if (t.meshLink != null)
        {
            MonoBehaviour monoBehavior;
            if (t.meshLink.UpdatePivotPoint(diff, out monoBehavior))
            {
                EditorUtility.SetDirty(monoBehavior);
            }
        }

        for (int i = 0; i < t.Shape.VertexCount; i++)
        {
            t.Shape.setVertex(i, t.Shape.getVertex(i) - diff);
        }

        t.polyCollider.points = t.Shape.EdgeVertices;

        t.transform.position += (Vector3)JelloVectorTools.rotateVector(new Vector2(diff.x * t.Scale.x, diff.y * t.Scale.y), t.Angle);
        if (t.transform.childCount > 0)
        {
            for (int i = 0; i < t.transform.childCount; i++)
            {
                t.transform.GetChild(i).position -= (Vector3)diff;
            }
        }

        if (t.JointCount > 0)
        {
            for (int i = 0; i < t.JointCount; i++)
            {
                t.GetJoint(i).localAnchorA -= diff;
            }
        }

        if (t.AttachPointCount > 0)
        {
            for (int i = 0; i < t.AttachPointCount; i++)
            {
                t.GetAttachPoint(i).point -= diff;
            }
        }

        t.updateGlobalShape(true);

        EditorUtility.SetDirty(t);

        pivot = Vector2.zero;
    }
    public void CenterPivot(JelloBody t)
    {
        Vector2 center = new Vector2();

        t.polyCollider.points = JelloShapeTools.RemoveDuplicatePoints(t.polyCollider.points);
        t.Shape.changeVertices(t.polyCollider.points, t.Shape.InternalVertices);


        center = JelloShapeTools.FindCenter(t.Shape.EdgeVertices);        //using vertices instead of collider.points because need of assigning entire array at once


        if (t.meshLink != null)
        {
            MonoBehaviour monoBehavior;
            if (t.meshLink.UpdatePivotPoint(center, out monoBehavior))
            {
                EditorUtility.SetDirty(monoBehavior);
            }
        }

        for (int i = 0; i < t.Shape.VertexCount; i++)
        {
            t.Shape.setVertex(i, t.Shape.getVertex(i) - center);
        }

        t.polyCollider.points = t.Shape.EdgeVertices;

        t.transform.position += (Vector3)JelloVectorTools.rotateVector(new Vector2(center.x * t.Scale.x, center.y * t.Scale.y), t.Angle);
        if (t.transform.childCount > 0)
        {
            for (int i = 0; i < t.transform.childCount; i++)
            {
                t.transform.GetChild(i).position -= (Vector3)center;
            }
        }

        if (t.JointCount > 0)
        {
            for (int i = 0; i < t.JointCount; i++)
            {
                t.GetJoint(i).localAnchorA -= center;
            }
        }

        if (t.AttachPointCount > 0)
        {
            for (int i = 0; i < t.AttachPointCount; i++)
            {
                t.GetAttachPoint(i).point -= center;
            }
        }

        t.updateGlobalShape(true);

        EditorUtility.SetDirty(t);

        pivot = Vector2.zero;
    }
예제 #4
0
	public void CopyToStaticBody(JelloBody oldBody, JelloBody newBody) //TODO make sure these all are up to date with any new variables that need assigning
	{
		newBody.affectedByGravity = oldBody.affectedByGravity;
		newBody.disabled = oldBody.disabled;
		newBody.gravity = oldBody.gravity;
		newBody.IsAwake = oldBody.IsAwake;
		newBody.IsKinematic = oldBody.IsKinematic;
		newBody.IsStatic = tar.IsStatic;
		newBody.IsStatic = true;
		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 = Mathf.Infinity;
		}
		
		for(int i = 0; i < oldBody.EdgePointMassCount; i++)
		{
			newBody.setEdgePointMass(oldBody.getEdgePointMass(i), i);
			newBody.getEdgePointMass(i).Mass = Mathf.Infinity;
			newBody.getEdgePointMass(i).body = newBody;
		}
		for(int i = 0; i < oldBody.InternalPointMassCount; i++)
		{
			newBody.setInternalPointMass(oldBody.getInternalPointMass(i), i);
			newBody.getInternalPointMass(i).Mass = Mathf.Infinity;
			newBody.getInternalPointMass(i).body = newBody;
		}
		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);
	}
예제 #5
0
    //TODO make sure these all are up to date with any new variables that need assigning
    public void CopyToStaticBody(JelloBody oldBody, JelloBody newBody)
    {
        newBody.affectedByGravity = oldBody.affectedByGravity;
        newBody.disabled = oldBody.disabled;
        newBody.gravity = oldBody.gravity;
        newBody.IsAwake = oldBody.IsAwake;
        newBody.IsKinematic = oldBody.IsKinematic;
        newBody.IsStatic = tar.IsStatic;
        newBody.IsStatic = true;
        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 = Mathf.Infinity;
        }

        for(int i = 0; i < oldBody.EdgePointMassCount; i++)
        {
            newBody.setEdgePointMass(oldBody.getEdgePointMass(i), i);
            newBody.getEdgePointMass(i).Mass = Mathf.Infinity;
            newBody.getEdgePointMass(i).body = newBody;
        }
        for(int i = 0; i < oldBody.InternalPointMassCount; i++)
        {
            newBody.setInternalPointMass(oldBody.getInternalPointMass(i), i);
            newBody.getInternalPointMass(i).Mass = Mathf.Infinity;
            newBody.getInternalPointMass(i).body = newBody;
        }
        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);
    }
예제 #6
0
    public void ChangePivot(JelloBody t)
    {
        t.polyCollider.points = JelloShapeTools.RemoveDuplicatePoints(t.polyCollider.points);

        t.Shape.changeVertices(t.polyCollider.points, t.Shape.InternalVertices);

        Vector2 diff = pivot;
        diff = new Vector2(diff.x / t.Scale.x, diff.y / t.Scale.y);
        diff = JelloVectorTools.rotateVector( diff, -t.Angle);

        if(t.meshLink != null)
        {
            MonoBehaviour monoBehavior;
            if(t.meshLink.UpdatePivotPoint(diff, out monoBehavior))
                EditorUtility.SetDirty(monoBehavior);
        }

        for(int i = 0; i < t.Shape.VertexCount; i++)
            t.Shape.setVertex(i, t.Shape.getVertex(i) - diff);

        t.polyCollider.points = t.Shape.EdgeVertices;

        t.transform.position += (Vector3)JelloVectorTools.rotateVector(new Vector2(diff.x * t.Scale.x, diff.y * t.Scale.y), t.Angle);
        if(t.transform.childCount > 0)
            for(int i = 0; i < t.transform.childCount; i++)
                t.transform.GetChild(i).position -= (Vector3)diff;

        if(t.JointCount > 0)
            for(int i = 0; i < t.JointCount; i++)
                t.GetJoint (i).localAnchorA -= diff;

        if(t.AttachPointCount > 0)
            for(int i = 0; i < t.AttachPointCount; i++)
                t.GetAttachPoint(i).point -= diff;

        t.updateGlobalShape(true);

        EditorUtility.SetDirty(t);

        pivot = Vector2.zero;
    }
예제 #7
0
    public void CenterPivot(JelloBody t)
    {
        Vector2 center = new Vector2();

        t.polyCollider.points = JelloShapeTools.RemoveDuplicatePoints(t.polyCollider.points);
        t.Shape.changeVertices(t.polyCollider.points, t.Shape.InternalVertices);

        center = JelloShapeTools.FindCenter(t.Shape.EdgeVertices);//using vertices instead of collider.points because need of assigning entire array at once

        if(t.meshLink != null)
        {
            MonoBehaviour monoBehavior;
            if(t.meshLink.UpdatePivotPoint(center, out monoBehavior))
                EditorUtility.SetDirty(monoBehavior);
        }

        for(int i = 0; i < t.Shape.VertexCount; i++)
            t.Shape.setVertex(i, t.Shape.getVertex(i) - center);

        t.polyCollider.points = t.Shape.EdgeVertices;

        t.transform.position += (Vector3)JelloVectorTools.rotateVector(new Vector2(center.x * t.Scale.x, center.y * t.Scale.y), t.Angle);
        if(t.transform.childCount > 0)
            for(int i = 0; i < t.transform.childCount; i++)
                t.transform.GetChild(i).position -= (Vector3)center;

        if(t.JointCount > 0)
            for(int i = 0; i < t.JointCount; i++)
                t.GetJoint (i).localAnchorA -= center;

        if(t.AttachPointCount > 0)
            for(int i = 0; i < t.AttachPointCount; i++)
                t.GetAttachPoint(i).point -= center;

        t.updateGlobalShape(true);

        EditorUtility.SetDirty(t);

        pivot = Vector2.zero;
    }