Skip to content
This repository has been archived by the owner on Apr 10, 2024. It is now read-only.

Commit

Permalink
Merge pull request #57 from techno-dwarf-works/dev
Browse files Browse the repository at this point in the history
Version: 1.5.2
  • Loading branch information
OpOpYaDev authored Feb 28, 2024
2 parents 087c2c3 + d259a57 commit 93854d6
Show file tree
Hide file tree
Showing 44 changed files with 1,146 additions and 4 deletions.
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.

120 changes: 120 additions & 0 deletions Assets/BetterExtensions/Runtime/Extensions/ComponentExtensions.cs
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.

83 changes: 83 additions & 0 deletions Assets/BetterExtensions/Runtime/Extensions/GameObjectExtensions.cs
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.

10 changes: 10 additions & 0 deletions Assets/BetterExtensions/Runtime/Extensions/QuaternionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,15 @@ public static bool Approximately(this Quaternion self, Quaternion other)
{
return QuaternionUtility.Approximately(self, other);
}

public static Quaternion Scale(this Quaternion self, Vector3 scale)
{
return QuaternionUtility.Scale(self, scale);
}

public static Quaternion Scale(this Quaternion self, float scale)
{
return QuaternionUtility.Scale(self, scale);
}
}
}
12 changes: 12 additions & 0 deletions Assets/BetterExtensions/Runtime/Extensions/RectExtensions.cs
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
Expand Up @@ -156,5 +156,33 @@ public static bool IsVisibleFrom(this RectTransform self, Camera camera)

return CountCornersVisible(self, camera) > 0; // True if any corners are visible
}

public static bool IsFullyStretched(this RectTransform self)
{
if (self == null)
{
DebugUtility.LogException<ArgumentNullException>(nameof(self));
return false;
}

return self.localScale == Vector3.one
&& self.anchorMin == Vector2.zero
&& self.anchorMax == Vector2.one
&& self.sizeDelta == Vector2.zero;
}

public static void FullyStretch(this RectTransform self)
{
if (self == null)
{
DebugUtility.LogException<ArgumentNullException>(nameof(self));
return;
}

self.LocalReset();
self.anchorMin = Vector2.zero;
self.anchorMax = Vector2.one;
self.sizeDelta = Vector2.zero;
}
}
}
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.

Loading

0 comments on commit 93854d6

Please sign in to comment.