hellbound/Assets/Scripts/Core/Extensions/GameObjectExtensions.cs

34 lines
775 B
C#
Raw Permalink Normal View History

2021-11-26 11:16:25 +03:00
using UnityEngine;
public static class GameObjectExtensions
{
public static T GetOrCreate<T>(this GameObject go) where T : Component
{
var comp = go.GetComponent<T>();
if (comp != null)
return comp;
return go.AddComponent<T>();
}
public static void SetParent(this GameObject go, Transform parent, bool worldPosStays = false)
{
go.transform.SetParent(parent, worldPosStays);
}
public static bool CompareLayers(this GameObject obj, LayerMask layer)
{
return ((1 << obj.layer) & layer) != 0;
}
public static void Show(this GameObject obj)
{
obj.SetActive(true);
}
public static void Hide(this GameObject obj)
{
obj.SetActive(false);
}
}