diff --git a/Assets/BetterExtensions/Runtime/Extensions/BoundsExtensions.cs b/Assets/BetterExtensions/Runtime/Extensions/BoundsExtensions.cs
index 2d06675..c44f345 100644
--- a/Assets/BetterExtensions/Runtime/Extensions/BoundsExtensions.cs
+++ b/Assets/BetterExtensions/Runtime/Extensions/BoundsExtensions.cs
@@ -1,12 +1,12 @@
using UnityEngine;
-namespace Better.Extensions.Runtime.Runtime.Extensions
+namespace Better.Extensions.Runtime
{
public static class BoundsExtensions
{
- public static bool Approximately(this Bounds current, Bounds other)
+ public static bool Approximately(this Bounds self, Bounds other)
{
- return BoundsUtility.Approximately(current, other);
+ return BoundsUtility.Approximately(self, other);
}
}
}
\ No newline at end of file
diff --git a/Assets/BetterExtensions/Runtime/Extensions/FloatExtensions.cs b/Assets/BetterExtensions/Runtime/Extensions/FloatExtensions.cs
index 8462ec7..d0f46b1 100644
--- a/Assets/BetterExtensions/Runtime/Extensions/FloatExtensions.cs
+++ b/Assets/BetterExtensions/Runtime/Extensions/FloatExtensions.cs
@@ -5,13 +5,13 @@ public static class FloatExtensions
///
/// Check that point in two other points
///
- ///
+ ///
///
///
///
- private static bool InRange(this float value, float min, float max)
+ private static bool InRange(this float self, float min, float max)
{
- return FloatUtility.InRange(value, min, max);
+ return FloatUtility.InRange(self, min, max);
}
}
}
\ No newline at end of file
diff --git a/Assets/BetterExtensions/Runtime/Extensions/IntExtensions.cs b/Assets/BetterExtensions/Runtime/Extensions/IntExtensions.cs
index 31ca084..16b1e85 100644
--- a/Assets/BetterExtensions/Runtime/Extensions/IntExtensions.cs
+++ b/Assets/BetterExtensions/Runtime/Extensions/IntExtensions.cs
@@ -5,13 +5,13 @@ public static class IntExtensions
///
/// Check that point in two other points
///
- ///
+ ///
///
///
///
- private static bool InRange(this int value, int min, int max)
+ private static bool InRange(this int self, int min, int max)
{
- return IntUtility.InRange(value, min, max);
+ return IntUtility.InRange(self, min, max);
}
}
}
\ No newline at end of file
diff --git a/Assets/BetterExtensions/Runtime/Extensions/TaskExtensions.cs b/Assets/BetterExtensions/Runtime/Extensions/TaskExtensions.cs
index 9c0a964..19797b9 100644
--- a/Assets/BetterExtensions/Runtime/Extensions/TaskExtensions.cs
+++ b/Assets/BetterExtensions/Runtime/Extensions/TaskExtensions.cs
@@ -1,7 +1,7 @@
using System.Collections.Generic;
using System.Threading.Tasks;
-namespace Better.Extensions.Runtime.TasksExtension
+namespace Better.Extensions.Runtime
{
public static class TaskExtensions
{
diff --git a/Assets/BetterExtensions/Runtime/Extensions/Vector2Extensions.cs b/Assets/BetterExtensions/Runtime/Extensions/Vector2Extensions.cs
new file mode 100644
index 0000000..63e03e0
--- /dev/null
+++ b/Assets/BetterExtensions/Runtime/Extensions/Vector2Extensions.cs
@@ -0,0 +1,12 @@
+using UnityEngine;
+
+namespace Better.Extensions.Runtime
+{
+ public static class Vector2Extensions
+ {
+ public static bool Approximately(this Vector2 self, Vector2 other)
+ {
+ return Vector2Utility.Approximately(self, other);
+ }
+ }
+}
\ No newline at end of file
diff --git a/Assets/BetterExtensions/Runtime/Extensions/Vector2Extensions.cs.meta b/Assets/BetterExtensions/Runtime/Extensions/Vector2Extensions.cs.meta
new file mode 100644
index 0000000..0a65837
--- /dev/null
+++ b/Assets/BetterExtensions/Runtime/Extensions/Vector2Extensions.cs.meta
@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: 2b59568b07e24214a542eed0a0496ba0
+timeCreated: 1708972921
\ No newline at end of file
diff --git a/Assets/BetterExtensions/Runtime/Extensions/Vector3Extensions.cs b/Assets/BetterExtensions/Runtime/Extensions/Vector3Extensions.cs
new file mode 100644
index 0000000..6193856
--- /dev/null
+++ b/Assets/BetterExtensions/Runtime/Extensions/Vector3Extensions.cs
@@ -0,0 +1,35 @@
+using System.Collections.Generic;
+using Unity.Collections;
+using UnityEngine;
+
+namespace Better.Extensions.Runtime
+{
+ public static class Vector3Extensions
+ {
+ public static bool Approximately(this Vector3 self, Vector3 other)
+ {
+ return Vector3Utility.Approximately(self, other);
+ }
+
+ ///
+ /// Multiplies Vector3 and Quaternion
+ ///
+ ///
+ ///
+ ///
+ public static Vector3 Multiply(this Vector3 self, Quaternion quaternion)
+ {
+ return Vector3Utility.Multiply(self, quaternion);
+ }
+
+ public static Vector3 Average(this NativeArray self)
+ {
+ return Vector3Utility.Average(self);
+ }
+
+ public static Vector3 Average(this IEnumerable self)
+ {
+ return Vector3Utility.Average(self);
+ }
+ }
+}
\ No newline at end of file
diff --git a/Assets/BetterExtensions/Runtime/Extensions/Vector3Extensions.cs.meta b/Assets/BetterExtensions/Runtime/Extensions/Vector3Extensions.cs.meta
new file mode 100644
index 0000000..ea2a4c0
--- /dev/null
+++ b/Assets/BetterExtensions/Runtime/Extensions/Vector3Extensions.cs.meta
@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: d88ac92e35854c6b89d929088a310954
+timeCreated: 1708972661
\ No newline at end of file
diff --git a/Assets/BetterExtensions/Runtime/Utility/AssetDatabaseUtility.cs b/Assets/BetterExtensions/Runtime/Utility/AssetDatabaseUtility.cs
new file mode 100644
index 0000000..12fc466
--- /dev/null
+++ b/Assets/BetterExtensions/Runtime/Utility/AssetDatabaseUtility.cs
@@ -0,0 +1,68 @@
+using System;
+using System.Collections.Generic;
+using UnityEditor;
+using UnityEngine;
+using Object = UnityEngine.Object;
+
+namespace Better.Extensions.Runtime
+{
+ public static class AssetDatabaseUtility
+ {
+ private const string PrefabFilter = "t:prefab";
+ private const string ScriptableObjectFilter = "t:ScriptableObject";
+
+ public static T[] FindPrefabsOfType()
+ {
+ var prefabs = new List();
+ var gameObjects = FindAssetsOfType(PrefabFilter);
+
+ foreach (var gameObject in gameObjects)
+ {
+ var components = gameObject.GetComponents();
+ foreach (var component in components)
+ {
+ if (component is not T item) continue;
+
+ prefabs.Add(item);
+ break;
+ }
+ }
+
+ return prefabs.ToArray();
+ }
+
+ public static T[] FindScriptableObjectsOfType() where T : ScriptableObject
+ {
+ return FindAssetsOfType(ScriptableObjectFilter);
+ }
+
+ public static T[] FindAssetsOfType(string filter) where T : Object
+ {
+ if (filter.IsNullOrEmpty() || filter.IsNullOrWhiteSpace())
+ {
+ var message = $"{nameof(filter)} cannot be Null or Empty";
+ DebugUtility.LogException(message);
+ return Array.Empty();
+ }
+
+ var assets = new List();
+#if UNITY_EDITOR
+ var guids = AssetDatabase.FindAssets(filter);
+
+ foreach (var guid in guids)
+ {
+ var path = AssetDatabase.GUIDToAssetPath(guid);
+ var asset = AssetDatabase.LoadAssetAtPath(path);
+
+ if (asset != null)
+ {
+ assets.Add(asset);
+ }
+ }
+
+#endif
+
+ return assets.ToArray();
+ }
+ }
+}
\ No newline at end of file
diff --git a/Assets/BetterExtensions/Runtime/Utility/AssetDatabaseUtility.cs.meta b/Assets/BetterExtensions/Runtime/Utility/AssetDatabaseUtility.cs.meta
new file mode 100644
index 0000000..3ce64c4
--- /dev/null
+++ b/Assets/BetterExtensions/Runtime/Utility/AssetDatabaseUtility.cs.meta
@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: c70fc0a29be24eb7a849caf1c99301c4
+timeCreated: 1701569852
\ No newline at end of file
diff --git a/Assets/BetterExtensions/Runtime/Utility/BoundsUtility.cs b/Assets/BetterExtensions/Runtime/Utility/BoundsUtility.cs
index 1987388..800fbc9 100644
--- a/Assets/BetterExtensions/Runtime/Utility/BoundsUtility.cs
+++ b/Assets/BetterExtensions/Runtime/Utility/BoundsUtility.cs
@@ -6,8 +6,8 @@ public static class BoundsUtility
{
public static bool Approximately(Bounds current, Bounds other)
{
- return VectorUtility.Approximately(current.center, other.center) &&
- VectorUtility.Approximately(current.size, other.size);
+ return current.center.Approximately(other.center) &&
+ current.size.Approximately(other.size);
}
}
}
\ No newline at end of file
diff --git a/Assets/BetterExtensions/Runtime/Utility/EnumUtility.cs b/Assets/BetterExtensions/Runtime/Utility/EnumUtility.cs
index 7cfa242..6738ad6 100644
--- a/Assets/BetterExtensions/Runtime/Utility/EnumUtility.cs
+++ b/Assets/BetterExtensions/Runtime/Utility/EnumUtility.cs
@@ -26,7 +26,7 @@ public static IEnumerable GetAllValues(Type enumType)
var values = Enum.GetValues(enumType);
return values.ToEnumerable();
}
-
+
public static IEnumerable GetAllValues()
where TEnum : Enum
{
diff --git a/Assets/BetterExtensions/Runtime/Utility/Vector2Utility.cs b/Assets/BetterExtensions/Runtime/Utility/Vector2Utility.cs
new file mode 100644
index 0000000..4cf6dd1
--- /dev/null
+++ b/Assets/BetterExtensions/Runtime/Utility/Vector2Utility.cs
@@ -0,0 +1,47 @@
+using UnityEngine;
+
+namespace Better.Extensions.Runtime
+{
+ public struct Vector2Utility
+ {
+ public static bool Approximately(Vector2 current, Vector2 other)
+ {
+ return Mathf.Approximately(current.x, other.x) &&
+ Mathf.Approximately(current.y, other.y);
+ }
+
+ public static Vector2 MiddlePoint(Vector2 start, Vector2 end)
+ {
+ var t = start + end;
+ return t / 2;
+ }
+
+ public static Vector2 MiddlePoint(Vector2 start, Vector2 end, Vector2 offset)
+ {
+ var middlePoint = MiddlePoint(start, end);
+ return middlePoint + offset;
+ }
+
+ public static Vector2 AxesInverseLerp(Vector2 a, Vector2 b, Vector2 value)
+ {
+ return new Vector2(
+ Mathf.InverseLerp(a.x, b.x, value.x),
+ Mathf.InverseLerp(a.y, b.y, value.y)
+ );
+ }
+
+ public static float InverseLerp(Vector2 a, Vector2 b, Vector2 value)
+ {
+ if (a == b)
+ {
+ return default;
+ }
+
+ var ab = b - a;
+ var av = value - a;
+
+ var result = Vector2.Dot(av, ab) / Vector2.Dot(ab, ab);
+ return Mathf.Clamp01(result);
+ }
+ }
+}
\ No newline at end of file
diff --git a/Assets/BetterExtensions/Runtime/Utility/VectorUtility.cs.meta b/Assets/BetterExtensions/Runtime/Utility/Vector2Utility.cs.meta
similarity index 100%
rename from Assets/BetterExtensions/Runtime/Utility/VectorUtility.cs.meta
rename to Assets/BetterExtensions/Runtime/Utility/Vector2Utility.cs.meta
diff --git a/Assets/BetterExtensions/Runtime/Utility/VectorUtility.cs b/Assets/BetterExtensions/Runtime/Utility/Vector3Utility.cs
similarity index 86%
rename from Assets/BetterExtensions/Runtime/Utility/VectorUtility.cs
rename to Assets/BetterExtensions/Runtime/Utility/Vector3Utility.cs
index 9db3e4d..e627495 100644
--- a/Assets/BetterExtensions/Runtime/Utility/VectorUtility.cs
+++ b/Assets/BetterExtensions/Runtime/Utility/Vector3Utility.cs
@@ -5,7 +5,7 @@
namespace Better.Extensions.Runtime
{
- public struct VectorUtility
+ public struct Vector3Utility
{
public static bool Approximately(Vector3 current, Vector3 other)
{
@@ -14,12 +14,6 @@ public static bool Approximately(Vector3 current, Vector3 other)
Mathf.Approximately(current.z, other.z);
}
- public static bool Approximately(Vector2 current, Vector2 other)
- {
- return Mathf.Approximately(current.x, other.x) &&
- Mathf.Approximately(current.y, other.y);
- }
-
///
/// Take projection of point on Plane
///
@@ -124,16 +118,27 @@ public static Vector3 MiddlePoint(Vector3 start, Vector3 end, Vector3 offset)
return middlePoint + offset;
}
- public static Vector2 MiddlePoint(Vector2 start, Vector2 end)
+ public static float InverseLerp(Vector3 a, Vector3 b, Vector3 value)
{
- var t = start + end;
- return t / 2;
+ if (a == b)
+ {
+ return default;
+ }
+
+ var ab = b - a;
+ var av = value - a;
+
+ var result = Vector3.Dot(av, ab) / Vector3.Dot(ab, ab);
+ return Mathf.Clamp01(result);
}
- public static Vector2 MiddlePoint(Vector2 start, Vector2 end, Vector2 offset)
+ public static Vector3 AxesInverseLerp(Vector3 a, Vector3 b, Vector3 value)
{
- var middlePoint = MiddlePoint(start, end);
- return middlePoint + offset;
+ return new Vector3(
+ Mathf.InverseLerp(a.x, b.x, value.x),
+ Mathf.InverseLerp(a.y, b.y, value.y),
+ Mathf.InverseLerp(a.z, b.z, value.z)
+ );
}
}
}
\ No newline at end of file
diff --git a/Assets/BetterExtensions/Runtime/Utility/Vector3Utility.cs.meta b/Assets/BetterExtensions/Runtime/Utility/Vector3Utility.cs.meta
new file mode 100644
index 0000000..df3e9c0
--- /dev/null
+++ b/Assets/BetterExtensions/Runtime/Utility/Vector3Utility.cs.meta
@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: 4328768fbbd74795a5adad32ec08e80c
+timeCreated: 1708972566
\ No newline at end of file