// Copyright (c) 2015 - 2023 Doozy Entertainment. All Rights Reserved. // This code can only be used under the standard Unity Asset Store End User License Agreement // A Copy of the EULA APPENDIX 1 is available at http://unity3d.com/company/legal/as_terms using UnityEngine; namespace Doozy.Runtime.Common.Extensions { /// Extension methods for the GameObject class public static class GameObjectExtensions { /// Gets or adds a component of type T to the target GameObject. /// Target GameObject /// Type of component to get or add /// The component of type T public static T GetOrAddComponent(this GameObject target) where T : MonoBehaviour => target.GetComponent() ?? target.AddComponent(); /// Checks if the target GameObject has a component of type T attached to it. /// Target GameObject /// Type of component to check for /// True if the target GameObject has a component of type T attached to it public static bool HasComponent(this GameObject target) where T : MonoBehaviour => target.GetComponent() != null; } }