add project files
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace OHM.UnityToolkit
|
||||
{
|
||||
public static class ComponentsUtils
|
||||
{
|
||||
public static bool GetRequiredComponentInChildren<ComponentToFind>(Component parent, ref ComponentToFind componentToFind)
|
||||
{
|
||||
if (!IsNull(componentToFind))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
componentToFind = parent.GetComponentInChildren<ComponentToFind>(true);
|
||||
return !IsNull(componentToFind);
|
||||
}
|
||||
|
||||
public static bool GetRequiredComponentInParent<ComponentToFind>(Component parent, ref ComponentToFind componentToFind)
|
||||
{
|
||||
if (!IsNull(componentToFind))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
componentToFind = parent.GetComponentInParent<ComponentToFind>();
|
||||
return !IsNull(componentToFind);
|
||||
}
|
||||
|
||||
public static bool GetRequiredComponent<ComponentToFind>(Component parent, ref ComponentToFind componentToFind)
|
||||
{
|
||||
if (!IsNull(componentToFind))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
componentToFind = parent.GetComponent<ComponentToFind>();
|
||||
return !IsNull(componentToFind);
|
||||
}
|
||||
|
||||
public static ComponentToFind GetRequiredComponent<ComponentToFind>(Component parent)
|
||||
{
|
||||
return parent.GetComponent<ComponentToFind>();
|
||||
}
|
||||
|
||||
private static bool IsNull<T>(T value)
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return value is UnityEngine.Object obj && obj == null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user