Files
modular-vr/Assets/Engine/Runtime/Utilities/Utilities.cs

40 lines
1.4 KiB
C#

using System.Collections.Generic;
using System.Linq;
using UnityEngine;
namespace EscapeRoomEngine.Engine.Runtime.Utilities
{
public static class Utilities
{
#region Math
/// <summary>
/// Returns whether a position relative to some placement is inside its dimensions.
/// </summary>
/// <param name="position">The position to check, relative to the placement.</param>
/// <param name="placement">The placement to check the position against.</param>
public static bool IsInsideRelative(this Vector3Int position, Placement placement)
{
return position.x >= 0 && position.z >= 0 && position.x < placement.size.x && position.z < placement.size.y;
}
#endregion
#region Randomness
public static int RandomInclusive(int from, int to) => Random.Range(from, to + 1);
public static T RandomElement<T>(this List<T> list) => list[Random.Range(0, list.Count)];
public static T RandomElement<T>(this HashSet<T> set) => set.ElementAt(Random.Range(0, set.Count));
#endregion
}
public static class Vector2IntExtensions
{
public static Vector3Int ProjectAtFloor(this Vector2Int vector) => vector.ProjectAtHeight(0);
public static Vector3Int ProjectAtHeight(this Vector2Int vector, int height) =>
new Vector3Int(vector.x, height, vector.y);
}
}