-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
Version: 1.5.2
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using System; | ||
using Better.Extensions.Runtime.Helpers; | ||
using UnityEngine; | ||
|
||
namespace Better.Extensions.Runtime | ||
{ | ||
public static class AssetBundleRequestAwaiterExtensions | ||
{ | ||
public static AssetBundleRequestAwaiter GetAwaiter(this AssetBundleRequest self) | ||
{ | ||
if (self == null) | ||
{ | ||
throw new ArgumentNullException(nameof(self)); | ||
} | ||
|
||
return new AssetBundleRequestAwaiter(self); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using System; | ||
using Better.Extensions.Runtime.Helpers; | ||
using UnityEngine; | ||
|
||
namespace Better.Extensions.Runtime | ||
{ | ||
public static class AsyncOperationAwaiterExtensions | ||
{ | ||
public static AsyncOperationAwaiter GetAwaiter(this AsyncOperation self) | ||
{ | ||
if (self == null) | ||
{ | ||
throw new ArgumentNullException(nameof(self)); | ||
} | ||
|
||
return new AsyncOperationAwaiter(self); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using UnityEngine; | ||
|
||
namespace Better.Extensions.Runtime | ||
{ | ||
public static class ComponentExtensions | ||
{ | ||
public static void DestroyGameObject(this Component self) | ||
{ | ||
if (self == null) | ||
{ | ||
DebugUtility.LogException<ArgumentNullException>(nameof(self)); | ||
return; | ||
} | ||
|
||
self.gameObject.Destroy(); | ||
} | ||
|
||
public static void DestroyGameObject(this Component self, float delay) | ||
{ | ||
if (self == null) | ||
{ | ||
DebugUtility.LogException<ArgumentNullException>(nameof(self)); | ||
return; | ||
} | ||
|
||
self.gameObject.Destroy(delay); | ||
} | ||
|
||
public static void DestroyGameObject(this IEnumerable<Component> self) | ||
{ | ||
if (self == null) | ||
{ | ||
DebugUtility.LogException<ArgumentNullException>(nameof(self)); | ||
return; | ||
} | ||
|
||
var cached = self.ToArray(); | ||
for (var i = 0; i < cached.Length; i++) | ||
{ | ||
cached[i].DestroyGameObject(); | ||
} | ||
} | ||
|
||
public static void DestroyGameObject(this IEnumerable<Component> self, float delay) | ||
{ | ||
if (self == null) | ||
{ | ||
DebugUtility.LogException<ArgumentNullException>(nameof(self)); | ||
return; | ||
} | ||
|
||
var cached = self.ToArray(); | ||
for (var i = 0; i < cached.Length; i++) | ||
{ | ||
cached[i].DestroyGameObject(delay); | ||
} | ||
} | ||
|
||
public static IEnumerable<GameObject> GetGameObjects(this IEnumerable<Component> self) | ||
{ | ||
if (self == null) | ||
{ | ||
DebugUtility.LogException<ArgumentNullException>(nameof(self)); | ||
return Enumerable.Empty<GameObject>(); | ||
} | ||
|
||
return self.Select(c => c.gameObject); | ||
} | ||
|
||
public static IEnumerable<Transform> GetTransforms(this IEnumerable<Component> self) | ||
{ | ||
if (self == null) | ||
{ | ||
DebugUtility.LogException<ArgumentNullException>(nameof(self)); | ||
return Enumerable.Empty<Transform>(); | ||
} | ||
|
||
return self.Select(c => c.transform); | ||
} | ||
|
||
public static T GetOrAddComponent<T>(this Component self) | ||
where T : Component | ||
{ | ||
if (self == null) | ||
{ | ||
DebugUtility.LogException<ArgumentNullException>(nameof(self)); | ||
return default; | ||
} | ||
|
||
return self.gameObject.GetOrAddComponent<T>(); | ||
} | ||
|
||
public static bool TryGetComponentInParent<T>(this Component self, out T component) | ||
{ | ||
if (self == null) | ||
{ | ||
DebugUtility.LogException<ArgumentNullException>(nameof(self)); | ||
component = default; | ||
return false; | ||
} | ||
|
||
return self.gameObject.TryGetComponentInParent(out component); | ||
} | ||
|
||
public static bool TryGetComponentInChildren<T>(this Component self, out T component) | ||
{ | ||
if (self == null) | ||
{ | ||
DebugUtility.LogException<ArgumentNullException>(nameof(self)); | ||
component = default; | ||
return false; | ||
} | ||
|
||
return self.gameObject.TryGetComponentInChildren(out component); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using UnityEngine; | ||
|
||
namespace Better.Extensions.Runtime | ||
{ | ||
public static class GameObjectExtensions | ||
{ | ||
public static void SetActive(this IEnumerable<GameObject> self, bool value) | ||
{ | ||
if (self == null) | ||
{ | ||
DebugUtility.LogException<ArgumentNullException>(nameof(self)); | ||
return; | ||
} | ||
|
||
var cached = self.ToArray(); | ||
for (var i = 0; i < cached.Length; i++) | ||
{ | ||
cached[i].SetActive(value); | ||
} | ||
} | ||
|
||
public static T GetOrAddComponent<T>(this GameObject self) | ||
where T : Component | ||
{ | ||
if (self == null) | ||
{ | ||
DebugUtility.LogException<ArgumentNullException>(nameof(self)); | ||
return default; | ||
} | ||
|
||
if (self.TryGetComponent(out T component)) | ||
{ | ||
return component; | ||
} | ||
|
||
return self.AddComponent<T>(); | ||
} | ||
|
||
public static bool TryGetComponentInParent<T>(this GameObject self, out T component) | ||
{ | ||
if (self == null) | ||
{ | ||
DebugUtility.LogException<ArgumentNullException>(nameof(self)); | ||
component = default; | ||
return false; | ||
} | ||
|
||
component = self.GetComponentInParent<T>(); | ||
return component != null; | ||
} | ||
|
||
public static bool TryGetComponentInChildren<T>(this GameObject self, out T component) | ||
{ | ||
if (self == null) | ||
{ | ||
DebugUtility.LogException<ArgumentNullException>(nameof(self)); | ||
component = default; | ||
return false; | ||
} | ||
|
||
component = self.GetComponentInChildren<T>(); | ||
return component != null; | ||
} | ||
|
||
public static void RecursiveSetLayer(this GameObject self, int layer) | ||
{ | ||
self.layer = layer; | ||
|
||
foreach (Transform child in self.transform) | ||
{ | ||
RecursiveSetLayer(child.gameObject, layer); | ||
} | ||
} | ||
|
||
public static void RecursiveSetLayer(this GameObject self, LayerMask layerMask) | ||
{ | ||
self.RecursiveSetLayer(layerMask.value); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using UnityEngine; | ||
|
||
namespace Better.Extensions.Runtime | ||
{ | ||
public static class RectExtensions | ||
{ | ||
public static float GetRatio(this Rect self) | ||
{ | ||
return self.size.y / self.size.y; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using System; | ||
using Better.Extensions.Runtime.Helpers; | ||
using UnityEngine; | ||
|
||
namespace Better.Extensions.Runtime | ||
{ | ||
public static class ResourceRequestAwaiterExtensions | ||
{ | ||
public static ResourceRequestAwaiter GetAwaiter(this ResourceRequest self) | ||
{ | ||
if (self == null) | ||
{ | ||
throw new ArgumentNullException(nameof(self)); | ||
} | ||
|
||
return new ResourceRequestAwaiter(self); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.