TrueSync
TSCircleCollider2D.cs
1 using UnityEngine;
2 using UnityEngine.Serialization;
3 
4 namespace TrueSync {
8  [AddComponentMenu("TrueSync/Physics/CircleCollider2D", 0)]
10 
11  [FormerlySerializedAs("radius")]
12  [SerializeField]
13  private FP _radius = 0.5f;
14 
18  public FP radius {
19  get {
20  if (_body != null) {
21  return ((Physics2D.CircleShape) _body.FixtureList[0].Shape).Radius;
22  }
23 
24  return _radius;
25  }
26  set {
27  _radius = value;
28 
29  if (_body != null) {
30  Physics2D.CircleShape cShape = (Physics2D.CircleShape) _body.FixtureList[0].Shape;
31  if (cShape.Radius != _radius) {
32  cShape.Radius = _radius;
33  }
34  }
35  }
36  }
37 
41  public void Reset() {
42  if (GetComponent<CircleCollider2D>() != null) {
43  CircleCollider2D circleCollider2D = GetComponent<CircleCollider2D>();
44 
45  radius = circleCollider2D.radius;
46  Center = new TSVector2(circleCollider2D.offset.x, circleCollider2D.offset.y);
47  isTrigger = circleCollider2D.isTrigger;
48  } else if (GetComponent<SphereCollider>() != null) {
49  SphereCollider sphereCollider = GetComponent<SphereCollider>();
50 
51  radius = sphereCollider.radius;
52  Center = sphereCollider.center.ToTSVector2();
53  isTrigger = sphereCollider.isTrigger;
54  }
55  }
56 
60  public override TrueSync.Physics2D.Shape CreateShape() {
61  return new TrueSync.Physics2D.CircleShape(radius, 1);
62  }
63 
64  protected override void DrawGizmos() {
65  Gizmos.DrawWireSphere(Vector3.zero, 1);
66  }
67 
68  protected override Vector3 GetGizmosSize() {
69  return Vector3.one * radius.AsFloat();
70  }
71 
72  }
73 
74 }
bool isTrigger
If it is only a trigger and doesn&#39;t interfere on collisions.
Definition: TSCollider2D.cs:30
override TrueSync.Physics2D.Shape CreateShape()
Create the internal shape used to represent a TSSphereCollider.
override Vector3 GetGizmosSize()
Returns the gizmos size.
void Reset()
Sets initial values to radius based on a pre-existing SphereCollider or CircleCollider2D.
TSVector2 Center
Center of the collider shape.
Definition: TSCollider2D.cs:60
Collider with a circle shape.
FP radius
Radius of the sphere.
Abstract collider for 2D shapes.
Definition: TSCollider2D.cs:11
override void DrawGizmos()
Draws the specific gizmos of concrete collider (for example "Gizmos.DrawWireCube" for a TSBoxCollider...