1 using System.Collections.Generic;
9 [AddComponentMenu(
"TrueSync/Physics/PolygonCollider2D", 0)]
13 private TSVector2[] _points;
15 public TSVector2[] points {
31 if (_points == null || _points.Length == 0) {
37 TrueSync.Physics2D.Vertices v =
new Physics2D.Vertices();
38 for (
int index = 0, length = _points.Length; index < length; index++) {
39 v.Add(TSVector2.Scale(_points[index], lossy2D));
42 List<
TrueSync.Physics2D.Vertices> convexShapeVs =
TrueSync.Physics2D.BayazitDecomposer.ConvexPartition(v);
43 TrueSync.Physics2D.Shape[] result =
new Physics2D.Shape[convexShapeVs.Count];
44 for (
int index = 0, length = result.Length; index < length; index++) {
45 result[index] =
new TrueSync.Physics2D.PolygonShape(convexShapeVs[index], 1);
55 private void DrawPolygon(TSVector2[] allPoints) {
56 if (allPoints == null || allPoints.Length == 0) {
60 for (
int index = 0, length = allPoints.Length - 1; index < length; index++) {
61 Gizmos.DrawLine(allPoints[index].ToVector(), allPoints[index+1].ToVector());
64 Gizmos.DrawLine(allPoints[allPoints.Length - 1].ToVector(), allPoints[0].ToVector());
override TrueSync.Physics2D.Shape[] CreateShapes()
Create the internal shape used to represent a PolygonCollider.
Collider with a polygon 2D shape.
override void DrawGizmos()
Draws the specific gizmos of concrete collider (for example "Gizmos.DrawWireCube" for a TSBoxCollider...
TSVector lossyScale
Holds an first value of the GameObject's lossy scale.
override Vector3 GetGizmosSize()
Returns the gizmos size.
Abstract collider for 2D shapes.