using System.Collections; using System.Collections.Generic; using UnityEngine; /// /// Class used to write extension methodes in /// public static class ExtensionMethods { /// /// Converts provided Direction to Global Vector3 /// /// Direction to convert /// Global Vector3 direction public static Vector3 ToVector(this Direction direction) { switch (direction) { case Direction.Forward: return Vector3.forward; case Direction.Right: return Vector3.right; case Direction.Back: return Vector3.back; case Direction.Left: return Vector3.left; default: return Vector3.zero; } } /// /// Converts provided Direction to local Vector3 /// /// Direction to convert /// Transform to use as directions local space /// Local Vector3 direction public static Vector3 ToVector(this Direction direction, Transform transform) { switch (direction) { case Direction.Forward: return transform.forward; case Direction.Right: return transform.right; case Direction.Back: return -transform.forward; case Direction.Left: return -transform.right; default: return Vector3.zero; } } public static Rect GlobalRect(this RectTransform rt) { var r = rt.rect; Vector2 centre = rt.TransformPoint(r.center); r.size = rt.TransformVector(r.size); r.center = centre; return r; } }