VectorUtils.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using UnityEngine;
  2. namespace XGame.Database
  3. {
  4. public static class VectorUtils
  5. {
  6. ///// <summary>
  7. ///// Vector3 -> Vec3 µÄ±¶Êý
  8. ///// </summary>
  9. //public static readonly int Multiple = 1000;
  10. #region Vec3
  11. /// <summary>
  12. /// Vec3 -> Vector3
  13. /// </summary>
  14. /// <param name="vec"></param>
  15. /// <returns></returns>
  16. public static Vector3 ToVector3(this Vec3 vec)
  17. {
  18. return new Vector3(vec.X, vec.Y, vec.Z);
  19. }
  20. /// <summary>
  21. /// Vec3 -> Vector3Int
  22. /// </summary>
  23. /// <param name="vec"></param>
  24. /// <returns></returns>
  25. public static Vector3Int ToVector3Int(this Vec3 vec)
  26. {
  27. return Vector3Int.RoundToInt(new Vector3(vec.X, vec.Y, vec.Z));
  28. }
  29. #endregion
  30. #region Vec2
  31. /// <summary>
  32. /// Vec2 -> Vector2
  33. /// </summary>
  34. /// <param name="vec"></param>
  35. /// <returns></returns>
  36. public static Vector2 ToVector2(this Vec2 vec)
  37. {
  38. return new Vector2(vec.X, vec.Y);
  39. }
  40. /// <summary>
  41. /// Vec2 -> Vector2Int
  42. /// </summary>
  43. /// <param name="vec"></param>
  44. /// <returns></returns>
  45. public static Vector2Int ToVector2Int(this Vec2 vec)
  46. {
  47. return Vector2Int.RoundToInt(new Vector2(vec.X, vec.Y));
  48. }
  49. #endregion
  50. }
  51. }