This repository has been archived by the owner on Apr 10, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Anatoly Brizhan
committed
Feb 27, 2024
1 parent
2612d1a
commit c5c065c
Showing
16 changed files
with
205 additions
and
26 deletions.
There are no files selected for viewing
6 changes: 3 additions & 3 deletions
6
Assets/BetterExtensions/Runtime/Extensions/BoundsExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
Assets/BetterExtensions/Runtime/Extensions/Vector2Extensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
Assets/BetterExtensions/Runtime/Extensions/Vector2Extensions.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
35 changes: 35 additions & 0 deletions
35
Assets/BetterExtensions/Runtime/Extensions/Vector3Extensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
|
||
/// <summary> | ||
/// Multiplies Vector3 and Quaternion | ||
/// </summary> | ||
/// <param name="self"></param> | ||
/// <param name="quaternion"></param> | ||
/// <returns></returns> | ||
public static Vector3 Multiply(this Vector3 self, Quaternion quaternion) | ||
{ | ||
return Vector3Utility.Multiply(self, quaternion); | ||
} | ||
|
||
public static Vector3 Average(this NativeArray<Vector3> self) | ||
{ | ||
return Vector3Utility.Average(self); | ||
} | ||
|
||
public static Vector3 Average(this IEnumerable<Vector3> self) | ||
{ | ||
return Vector3Utility.Average(self); | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
Assets/BetterExtensions/Runtime/Extensions/Vector3Extensions.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
68 changes: 68 additions & 0 deletions
68
Assets/BetterExtensions/Runtime/Utility/AssetDatabaseUtility.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<T>() | ||
{ | ||
var prefabs = new List<T>(); | ||
var gameObjects = FindAssetsOfType<GameObject>(PrefabFilter); | ||
|
||
foreach (var gameObject in gameObjects) | ||
{ | ||
var components = gameObject.GetComponents<Component>(); | ||
foreach (var component in components) | ||
{ | ||
if (component is not T item) continue; | ||
|
||
prefabs.Add(item); | ||
break; | ||
} | ||
} | ||
|
||
return prefabs.ToArray(); | ||
} | ||
|
||
public static T[] FindScriptableObjectsOfType<T>() where T : ScriptableObject | ||
{ | ||
return FindAssetsOfType<T>(ScriptableObjectFilter); | ||
} | ||
|
||
public static T[] FindAssetsOfType<T>(string filter) where T : Object | ||
{ | ||
if (filter.IsNullOrEmpty() || filter.IsNullOrWhiteSpace()) | ||
{ | ||
var message = $"{nameof(filter)} cannot be Null or Empty"; | ||
DebugUtility.LogException<ArgumentException>(message); | ||
return Array.Empty<T>(); | ||
} | ||
|
||
var assets = new List<T>(); | ||
#if UNITY_EDITOR | ||
var guids = AssetDatabase.FindAssets(filter); | ||
|
||
foreach (var guid in guids) | ||
{ | ||
var path = AssetDatabase.GUIDToAssetPath(guid); | ||
var asset = AssetDatabase.LoadAssetAtPath<T>(path); | ||
|
||
if (asset != null) | ||
{ | ||
assets.Add(asset); | ||
} | ||
} | ||
|
||
#endif | ||
|
||
return assets.ToArray(); | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
Assets/BetterExtensions/Runtime/Utility/AssetDatabaseUtility.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
Assets/BetterExtensions/Runtime/Utility/Vector3Utility.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.