Skip to content

Commit

Permalink
Take advantage of Monobehavior implicit cast to bool and use bool che…
Browse files Browse the repository at this point in the history
…ck instead of counter
  • Loading branch information
searica committed Nov 18, 2023
1 parent b2220bf commit f7441aa
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions JotunnLib/Extensions/GameObjectExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,19 +151,14 @@ public static bool HasAnyComponent(this GameObject gameObject, params string[] c
/// <returns></returns>
public static bool HasAllComponents(this GameObject gameObject, params string[] componentNames)
{
int compCount = 0;
foreach (var name in componentNames)
{
if (gameObject.GetComponent(name))
{
compCount++;
}
else
if (!gameObject.GetComponent(name))
{
return false;
}
}
return compCount == componentNames.Length;
return true;
}

/// <summary>
Expand All @@ -174,19 +169,14 @@ public static bool HasAllComponents(this GameObject gameObject, params string[]
/// <returns></returns>
public static bool HasAllComponents(this GameObject gameObject, params Type[] components)
{
int compCount = 0;
foreach (var compo in components)
{
if (gameObject.GetComponent(compo))
{
compCount++;
}
else
if (!gameObject.GetComponent(compo))
{
return false;
}
}
return compCount == components.Length;
return true;
}

/// <summary>
Expand Down

0 comments on commit f7441aa

Please sign in to comment.