示例#1
0
    void OnDrawGizmos()
    {
        if (NumberOfSides != LastNumberOfSides)
        {
            pointsList        = LPShapeTools.makePolyPoints(NumberOfSides, radius);
            LastNumberOfSides = NumberOfSides;
            LastRadius        = radius;
        }
        if (radius != LastRadius)
        {
            pointsList = LPShapeTools.ChangeRadius(radius - LastRadius, pointsList, Vector3.zero);
            LastRadius = radius;
        }

        bool loop = true;

        if (DontDrawLoop)
        {
            loop = false;
        }

        if (!Application.isPlaying)
        {
            if (pointsList == null)
            {
                pointsList = LPShapeTools.makePolyPoints(NumberOfSides, radius);
            }
            LPShapeTools.DrawGizmos(GetColors(), LPShapeTools.TransformPoints(transform, Vector3.zero, pointsList), loop);
        }
    }
示例#2
0
    void OnDrawGizmos()
    {
        if (Rotation != LastRotation)
        {
            pointsList   = LPShapeTools.RotatePoints(pointsList, Rotation - LastRotation, new Vector3(Offset.x, Offset.y));
            LastRotation = Rotation;
        }
        if (Offset != LastOffset)
        {
            pointsList = LPShapeTools.OffsetPoints(Offset - LastOffset, pointsList);
            LastOffset = Offset;
        }

        if (!Application.isPlaying)
        {
            if (pointsList == null)
            {
                pointsList = LPShapeTools.MakeEdgePoints();
            }
            LPShapeTools.DrawGizmos(GetColor(), LPShapeTools.TransformPoints(transform, Vector3.zero, pointsList), IsLoop);
        }
        else
        {
            if (PointsCopy != null)
            {
                LPShapeTools.DrawGizmosPlaying(transform, true, GetComponent <LPBody>().GetDiff(), GetColor(), PointsCopy, IsLoop);
            }
        }
    }
示例#3
0
 public override IntPtr GetShape()
 {
     Shapetype = LPShapeTypes.Polygon;
     if (pointsList == null)
     {
         pointsList = LPShapeTools.MakeBoxPoints(Size);
     }
     PointsCopy = LPShapeTools.TransformPoints(transform, transform.position, pointsList);
     return(LPShapeTools.Initialise(PointsCopy));
 }
示例#4
0
    protected override IntPtr GetShape()
    {
        if (pointsList == null)
        {
            pointsList = LPShapeTools.MakeBoxPoints(Size);
        }
        PointsCopy = LPShapeTools.TransformPoints(transform, Vector3.zero, pointsList);

        return(LPShapeTools.Initialise(PointsCopy));
    }
示例#5
0
    private bool CheckDists(Transform transform, List <Vector3> pointsList, Vector3 tran, Vector3 mousepos, int controlID
                            , out int closest, out float dist, Color col, bool editme)
    {
        tran = new Vector3(tran.x, tran.y, 0f);
        Vector3[] points = LPShapeTools.TransformPoints(transform, tran, pointsList);
        closest = 0;
        dist    = 10f;
        bool       isclosest  = false;
        List <int> contenders = new List <int>();

        for (int i = 0; i < points.Length; i++)
        {
            points[i] = new Vector3(points[i].x, points[i].y, 0f);
            if ((mousepos - (points[i] + tran)).magnitude < 1f)
            {
                contenders.Add(i);
            }
        }

        if (contenders.Count > 0)
        {
            isclosest = true;
            closest   = contenders[0];
            dist      = (mousepos - (points[contenders[0]] + tran)).sqrMagnitude;

            if (contenders.Count > 1)
            {
                for (int i = 1; i < contenders.Count; i++)
                {
                    float compdist = (mousepos - (points[contenders[i]] + tran)).sqrMagnitude;
                    if (compdist < dist)
                    {
                        dist    = compdist;
                        closest = contenders[i];
                    }
                }
            }
        }

        for (int i = 0; i < points.Length; i++)
        {
            if (isclosest && i == closest && editme)
            {
                Handles.color = Color.yellow;
            }
            else
            {
                Handles.color = col;
            }

            Handles.DotCap(controlID, points[i] + tran, Quaternion.identity, HandleUtility.GetHandleSize(points[i] + tran) * 0.07f);
        }
        return(isclosest);
    }
示例#6
0
    void OnDrawGizmos()
    {
        if (true)
        {
            Gizmos.color = LPColors.Joint;

            Gizmos.DrawLine(BodyA.transform.position + LPShapeTools.RotatePoint((Vector3)BodyAAnchorOffset, BodyA.transform.rotation.eulerAngles.z, Vector3.zero),
                            BodyB.transform.position + LPShapeTools.RotatePoint((Vector3)BodyBAnchorOffset, BodyB.transform.rotation.eulerAngles.z, Vector3.zero));
        }
        Gizmos.DrawIcon(transform.position, @"LiquidPhysics2D/Icon_rope", false);
    }
示例#7
0
    void OnDrawGizmos()
    {
        if (NumberOfSides != LastNumberOfSides)
        {
            pointsList        = LPShapeTools.makePolyPoints(NumberOfSides, radius);
            LastNumberOfSides = NumberOfSides;
            LastRotation      = 0f;
            LastOffset        = Vector2.zero;
        }
        if (radius != LastRadius)
        {
            pointsList = LPShapeTools.ChangeRadius(radius - LastRadius, pointsList, new Vector3(Offset.x, Offset.y));
            LastRadius = radius;
        }

        if (Offset != LastOffset)
        {
            pointsList = LPShapeTools.OffsetPoints(Offset - LastOffset, pointsList);
            LastOffset = Offset;
        }

        if (Rotation != LastRotation)
        {
            pointsList   = LPShapeTools.RotatePoints(pointsList, Rotation - LastRotation, new Vector3(Offset.x, Offset.y));
            LastRotation = Rotation;
        }

        bool loop = true;

        if (DontDrawLoop)
        {
            loop = false;
        }

        if (!Application.isPlaying)
        {
            if (pointsList == null)
            {
                pointsList = LPShapeTools.makePolyPoints(NumberOfSides, radius);
            }
            LPShapeTools.DrawGizmos(GetColor(), LPShapeTools.TransformPoints(transform, Vector3.zero, pointsList), loop);
        }
        else
        {
            if (PointsCopy != null)
            {
                LPShapeTools.DrawGizmosPlaying(transform, true, GetComponent <LPBody>().GetDiff(), GetColor(), PointsCopy, loop);
            }
        }
    }
示例#8
0
    static void ConvertEdges()
    {
        foreach (EdgeCollider2D Edge in FindObjectsOfType <EdgeCollider2D>())
        {
            GameObject          ob     = Edge.gameObject;
            LPFixtureChainShape lpEdge = Undo.AddComponent <LPFixtureChainShape>(ob);

            lpEdge.DefinePoints(LPShapeTools.Vec2ArrayToVec3Array(Edge.points));
            CopyGeneric(Edge, lpEdge);

            Undo.DestroyObjectImmediate(Edge);

            Setupdynamics(ob);
        }
    }
示例#9
0
    static void ConvertPolys()
    {
        foreach (PolygonCollider2D poly in FindObjectsOfType <PolygonCollider2D>())
        {
            GameObject    ob     = poly.gameObject;
            LPFixturePoly lppoly = Undo.AddComponent <LPFixturePoly>(ob);

            lppoly.DefinePoints(LPShapeTools.Vec2ArrayToVec3Array(poly.points));
            CopyGeneric(poly, lppoly);

            Undo.DestroyObjectImmediate(poly);

            Setupdynamics(ob);
        }
    }
示例#10
0
    void OnDrawGizmos()
    {
        Gizmos.color = LPColors.Joint;
        Gizmos.DrawLine(transform.position + (Vector3)BodyAGroundOffset, transform.position + (Vector3)BodyBGroundOffset);
        Gizmos.DrawWireSphere(transform.position + (Vector3)BodyAGroundOffset, 0.15f);

        Gizmos.DrawLine(transform.position + (Vector3)BodyAGroundOffset, BodyA.transform.position +
                        LPShapeTools.RotatePoint((Vector3)BodyAAnchorOffset, BodyA.transform.rotation.eulerAngles.z, Vector3.zero));

        Gizmos.DrawWireSphere(transform.position + (Vector3)BodyBGroundOffset, 0.15f);

        Gizmos.DrawLine(transform.position + (Vector3)BodyBGroundOffset, BodyB.transform.position
                        + LPShapeTools.RotatePoint((Vector3)BodyBAnchorOffset, BodyB.transform.rotation.eulerAngles.z, Vector3.zero));

        Gizmos.DrawIcon(transform.position, @"LiquidPhysics2D/Icon_pulley", false);
    }
示例#11
0
    /// <summary>
    /// Gets a pointer to a Box2D poly shape object. First checks that: shape is complex or not,
    /// points are in counter-clockwise order and shape is convex or not </summary>
    protected IntPtr GetPolyShape(int NumberOfSides, float radius, Vector3 tran)
    {
        if (pointsList == null)
        {
            pointsList = LPShapeTools.makePolyPoints(NumberOfSides, radius);
        }
        PointsCopy = LPShapeTools.TransformPoints(transform, tran, pointsList);

        //check complex
        if (LPShapeTools.CheckComplex(PointsCopy))
        {
            LogComplex();
            PointsCopy = LPShapeTools.TransformPoints(transform, tran, LPShapeTools.makePolyPoints(4, 1f));
        }

        //check anticlockwise
        if (!LPShapeTools.CheckAntiClockwise(PointsCopy))
        {
            Array.Reverse(PointsCopy);
        }

        //check convex. If convex use decomposer and create multiple fixtures
        if (PointsCopy.Length > 8 || !LPShapeTools.CheckConvex(PointsCopy))
        {
            List <Vector2> verts = new List <Vector2>();

            foreach (Vector3 point in PointsCopy)
            {
                verts.Add(new Vector2(point.x, point.y));
            }
            List <List <Vector2> > bits = PolygonDecomposerAPI.DecomposePolygon(verts);

            if (bits.Count > 1)
            {
                SubPtrs = new List <IntPtr>();
                for (int i = 1; i < bits.Count; i++)
                {
                    InitialiseWithShape(LPShapeTools.Initialise(LPShapeTools.Vec2listToVec3Array(bits[i])));
                }
            }

            return(LPShapeTools.Initialise(LPShapeTools.Vec2listToVec3Array(bits[0])));
        }

        return(LPShapeTools.Initialise(PointsCopy));
    }
示例#12
0
    public override IntPtr GetShape()
    {
        if (pointsList == null)
        {
            pointsList = LPShapeTools.MakeEdgePoints();
        }
        PointsCopy = LPShapeTools.TransformPoints(transform, transform.position, pointsList);

        if (pointsList.Count > 2)
        {
            Shapetype = LPShapeTypes.ChainShape;
            return(LPAPIShape.GetChainShapeDef(LPShapeTools.GetfloatArray(PointsCopy), IsLoop));
        }
        else
        {
            Shapetype = LPShapeTypes.Edge;
            return(LPAPIShape.GetEdgeShapeDef(PointsCopy[0].x, PointsCopy[0].y, PointsCopy[1].x, PointsCopy[1].y));
        }
    }
示例#13
0
    void OnDrawGizmos()
    {
        if (Size != LastSize)
        {
            pointsList   = LPShapeTools.MakeBoxPoints(Size);
            LastRotation = 0f;
            LastSize     = Size;
        }

        if (Rotation != LastRotation)
        {
            pointsList   = LPShapeTools.RotatePoints(pointsList, Rotation - LastRotation, Vector3.zero);
            LastRotation = Rotation;
        }

        if (!Application.isPlaying)
        {
            if (pointsList == null)
            {
                pointsList = LPShapeTools.MakeBoxPoints(Size);
            }
            LPShapeTools.DrawGizmos(GetColors(), LPShapeTools.TransformPoints(transform, Vector3.zero, pointsList), true);
        }
    }
示例#14
0
    private bool DrawLines(Transform transform, List <Vector3> pointsList, Vector3 tran, Vector3 mousepos, int controlID, out int closest, out float dist
                           , Color col, bool editme)
    {
        tran = new Vector3(tran.x, tran.y, 0f);
        Vector3[] points = LPShapeTools.TransformPoints(transform, tran, pointsList);
        closest = 0;
        dist    = 10f;
        bool       isclosest  = false;
        List <int> contenders = new List <int>();

        for (int i = 0; i < points.Length; i++)
        {
            int j = i + 1;
            if (j == points.Length)
            {
                j = 0;
            }

            points[i] = new Vector3(points[i].x, points[i].y, 0f);
            points[j] = new Vector3(points[j].x, points[j].y, 0f);
            if (HandleUtility.DistancePointLine(mousepos, points[i] + tran, points[j] + tran) < 1f)
            {
                contenders.Add(i);
            }
        }

        if (contenders.Count > 0)
        {
            isclosest = true;
            closest   = contenders[0];
            int closest2 = closest + 1;
            if (closest2 == points.Length)
            {
                closest2 = 0;
            }
            dist = HandleUtility.DistancePointLine(mousepos, points[closest] + tran, points[closest2] + tran);

            if (contenders.Count > 1)
            {
                for (int i = 1; i < contenders.Count; i++)
                {
                    int index  = contenders[i];
                    int index2 = index + 1;
                    if (index2 == points.Length)
                    {
                        index2 = 0;
                    }

                    float dist2 = HandleUtility.DistancePointLine(mousepos, points[index] + tran, points[index2] + tran);

                    if (dist2 < dist)
                    {
                        dist    = dist2;
                        closest = contenders[i];
                    }
                }
            }
        }

        if (editme && isclosest)
        {
            Handles.color = col;
            int closest2 = closest + 1;
            if (closest2 == points.Length)
            {
                closest2 = 0;
            }
            Handles.DrawAAPolyLine(10f, new Vector3[2] {
                points[closest] + tran, points[closest2] + tran
            });                                                                                                   //DrawLine();
        }

        return(isclosest);
    }