Initial commit

This commit is contained in:
2026-06-02 18:57:47 -04:00
commit 59d26a915d
268 changed files with 41240 additions and 0 deletions
+44
View File
@@ -0,0 +1,44 @@
using System;
using System.Collections;
using UnityEngine.TestTools;
namespace BracerLib.Utility
{
[ExcludeFromCoverage]
public static class ArrayExtensions
{
public static bool Contains<T>(this T[] array, T value) where T : IComparable
{
for (var i = 0; i < array.Length; i++)
{
if (array[i].CompareTo(value) == 0)
return true;
}
return false;
}
public static bool Contains<T, U>(this T[] array, U value, Func<T, U, bool> predicate)
{
for (var i = 0; i < array.Length; i++)
{
if (predicate(array[i], value))
return true;
}
return false;
}
public static T[] Subset<T>(this T[] data, int index, int length)
{
var result = new T[length];
Array.Copy(data, index, result, 0, length);
return result;
}
public static bool HasIndex(this IList list, int index) => index >= 0 && index < list.Count;
public static bool HasIndex(this Array array, int index) => index >= 0 && index < array.Length;
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 5fe12305b0d411b41bb552e80e21d2c5
+31
View File
@@ -0,0 +1,31 @@
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.TestTools;
namespace BracerLib.Utility
{
[ExcludeFromCoverage]
public static class CameraUtility
{
private static Camera mainCamera;
public static Camera MainCamera
{
get
{
if (mainCamera == null)
mainCamera = Camera.main;
return mainCamera;
}
}
public static Vector3 MouseToWorldPoint()
{
var screenPosition = (Vector3)Mouse.current.position.ReadValue();
screenPosition.z = mainCamera.nearClipPlane;
return mainCamera.ScreenToWorldPoint(screenPosition);
}
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 16fe30152b82df3439d6cd584b5603f7
@@ -0,0 +1,11 @@
using UnityEngine;
using UnityEngine.TestTools;
namespace BracerLib.Utility
{
[ExcludeFromCoverage]
public static class CoroutineUtility
{
public static readonly WaitForEndOfFrame WAIT_END_OF_FRAME = new WaitForEndOfFrame();
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: c41498bcbc999014bb88eaa4c886662d
@@ -0,0 +1,18 @@
using System.IO;
using UnityEngine;
using UnityEngine.TestTools;
namespace BracerLib.Utility
{
[ExcludeFromCoverage]
public static class DirectoryUtility
{
private const string FOLDER_SCRIPTABLE_DATA = "Scriptables";
public static string AssetPath => Application.dataPath;
public static string DataPath => Path.Combine(AssetPath, FOLDER_SCRIPTABLE_DATA);
public static void CreateDirectory(string path) => Directory.CreateDirectory(path);
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 70c2b1f7783b82e4bb38be51e9a3ee8d
@@ -0,0 +1,15 @@
using UnityEngine;
using UnityEngine.TestTools;
namespace BracerLib.Utility
{
[ExcludeFromCoverage]
public class EditorOnlyObject : MonoBehaviour
{
private void Awake()
{
if (Application.isPlaying)
Destroy(gameObject);
}
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: b3d9a97f953c3834ab17f72144e3c68e
+15
View File
@@ -0,0 +1,15 @@
using System;
using UnityEngine.TestTools;
namespace BracerLib.Utility
{
[ExcludeFromCoverage]
public static class EnumUtility
{
public static T GetValue<T>(int index) where T : IConvertible => (T)Enum.ToObject(typeof(T), index);
public static T GetValue<T>(string value) where T : IConvertible => (T)Enum.Parse(typeof(T), value, true);
public static T[] GetValues<T>() where T : IConvertible => (T[])Enum.GetValues(typeof(T));
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: f0af1e16642bde44a9213b87a7940873
+44
View File
@@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using UnityEngine.TestTools;
namespace BracerLib.Utility
{
/// <summary>
/// An object-oriented, extensible base class to represent an enum type.
/// </summary>
[ExcludeFromCoverage]
public abstract class Enumeration : IComparable
{
public static IEnumerable<T> GetAll<T>() where T : Enumeration =>
typeof(T).GetFields(BindingFlags.Public
| BindingFlags.Static
| BindingFlags.DeclaredOnly)
.Select(f => f.GetValue(null))
.Cast<T>();
public string Name { get; private set; }
public int Id { get; private set; }
protected Enumeration(int id, string name) => (Id, Name) = (id, name);
public override string ToString() => Name;
public override bool Equals(object obj)
{
if (obj is not Enumeration otherValue)
return false;
var typeMatches = GetType() == obj.GetType();
var valueMatches = Id.Equals(otherValue.Id);
return typeMatches && valueMatches;
}
public override int GetHashCode() => HashCode.Combine(Name, Id);
public int CompareTo(object obj) => Id.CompareTo(((Enumeration)obj).Id);
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 00be9a2e2cb17ca4fb5fd4855caafef0
+32
View File
@@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using UnityEngine.TestTools;
namespace BracerLib.Utility
{
[ExcludeFromCoverage]
public static class ListExtensions
{
public static bool Contains<T>(this T[] array, T value) where T : IComparable
{
for (var i = 0; i < array.Length; i++)
{
if (array[i].CompareTo(value) == 0)
return true;
}
return false;
}
public static bool Contains<T, U>(this List<T> list, U item, Func<T, U, bool> predicate)
{
for (var i = 0; i < list.Count; ++i)
{
if (predicate(list[i], item))
return true;
}
return false;
}
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 2bf3d9a83a2ae4946a0f64c698f37ca2
+93
View File
@@ -0,0 +1,93 @@
using UnityEngine;
namespace BracerLib.Utility
{
/// <summary>
/// Inclusivity determination for a comparison between a lower and upper bound number.
/// </summary>
public enum BoundsInclusivity
{
/// <summary>
/// Neither bound is included.
/// </summary>
None,
/// <summary>
/// Both bounds are included.
/// </summary>
Both,
/// <summary>
/// Left bound is included.
/// </summary>
Left,
/// <summary>
/// Right bound is included.
/// </summary>
Right
}
public static class MathUtility
{
public const float TWO_PI = 2f * Mathf.PI;
/// <summary>
/// Overflow of a value between two bounds. Values lower than the lowerbound will cycle from the upperbound and vice versa.
/// </summary>
/// <param name="value">The value to overflow, if needed.</param>
/// <param name="lowerBound">The lowerbound number to be checked against.</param>
/// <param name="upperBound">The upperbound number to be checked against.</param>
/// <returns>Inclusive value within the bounds.</returns>
public static int KeepWithinBounds(int value, int lowerBound, int upperBound)
{
var diff = upperBound - lowerBound + 1;
var v = (value - lowerBound) % diff + diff;
v = v % diff + lowerBound;
return v;
}
/// <summary>
/// Determine if a value is between a lower and upper bound set of numbers.
/// </summary>
/// <param name="value">The value to check.</param>
/// <param name="lowerBound">The lower bound of the comparison.</param>
/// <param name="upperBound">The upper bound of the comparison.</param>
/// <param name="inclusivity">The inclusivity bounds for the comparison.</param>
/// <returns>Whether the value is between the two numbers based on the inclusivity passed.</returns>
public static bool IsBetween(
int value,
int lowerBound,
int upperBound,
BoundsInclusivity inclusivity = BoundsInclusivity.None
)
{
var result = inclusivity switch
{
BoundsInclusivity.Both => value >= lowerBound && value <= upperBound,
BoundsInclusivity.Left => value >= lowerBound && value < upperBound,
BoundsInclusivity.Right => value > lowerBound && value <= upperBound,
_ => value > lowerBound && value < upperBound
};
return result;
}
/// <inheritdoc cref="IsBetween(int,int,int,BracerLib.Utility.BoundsInclusivity)" />
public static bool IsBetween(
float value,
float lowerBound,
float upperBound,
BoundsInclusivity inclusivity = BoundsInclusivity.None
)
{
var result = inclusivity switch
{
BoundsInclusivity.Both => value >= lowerBound && value <= upperBound,
BoundsInclusivity.Left => value >= lowerBound && value < upperBound,
BoundsInclusivity.Right => value > lowerBound && value <= upperBound,
_ => value > lowerBound && value < upperBound
};
return result;
}
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 6950e03105df6034da37cc9f7c066710
+113
View File
@@ -0,0 +1,113 @@
using System;
using UnityEngine;
using UnityEngine.TestTools;
using Random = System.Random;
using Vector2 = System.Numerics.Vector2;
using Vector3 = System.Numerics.Vector3;
namespace BracerLib.Utility
{
[ExcludeFromCoverage]
public static class RandomUtility
{
public static readonly string CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
[ThreadStatic]
private static Random unrepeatedRandomThreadInstance;
private static Random unrepeatedRandom => unrepeatedRandomThreadInstance ??= new Random(DateTime.Now.Millisecond);
private static int prevSeed = -1;
public static float NextFloat(this Random prng) => (float)prng.NextDouble();
public static float Range(this Random prng, float minInclusive, float maxExclusive)
=> minInclusive + (maxExclusive - minInclusive) * prng.NextFloat();
public static void RandomizeUnityRandom()
{
var seed = (int)DateTime.Now.Ticks;
if (seed != prevSeed)
return;
prevSeed = seed;
UnityEngine.Random.InitState(seed);
}
/// <summary> Random between 0.0 inclusive and 1.0 exclusive. </summary>
public static double NextDouble() => unrepeatedRandom.NextDouble();
/// <summary> Random between 0f inclusive and 1f exclusive. </summary>
public static float NextFloat() => unrepeatedRandom.NextFloat();
/// <summary>
/// Given a value, return a random number between the negative and positive of the input value.
/// </summary>
/// <param name="bookendRangeValue">Non-negative value.</param>
public static float Range(float bookendRangeValue) => unrepeatedRandom.Range(-bookendRangeValue, bookendRangeValue);
public static float Range(float minInclusive, float maxExclusive) => unrepeatedRandom.Range(minInclusive, maxExclusive);
public static int Range(int minInclusive, int maxExclusive) => unrepeatedRandom.Next(minInclusive, maxExclusive);
/// <summary> Random point uniformly distributed on the surface of a sphere of radius 1. </summary>
public static Vector3 RandomOnUnitSphere() {
var theta = MathUtility.TWO_PI * NextDouble();
var phi = Math.Acos(2.0 * NextDouble() - 1.0);
var sinPhi = Math.Sin(phi);
return new Vector3(
(float)(sinPhi * Math.Cos(theta)),
(float)(sinPhi * Math.Sin(theta)),
(float)Math.Cos(phi)
);
}
/// <summary> Random point uniformly distributed inside a sphere of radius 1. </summary>
public static Vector3 RandomInUnitSphere() => RandomOnUnitSphere() * (float)Math.Pow(NextDouble(), 1.0 / 3.0);
/// <summary> Random point uniformly distributed on the perimeter of a circle of radius 1. </summary>
public static Vector2 RandomOnUnitCircle() {
var angle = MathUtility.TWO_PI * NextDouble();
return new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle));
}
/// <summary> Random point uniformly distributed in a circle of radius 1. </summary>
public static Vector2 RandomInUnitCircle() => RandomOnUnitCircle() * (float)Math.Sqrt(NextDouble());
/// <summary> Random point uniformly distributed in a ring starting at radius1 and ending at radius2. </summary>
public static Vector2 RandomInRing(float r1, float r2) {
var r2sq = r2 * r2;
return RandomOnUnitCircle() * (float)Math.Sqrt(NextDouble() * (r1 * r1 - r2sq) + r2sq);
}
public static Color RandomColorRGB()
{
return new Color(
unrepeatedRandom.NextFloat(),
unrepeatedRandom.NextFloat(),
unrepeatedRandom.NextFloat(),
1f
);
}
public static Color RandomColorRGBA()
{
return new Color(
unrepeatedRandom.NextFloat(),
unrepeatedRandom.NextFloat(),
unrepeatedRandom.NextFloat(),
unrepeatedRandom.NextFloat()
);
}
public static string GetRandomString(int length)
{
var stringChars = new char[length];
var random = new Random();
for (var i = 0; i < stringChars.Length; i++)
stringChars[i] = CHARS[random.Next(CHARS.Length)];
return new string(stringChars);
}
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 431151141fd66ab49aa38604affb75c4
+34
View File
@@ -0,0 +1,34 @@
using System;
using System.Linq;
using System.Text.RegularExpressions;
using UnityEngine.TestTools;
namespace BracerLib.Utility
{
[ExcludeFromCoverage]
public static class RegexExtensions
{
public static T GrabValue<T>(this MatchCollection matches, string property)
{
var type = typeof(T);
var underlyingType = Nullable.GetUnderlyingType(type);
type = underlyingType ?? type;
foreach (var m in matches.Cast<Match>())
{
if (m.Groups[1].Value != property)
continue;
var value = m.Groups[2].Value;
if (type != typeof(bool))
return (T)Convert.ChangeType(value, type);
if (bool.TryParse(value, out var b))
return (T)Convert.ChangeType(b, type);
}
return default;
}
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 36e5a69e8b0b1724f97e84f459ce350e
+128
View File
@@ -0,0 +1,128 @@
using System;
using System.Collections.Generic;
using UnityEngine;
namespace BracerLib.Utility
{
/// <summary>
/// Sourced from https://mmems.gitbook.io/calepin/Algorithms/Polygon%20triangulation%20-%20tessellation/Triangulator%20-%20Unity
/// </summary>
public static class Triangulator
{
public static int[] Triangulate(Vector2[] points)
{
var n = points.Length;
if (n < 3)
return Array.Empty<int>();
var indices = new List<int>();
var verts = new int[n];
if (Area(points) > 0f)
{
for (var i = 0; i < n; i++)
verts[i] = i;
}
else
{
for (var i = 0; i < n; i++)
verts[i] = n - 1 - i;
}
var nv = n;
var count = 2 * nv;
for (int _ = 0, j = nv - 1; nv > 2;)
{
if (count-- <= 0)
return indices.ToArray();
var u = j;
if (nv <= u)
u = 0;
j = u + 1;
if (nv <= j)
j = 0;
var w = j + 1;
if (nv <= w)
w = 0;
if (!Snip(u, j, w, nv, points, verts))
continue;
indices.Add(verts[u]);
indices.Add(verts[j]);
indices.Add(verts[w]);
_++;
for (int s = j, t = j + 1; t < nv; s++, t++)
verts[s] = verts[t];
nv--;
count = 2 * nv;
}
indices.Reverse();
return indices.ToArray();
}
public static bool Snip(int u, int v, int w, int n, Vector2[] points, int[] verts)
{
var a = points[verts[u]];
var b = points[verts[v]];
var c = points[verts[w]];
if (Mathf.Epsilon > (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x))
return false;
for (var i = 0; i < n; i++)
{
if (i == u || i == v || i == w)
continue;
if (InsideTriangle(a, b, c, points[verts[i]]))
return false;
}
return true;
}
/// <summary>
/// Check if a point is inside of a triangle of 3 given points.
/// Used from https://blackpawn.com/texts/pointinpoly/
/// </summary>
public static bool InsideTriangle(Vector2 a, Vector2 b, Vector2 c, Vector2 p)
{
var v0 = c - a;
var v1 = b - a;
var v2 = p - a;
var dots = new[]
{
Vector2.Dot(v0, v0),
Vector2.Dot(v0, v1),
Vector2.Dot(v0, v2),
Vector2.Dot(v1, v1),
Vector2.Dot(v1, v2)
};
var invDenom = 1 / (dots[0] * dots[3] - dots[1] * dots[1]);
var u = (dots[3] * dots[2] - dots[1] * dots[4]) * invDenom;
var v = (dots[0] * dots[4] - dots[1] * dots[2]) * invDenom;
return u >= 0f && v >= 0f && u + v < 1;
}
public static float Area(Vector2[] points)
{
var n = points.Length;
var area = 0f;
for (int i = n - 1, j = 0; j < n; i = j++)
{
var iVal = points[i];
var jVal = points[j];
area += iVal.x * jVal.y - jVal.x * iVal.y;
}
return area * 0.5f;
}
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: a9d6996e34b8a71408e2f8b2f19fd6d5
+48
View File
@@ -0,0 +1,48 @@
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.SceneManagement;
using UnityEngine.TestTools;
namespace BracerLib.Utility
{
[ExcludeFromCoverage]
public static class UIUtility
{
private static bool performRefresh;
private static PointerEventData eventBuffer = new PointerEventData(EventSystem.current);
private static List<RaycastResult> raycastResultBuffer = new List<RaycastResult>(4);
static UIUtility()
{
SceneManager.activeSceneChanged += (before, after) => Refresh();
}
public static bool IsMouseOverUI(Vector2 position, int uiLayer)
{
var eventSystem = EventSystem.current;
eventBuffer.position = position;
eventSystem.RaycastAll(eventBuffer, raycastResultBuffer);
for (var i = 0; i < raycastResultBuffer.Count; i++)
{
var raycastResult = raycastResultBuffer[i];
if (raycastResult.gameObject.layer == uiLayer)
return true;
}
return false;
}
private static void Refresh()
{
var current = EventSystem.current;
if (current == null)
return;
eventBuffer = new PointerEventData(EventSystem.current);
}
}
}
+2
View File
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 3ded37ec57e76974ea31fe55ee797b90
+59
View File
@@ -0,0 +1,59 @@
using System;
using UnityEngine;
using UnityEngine.TestTools;
using Object = UnityEngine.Object;
namespace BracerLib.Utility
{
[ExcludeFromCoverage]
public class UnityLogger : MonoBehaviour, ILogger
{
public ILogHandler logHandler
{
get => Debug.unityLogger.logHandler;
set => Debug.unityLogger.logHandler = value;
}
public bool logEnabled
{
get => Debug.unityLogger.logEnabled;
set => Debug.unityLogger.logEnabled = value;
}
public LogType filterLogType
{
get => Debug.unityLogger.filterLogType;
set => Debug.unityLogger.filterLogType = value;
}
public void LogFormat(LogType logType, Object context, string format, params object[] args) => Debug.unityLogger.LogFormat(logType, context, format, args);
public void LogException(Exception exception, Object context) => Debug.unityLogger.LogException(exception, context);
public bool IsLogTypeAllowed(LogType logType) => Debug.unityLogger.IsLogTypeAllowed(logType);
public void Log(LogType logType, object message) => Debug.unityLogger.Log(logType, message);
public void Log(LogType logType, object message, Object context) => Debug.unityLogger.Log(logType, message, context);
public void Log(LogType logType, string logTag, object message) => Debug.unityLogger.Log(logType, logTag, message);
public void Log(LogType logType, string logTag, object message, Object context) => Debug.unityLogger.Log(logType, logTag, message, context);
public void Log(object message) => Debug.unityLogger.Log(message);
public void Log(string logTag, object message) => Debug.unityLogger.Log(logTag, message);
public void Log(string logTag, object message, Object context) => Debug.unityLogger.Log(logTag, message, context);
public void LogWarning(string logTag, object message) => Debug.unityLogger.LogWarning(logTag, message);
public void LogWarning(string logTag, object message, Object context) => Debug.unityLogger.LogWarning(logTag, message, context);
public void LogError(string logTag, object message) => Debug.unityLogger.LogError(logTag, message);
public void LogError(string logTag, object message, Object context) => Debug.unityLogger.LogError(logTag, message, context);
public void LogFormat(LogType logType, string format, params object[] args) => Debug.unityLogger.LogFormat(logType, format, args);
public void LogException(Exception exception) => Debug.unityLogger.LogException(exception);
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 14d325e5522f99c46bedfd5b49f1f5e1
@@ -0,0 +1,47 @@
using System;
using UnityEngine;
using UnityEngine.TestTools;
namespace BracerLib.Utility
{
[ExcludeFromCoverage]
public static class Vector3Extensions
{
public static Vector3 With(this Vector3 vector, float? x = null, float? y = null, float? z = null) => new(x ?? vector.x, y ?? vector.y, z ?? vector.z);
public static Vector3 Add(this Vector3 vector, float? x = null, float? y = null, float? z = null)
=> new(
x != null ? vector.x + x.Value : vector.x,
y != null ? vector.y + y.Value : vector.y,
z != null ? vector.z + z.Value : vector.z
);
/// <summary>
/// Take an existing Vector3 and truncate all its values to a certain number of decimal places.
/// </summary>
public static Vector3 Truncate(this Vector3 value, int decimalPlaces = 3)
{
double adjust = 0.5f / Mathf.Pow(10, decimalPlaces);
return new Vector3(
(float)Math.Round(value.x - adjust, decimalPlaces),
(float)Math.Round(value.y - adjust, decimalPlaces),
(float)Math.Round(value.z - adjust, decimalPlaces)
);
}
public static Vector3 Floor(this Vector3 value)
{
return new Vector3(Mathf.Floor(value.x), Mathf.Floor(value.y), Mathf.Floor(value.z));
}
public static Vector3 Ceiling(this Vector3 value)
{
return new Vector3(Mathf.Ceil(value.x), Mathf.Ceil(value.y), Mathf.Ceil(value.z));
}
public static Vector3 ProjectToLine(this Vector3 point, Vector3 lineStart, Vector3 lineEnd)
{
return Vector3.Project(point - lineStart, lineEnd - lineStart) + lineStart;
}
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: fed94b0e69fa9d74081a5836acda2292
+292
View File
@@ -0,0 +1,292 @@
using System;
using System.Globalization;
using System.Runtime.CompilerServices;
using UnityEngine;
using UnityEngine.TestTools;
namespace BracerLib.Utility
{
[ExcludeFromCoverage]
public struct Vector4Int : IEquatable<Vector4Int>, IFormattable
{
private static readonly Vector4Int zero = new Vector4Int(0, 0, 0, 0);
private static readonly Vector4Int one = new Vector4Int(1, 1, 1, 1);
private static readonly Vector4Int up = new Vector4Int(0, 1, 0, 0);
private static readonly Vector4Int down = new Vector4Int(0, -1, 0, 0);
private static readonly Vector4Int left = new Vector4Int(-1, 0, 0, 0);
private static readonly Vector4Int right = new Vector4Int(1, 0, 0, 0);
private static readonly Vector4Int forward = new Vector4Int(0, 0, 1, 0);
private static readonly Vector4Int back = new Vector4Int(0, 0, -1, 0);
public static Vector4Int Zero
{
[MethodImpl(MethodImplOptions.AggressiveInlining)] get => Vector4Int.zero;
}
/// <summary>
/// <para>Shorthand for writing Vector4Int(1, 1, 1, 1).</para>
/// </summary>
public static Vector4Int One
{
[MethodImpl(MethodImplOptions.AggressiveInlining)] get => Vector4Int.one;
}
/// <summary>
/// <para>Shorthand for writing Vector4Int(0, 1, 0, 0).</para>
/// </summary>
public static Vector4Int Up
{
[MethodImpl(MethodImplOptions.AggressiveInlining)] get => Vector4Int.up;
}
/// <summary>
/// <para>Shorthand for writing Vector4Int(0, -1, 0, 0).</para>
/// </summary>
public static Vector4Int Down
{
[MethodImpl(MethodImplOptions.AggressiveInlining)] get => Vector4Int.down;
}
/// <summary>
/// <para>Shorthand for writing Vector4Int(-1, 0, 0, 0).</para>
/// </summary>
public static Vector4Int Left
{
[MethodImpl(MethodImplOptions.AggressiveInlining)] get => Vector4Int.left;
}
/// <summary>
/// <para>Shorthand for writing Vector4Int(1, 0, 0, 0).</para>
/// </summary>
public static Vector4Int Right
{
[MethodImpl(MethodImplOptions.AggressiveInlining)] get => Vector4Int.right;
}
/// <summary>
/// <para>Shorthand for writing Vector4Int(0, 0, 1, 0).</para>
/// </summary>
public static Vector4Int Forward
{
[MethodImpl(MethodImplOptions.AggressiveInlining)] get => Vector4Int.forward;
}
/// <summary>
/// <para>Shorthand for writing Vector4Int(0, 0, -1, 0).</para>
/// </summary>
public static Vector4Int Back
{
[MethodImpl(MethodImplOptions.AggressiveInlining)] get => Vector4Int.back;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator Vector4(Vector4Int v)
{
return new Vector4((float) v.x, (float) v.y, (float) v.z);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static explicit operator Vector2Int(Vector4Int v) => new Vector2Int(v.x, v.y);
/// <summary>
/// <para>Converts a Vector4 to a Vector4Int by doing a Floor to each value.</para>
/// </summary>
/// <param name="v"></param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Vector4Int FloorToInt(Vector4 v)
{
return new Vector4Int(Mathf.FloorToInt(v.x), Mathf.FloorToInt(v.y), Mathf.FloorToInt(v.z), Mathf.FloorToInt(v.w));
}
/// <summary>
/// <para>Converts a Vector4 to a Vector4Int by doing a Ceiling to each value.</para>
/// </summary>
/// <param name="v"></param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Vector4Int CeilToInt(Vector4 v)
{
return new Vector4Int(Mathf.CeilToInt(v.x), Mathf.CeilToInt(v.y), Mathf.CeilToInt(v.z),Mathf.CeilToInt(v.w));
}
/// <summary>
/// <para>Converts a Vector4 to a Vector4Int by doing a Round to each value.</para>
/// </summary>
/// <param name="v"></param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Vector4Int RoundToInt(Vector4 v)
{
return new Vector4Int(Mathf.RoundToInt(v.x), Mathf.RoundToInt(v.y), Mathf.RoundToInt(v.z), Mathf.RoundToInt(v.w));
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Vector4Int operator +(Vector4Int a, Vector4Int b)
{
return new Vector4Int(a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Vector4Int operator -(Vector4Int a, Vector4Int b)
{
return new Vector4Int(a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Vector4Int operator *(Vector4Int a, Vector4Int b)
{
return new Vector4Int(a.x * b.x, a.y * b.y, a.z * b.z, a.w * b.w);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Vector4Int operator -(Vector4Int a) => new Vector4Int(-a.x, -a.y, -a.z, -a.w);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Vector4Int operator *(Vector4Int a, int b)
{
return new Vector4Int(a.x * b, a.y * b, a.z * b, a.w * b);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Vector4Int operator *(int a, Vector4Int b)
{
return new Vector4Int(a * b.x, a * b.y, a * b.z, a * b.w);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Vector4Int operator /(Vector4Int a, int b)
{
return new Vector4Int(a.x / b, a.y / b, a.z / b, a.w / b);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator ==(Vector4Int lhs, Vector4Int rhs)
{
return lhs.x == rhs.x && lhs.y == rhs.y && lhs.z == rhs.z && lhs.w == rhs.w;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator !=(Vector4Int lhs, Vector4Int rhs) => !(lhs == rhs);
private int x;
private int y;
private int z;
private int w;
public int X
{
[MethodImpl(MethodImplOptions.AggressiveInlining)] get => x;
[MethodImpl(MethodImplOptions.AggressiveInlining)] set => x = value;
}
public int Y
{
[MethodImpl(MethodImplOptions.AggressiveInlining)] get => y;
[MethodImpl(MethodImplOptions.AggressiveInlining)] set => y = value;
}
public int Z
{
[MethodImpl(MethodImplOptions.AggressiveInlining)] get => z;
[MethodImpl(MethodImplOptions.AggressiveInlining)] set => z = value;
}
public int W
{
[MethodImpl(MethodImplOptions.AggressiveInlining)] get => w;
[MethodImpl(MethodImplOptions.AggressiveInlining)] set => w = value;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Vector4Int(int x)
{
this.x = x;
this.y = 0;
this.z = 0;
this.w = 0;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Vector4Int(int x, int y)
{
this.x = x;
this.y = y;
this.z = 0;
this.w = 0;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Vector4Int(int x, int y, int z)
{
this.x = x;
this.y = y;
this.z = z;
this.w = 0;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Vector4Int(int x, int y, int z, int w)
{
this.x = x;
this.y = y;
this.z = z;
this.w = w;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Vector4Int(Vector3Int indexes, int w)
{
x = indexes.x;
y = indexes.y;
z = indexes.z;
this.w = w;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool Equals(Vector4Int other) => this == other;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public override bool Equals(object other) => other is Vector4Int other1 && Equals(other1);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public override int GetHashCode()
{
int hashCode1 = y.GetHashCode();
int hashCode2 = z.GetHashCode();
return x.GetHashCode() ^ hashCode1 << 4 ^ hashCode1 >> 28 ^ hashCode2 >> 4 ^ hashCode2 << 28;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Vector3Int ToVector3Int()
{
return new Vector3Int(x, y, z);
}
/// <summary>
/// <para>Returns a formatted string for this vector.</para>
/// </summary>
/// <param name="format">A numeric format string.</param>
/// <param name="formatProvider">An object that specifies culture-specific formatting.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public override string ToString() => ToString((string) null, (IFormatProvider) null);
/// <summary>
/// <para>Returns a formatted string for this vector.</para>
/// </summary>
/// <param name="format">A numeric format string.</param>
/// <param name="formatProvider">An object that specifies culture-specific formatting.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public string ToString(string format) => ToString(format, (IFormatProvider) null);
/// <summary>
/// <para>Returns a formatted string for this vector.</para>
/// </summary>
/// <param name="format">A numeric format string.</param>
/// <param name="formatProvider">An object that specifies culture-specific formatting.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public string ToString(string format, IFormatProvider formatProvider)
{
if (formatProvider == null)
formatProvider = (IFormatProvider) CultureInfo.InvariantCulture.NumberFormat;
return $"({(object)x.ToString(format, formatProvider)}, {(object)y.ToString(format, formatProvider)}, {(object)z.ToString(format, formatProvider)})";
}
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: c064042965f85f94598e90c06fb7ec18