TrueSync: TSCapsuleCollider.cs Source File

TrueSync

TSCapsuleCollider.cs
1 using UnityEngine;
2 using UnityEngine.Serialization;
3 using TrueSync.Physics3D;
4 
5 namespace TrueSync {
9  [AddComponentMenu("TrueSync/Physics/CapsuleCollider", 0)]
10  public class TSCapsuleCollider : TSCollider {
11 
12  [FormerlySerializedAs("radius")]
13  [SerializeField]
14  private FP _radius;
15 
19  public FP radius {
20  get {
21  if (_body != null) {
22  return ((CapsuleShape)_body.Shape).Radius;
23  }
24 
25  return _radius;
26  }
27  set {
28  _radius = value;
29 
30  if (_body != null) {
31  ((CapsuleShape)_body.Shape).Radius = _radius;
32  }
33  }
34  }
35 
36  [FormerlySerializedAs("length")]
37  [SerializeField]
38  private FP _length;
39 
43  public FP length {
44  get {
45  if (_body != null) {
46  return ((CapsuleShape)_body.Shape).Length;
47  }
48 
49  return _length;
50  }
51  set {
52  _length = value;
53 
54  if (_body != null) {
55  ((CapsuleShape)_body.Shape).Length = _length;
56  }
57  }
58  }
59 
63  public override Shape CreateShape() {
64  return new CapsuleShape(length, radius);
65  }
66 
67  protected override void DrawGizmos() {
68  Gizmos.DrawWireSphere(Vector3.zero, 1);
69  Gizmos.DrawWireSphere(new TSVector(0, length / radius - 2 * radius, 0).ToVector(), 1);
70  Gizmos.DrawWireSphere(new TSVector(0, -length / radius + 2 * radius, 0).ToVector(), 1);
71  }
72 
73  protected override Vector3 GetGizmosSize() {
74  return Vector3.one * radius.AsFloat();
75  }
76 
77  }
78 }
Shape Shape
Shape used by a collider.
Definition: TSCollider.cs:20
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.
FP radius
Radius of the capsule.
Abstract collider for 3D shapes.
Definition: TSCollider.cs:13
FP length
Length of the capsule.
Generated by   doxygen 1.8.11