9 public static class DirectionUtils
14 public static Vector3 GetRadialDirection (
this Transform transform)
22 public static Vector3 GetRadialDirection (
this Rigidbody rigidbody)
24 return rigidbody.transform.GetRadialDirection();
30 public static Vector3 GetDirection (
this Transform transform)
32 Sync sync = transform.GetComponent<
Sync>();
35 return sync.GetDirection();
36 else return transform.GetRadialDirection();
42 public static Vector3 GetDirection (
this Rigidbody rigidbody)
44 Sync sync = rigidbody.GetComponent<
Sync>();
47 return sync.GetDirection();
48 else return rigidbody.GetRadialDirection();
54 public static Vector3 GetFlipDirection (
this Transform transform)
56 return transform.localScale.x < 0 ? Vector3.left : Vector3.right;
62 public static Vector3 GetFlipDirection (
this Rigidbody rigidbody)
64 return rigidbody.transform.GetFlipDirection();
70 public static void SetRadialDirection (
this Transform transform, Vector3 direction)
72 transform.rotation = direction.Get2DRotation();
78 public static void SetRadialDirection (
this Rigidbody rigidbody, Vector3 direction)
80 rigidbody.MoveRotation(direction.Get2DRotation());
86 public static void SetFlipDirection (
this Transform transform, Vector3 direction)
88 var scale = transform.localScale;
89 scale.x = Mathf.Abs(scale.x) * Mathf.Sign(direction.x);
91 if (scale != transform.localScale)
93 transform.localScale = scale;
96 transform.localScale = transform.localScale;
103 public static void SetFlipDirection (
this Rigidbody rigidbody, Vector3 direction)
105 rigidbody.transform.SetFlipDirection(direction);
111 public static void SetDirection (
this Transform transform, Vector3 direction)
113 Sync sync = transform.GetComponent<
Sync>();
116 sync.SetDirection(direction,
true);
117 else transform.SetRadialDirection(direction);
123 public static void SetDirection (
this Rigidbody rigidbody, Vector3 direction)
125 Sync sync = rigidbody.GetComponent<
Sync>();
128 sync.SetDirection(direction);
129 else rigidbody.SetRadialDirection(direction);
135 public static void RollToward (
this Transform transform, Vector3 direction,
float t)
137 transform.rotation = transform.up.RollToward(direction, t).Get2DRotation();
143 public static void RollToward (
this Rigidbody rigidbody, Vector3 direction,
float t)
145 rigidbody.MoveRotation(rigidbody.transform.up.RollToward(direction, t).Get2DRotation());
This class server two main functions: 1) As a MonoBehaviour, it allows for network synchronization of...