TrueSync
TSCapsuleCollider.cs
1 using UnityEngine;
2 using UnityEngine.Serialization;
3 
4 namespace TrueSync {
8  [AddComponentMenu("TrueSync/Physics/CapsuleCollider", 0)]
9  public class TSCapsuleCollider : TSCollider {
10 
11  [FormerlySerializedAs("radius")]
12  [SerializeField]
13  private FP _radius;
14 
18  public FP radius {
19  get {
20  if (_body != null) {
21  return ((CapsuleShape)_body.Shape).Radius;
22  }
23 
24  return _radius;
25  }
26  set {
27  _radius = value;
28 
29  if (_body != null) {
30  ((CapsuleShape)_body.Shape).Radius = _radius;
31  }
32  }
33  }
34 
35  [FormerlySerializedAs("length")]
36  [SerializeField]
37  private FP _length;
38 
42  public FP length {
43  get {
44  if (_body != null) {
45  return ((CapsuleShape)_body.Shape).Length;
46  }
47 
48  return _length;
49  }
50  set {
51  _length = value;
52 
53  if (_body != null) {
54  ((CapsuleShape)_body.Shape).Length = _length;
55  }
56  }
57  }
58 
62  public override Shape CreateShape() {
63  return new CapsuleShape(length, radius);
64  }
65 
66  protected override void DrawGizmos() {
67  Gizmos.DrawWireSphere(Vector3.zero, 1);
68  Gizmos.DrawWireSphere(new TSVector(0, length / radius - 2 * radius, 0).ToVector(), 1);
69  Gizmos.DrawWireSphere(new TSVector(0, -length / radius + 2 * radius, 0).ToVector(), 1);
70  }
71 
72  protected override Vector3 GetGizmosSize() {
73  return Vector3.one * radius.AsFloat();
74  }
75 
76  }
77 }
Shape Shape
Shape used by a collider.
Definition: TSCollider.cs:19
override Shape CreateShape()
Create the internal shape used to represent a TSCapsuleCollider.
Collider with a capsule shape.
override void DrawGizmos()
Draws the specific gizmos of concrete collider (for example "Gizmos.DrawWireCube" for a TSBoxCollider...
override Vector3 GetGizmosSize()
Returns the gizmos size.
A vector structure.
Definition: TSVector.cs:29
FP radius
Radius of the capsule.
Abstract collider for 3D shapes.
Definition: TSCollider.cs:12
FP length
Length of the capsule.