using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public static class ToolboxExtensions
{
    /// <summary>
    /// Checks to see if the GameObject has the component, and adds it if it doesn't
    /// </summary>
    /// <param name="theObject">the Gameobject</param>
    /// <typeparam name="T">the type of Component to add</typeparam>
    /// <returns>the new or existing component</returns>
    public static T GetOrAddNewComponent<T>(this GameObject theObject) where T : Component
    {
        if (theObject.GetComponent<T>() == null)
        {
            T returnValue = (T)theObject.AddComponent(typeof(T));
            return returnValue;
        }
        else
        {
            return theObject.GetComponent<T>() as T;
        }
    }


}
