示例#1
0
    public static void UpdateFarseerPhysics(RageSpline spline)
    {
#if !UNITY_FLASH
        var fsConcave = spline.GetComponent <FSConcaveShapeComponent>();
        if (fsConcave == null)
        {
            fsConcave = spline.gameObject.AddComponent <FSConcaveShapeComponent>();
        }
        var fsBody = spline.GetComponent <FSBodyComponent>();
        if (fsBody == null)
        {
            spline.gameObject.AddComponent <FSBodyComponent>();
        }
        fsConcave.PointInput = FSShapePointInput.Vector2List;
        var points = new List <Vector2>();
        if (spline.FarseerPhysicsPointsOnly)
        {
            for (int i = 0; i < spline.GetPointCount(); i++)
            {
                points.Add(spline.GetPosition(i));
            }
        }
        else
        {
            int splitCount = spline.LockPhysicsToAppearence ? spline.GetVertexCount() : spline.GetPhysicsColliderCount();
            for (int i = 0; i < splitCount; i++)
            {
                float   splinePos = (float)i / (float)splitCount;
                Vector3 normal    = spline.GetNormal(splinePos);
                points.Add(spline.GetPosition(splinePos) + normal * spline.GetPhysicsNormalOffset());
            }
        }
        fsConcave.PointsCoordinates = points.ToArray();
        fsConcave.ConvertToConvex();
#endif
    }