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