// 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.UIManager.Extensions
{
public static class RectTransformExtensions
{
/// Reset the attached CanvasGroup component (if there is one)
/// Target RectTransform
/// Is the group interactable (are the elements beneath the group enabled)
/// Does this group block raycasting (allow collision)
/// Should a CanvasGroup be attached to the target RectTransform, if one does not exist
public static RectTransform ResetCanvasGroup(this RectTransform target, bool interactable = true, bool blockRaycasts = true, bool addCanvasGroupIfNotFound = false)
{
CanvasGroup canvasGroup = target.GetComponent();
if (canvasGroup == null)
{
if (addCanvasGroupIfNotFound)
canvasGroup = target.gameObject.AddComponent();
else
return target;
}
canvasGroup.interactable = interactable;
canvasGroup.blocksRaycasts = blockRaycasts;
return target;
}
}
}