using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
/// <summary>
|
|
/// Class used to write extension methodes in
|
|
/// </summary>
|
|
public static class ExtensionMethods
|
|
{
|
|
|
|
/// <summary>
|
|
/// Converts provided Direction to Global Vector3
|
|
/// </summary>
|
|
/// <param name="direction">Direction to convert</param>
|
|
/// <returns>Global Vector3 direction</returns>
|
|
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;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Converts provided Direction to local Vector3
|
|
/// </summary>
|
|
/// <param name="direction">Direction to convert</param>
|
|
/// <param name="transform">Transform to use as directions local space</param>
|
|
/// <returns>Local Vector3 direction</returns>
|
|
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;
|
|
}
|
|
}
|
|
|
|
|