UnityGameProjectsCode / DiceAndMenGame / Extensions.cs
Extensions.cs
Raw
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public static class Extensions
{
    /// <summary>
    /// Creates Vector3Int where (.5, -.5, .1) => (1, -1, 0)
    /// </summary>
    /// <param name="vec"></param>
    /// <returns></returns>
    public static Vector3Int RoundToInt(this Vector3 vec)
    {
        return new Vector3Int(
            Mathf.RoundToInt(vec.x),
            Mathf.RoundToInt(vec.y),
            Mathf.RoundToInt(vec.z));
    }

    /// <summary>
    /// Creates Vector3Int where (.5, -.5, .1) => (0, -1, 0)
    /// </summary>
    /// <param name="vec"></param>
    /// <returns></returns>
    public static Vector3Int FloorToInt(this Vector3 vec)
    {
        return new Vector3Int(
            Mathf.FloorToInt(vec.x),
            Mathf.FloorToInt(vec.y),
            Mathf.FloorToInt(vec.z));
    }

    /// <summary>
    /// Creates Vector3Int where (.5, -.5, .1) => (0, 0, 0)
    /// </summary>
    /// <param name="vec"></param>
    /// <returns></returns>
    public static Vector3Int TruncateToInt(this Vector3 vec)
    {
        return new Vector3Int(
            (int)(vec.x),
            (int)(vec.y),
            (int)(vec.z));
    }
}