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;
    }
Exemplo n.º 3
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;
    }
Exemplo n.º 4
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;
    }