using System;
using UnityEngine;

public static class GameObjectExtension
{
	public static T GetOrAddComponent<T>(this GameObject self) where T : Component
	{
		T t = self.GetComponent<T>();
		if (t == null)
		{
			t = self.AddComponent<T>();
		}
		return t;
	}

	public static T GetOrAddComponent<T>(this Component self) where T : Component
	{
		T component = self.GetComponent<T>();
		if (component == null)
		{
			component.gameObject.AddComponent<T>();
		}
		return component;
	}
}
