This commit is contained in:
2025-03-30 16:06:57 +02:00
parent e62bd2aa6d
commit 623ba3f621
148 changed files with 2773 additions and 1441 deletions

View File

@@ -8,10 +8,15 @@ namespace RebootKit.Engine.Extensions {
blue ?? color.b,
alpha ?? color.a);
}
public static string ToHexRGBA(this Color color) => $"#{ColorUtility.ToHtmlStringRGBA(color)}";
public static string ToHexRGB(this Color color) => $"#{ColorUtility.ToHtmlStringRGB(color)}";
public static string ToHexRGBA(this Color color) {
return $"#{ColorUtility.ToHtmlStringRGBA(color)}";
}
public static string ToHexRGB(this Color color) {
return $"#{ColorUtility.ToHtmlStringRGB(color)}";
}
public static Color Clamp01(this Color color) {
return new Color {
r = Mathf.Clamp01(color.r),

View File

@@ -1,10 +1,11 @@
using UnityEngine;
using System;
using UnityEngine;
using Object = UnityEngine.Object;
namespace RebootKit.Engine.Extensions {
public static class GameObjectEx {
public static T GetOrAdd<T>(this GameObject gameObject) where T : Component {
T component = gameObject.GetComponent<T>();
if (component == null) {
component = gameObject.AddComponent<T>();
}
@@ -12,6 +13,10 @@ namespace RebootKit.Engine.Extensions {
return component;
}
public static void ForEachChild(this GameObject gameObject, Action<GameObject> action) {
gameObject.transform.ForEachChild(transform => action(transform.gameObject));
}
public static void DestroyChildren(this GameObject gameObject) {
gameObject.transform.DestroyChildren();
}
@@ -22,9 +27,7 @@ namespace RebootKit.Engine.Extensions {
public static void SetLayersRecursively(this GameObject gameObject, int layer) {
gameObject.layer = layer;
gameObject.transform.ForEachChild(child => {
child.gameObject.SetLayersRecursively(layer);
});
gameObject.transform.ForEachChild(child => { child.gameObject.SetLayersRecursively(layer); });
}
}
}

View File

@@ -5,15 +5,11 @@ using Object = UnityEngine.Object;
namespace RebootKit.Engine.Extensions {
public static class TransformEx {
public static void DestroyChildren(this Transform transform) {
foreach (Transform child in transform) {
Object.Destroy(child);
}
foreach (Transform child in transform) Object.Destroy(child);
}
public static void ForEachChild(this Transform transform, Action<Transform> action) {
foreach (Transform child in transform) {
action(child);
}
foreach (Transform child in transform) action(child);
}
}
}

View File

@@ -1,11 +1,36 @@
using UnityEngine;
using System.Runtime.CompilerServices;
using Unity.Mathematics;
using UnityEngine;
namespace RebootKit.Engine.Extensions {
public static class Vector3Ex {
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Vector3 With(this Vector3 vec, float? x = null, float? y = null, float? z = null) {
return new Vector3(x ?? vec.x,
y ?? vec.y,
z ?? vec.z);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool IsZero(this Vector3 vec, float epsilon = float.Epsilon) {
return math.abs(vec.x) < epsilon && math.abs(vec.y) < epsilon && math.abs(vec.z) < epsilon;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool IsNonZero(this Vector3 vec, float epsilon = float.Epsilon) {
return !vec.IsZero(epsilon);
}
}
public static class float3Ex {
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool IsZero(this float3 vec, float epsilon = float.Epsilon) {
return math.abs(vec.x) < epsilon && math.abs(vec.y) < epsilon && math.abs(vec.z) < epsilon;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool IsNonZero(this float3 vec, float epsilon = float.Epsilon) {
return !vec.IsZero(epsilon);
}
}
}