TrueSync: TSSphereCollider.cs Source File

TrueSync

TSSphereCollider.cs
1 using UnityEngine;
2 using UnityEngine.Serialization;
3 using TrueSync.Physics3D;
4 
5 namespace TrueSync {
9  [AddComponentMenu("TrueSync/Physics/SphereCollider", 0)]
10  public class TSSphereCollider : TSCollider {
11 
12  [FormerlySerializedAs("radius")]
13  [SerializeField]
14  private float _radius;
15 
19  public FP radius {
20  get {
21  if (_body != null) {
22  return ((SphereShape)_body.Shape).Radius;
23  }
24 
25  return _radius;
26  }
27 
28  set {
29  _radius = value.AsFloat();
30 
31  if (_body != null) {
32  ((SphereShape)_body.Shape).Radius = value;
33  }
34  }
35  }
36 
40  public void Reset() {
41  if (GetComponent<CircleCollider2D>() != null) {
42  CircleCollider2D circleCollider2D = GetComponent<CircleCollider2D>();
43 
44  radius = circleCollider2D.radius;
45  Center = new TSVector(circleCollider2D.offset.x, circleCollider2D.offset.y, 0);
46  isTrigger = circleCollider2D.isTrigger;
47  } else if (GetComponent<SphereCollider>() != null) {
48  SphereCollider sphereCollider = GetComponent<SphereCollider>();
49 
50  radius = sphereCollider.radius;
51  Center = sphereCollider.center.ToTSVector();
52  isTrigger = sphereCollider.isTrigger;
53  }
54  }
55 
59  public override Shape CreateShape() {
60  return new SphereShape(radius);
61  }
62 
63  protected override void DrawGizmos() {
64  Gizmos.DrawWireSphere(Vector3.zero, 1);
65  }
66 
67  protected override Vector3 GetGizmosSize() {
68  return Vector3.one * radius.AsFloat();
69  }
70 
71  }
72 
73 }
Shape Shape
Shape used by a collider.
Definition: TSCollider.cs:20
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:36
Abstract collider for 3D shapes.
Definition: TSCollider.cs:13
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:68
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.
Generated by   doxygen 1.8.11