mirror of
https://github.com/Gurge44/EndlessHostRoles.git
synced 2026-10-19 15:51:58 +00:00
46 lines
1.2 KiB
C#
46 lines
1.2 KiB
C#
using UnityEngine;
|
|
|
|
namespace EHR;
|
|
|
|
public static class ObjectHelper
|
|
{
|
|
public static void DestroyTranslator(this GameObject obj)
|
|
{
|
|
if (!obj) return;
|
|
|
|
#if IL2CPP
|
|
obj.ForEachChild((Il2CppSystem.Action<GameObject>)(x => x.DestroyTranslator()));
|
|
#else
|
|
obj.ForEachChild(x => x.DestroyTranslator());
|
|
#endif
|
|
TextTranslatorTMP[] translator = obj.GetComponentsInChildren<TextTranslatorTMP>(true);
|
|
translator?.Do(Object.Destroy);
|
|
}
|
|
|
|
public static void DestroyTranslator(this MonoBehaviour obj)
|
|
{
|
|
obj?.gameObject.DestroyTranslator();
|
|
}
|
|
|
|
// From: Project Lotus - by Discussions
|
|
public static bool HasParentInHierarchy(this GameObject obj, string parentPath)
|
|
{
|
|
string[] pathParts = parentPath.Split('/');
|
|
int pathIndex = pathParts.Length - 1;
|
|
Transform current = obj.transform;
|
|
|
|
while (current)
|
|
{
|
|
if (current.name == pathParts[pathIndex])
|
|
{
|
|
pathIndex--;
|
|
if (pathIndex < 0) return true;
|
|
}
|
|
else pathIndex = pathParts.Length - 1;
|
|
|
|
current = current.parent;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
} |