1
This commit is contained in:
21
Src/Unity/Scripts/Extensions/GameObjectExtensions.cs
Normal file
21
Src/Unity/Scripts/Extensions/GameObjectExtensions.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace BITKit
|
||||
{
|
||||
public static class GameObjectExtensions
|
||||
{
|
||||
public static T GetOrAddComponent<T>(this GameObject gameObject) where T : Component
|
||||
{
|
||||
return gameObject.TryGetComponent<T>(out var t) ? t : gameObject.AddComponent<T>();
|
||||
}
|
||||
public static T RemoveComponent<T>(this GameObject gameObject) where T : Component
|
||||
{
|
||||
var t = gameObject.GetComponent<T>();
|
||||
if (t is null) return null;
|
||||
Object.Destroy(t);
|
||||
return t;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user