using UnityEngine;
namespace GameKit.Dependencies.Utilities
{
///
/// Ways a CanvasGroup can have it's blocking properties modified.
///
public enum CanvasGroupBlockingType
{
Unchanged = 0,
DoNotBlock = 1,
Block = 2,
}
public static class CanvaseGroups
{
public static void SetBlockingType(this CanvasGroup group, CanvasGroupBlockingType blockingType)
{
if (blockingType == CanvasGroupBlockingType.Unchanged)
return;
bool block = (blockingType == CanvasGroupBlockingType.Block);
group.blocksRaycasts = block;
group.interactable = block;
}
///
/// Sets a CanvasGroup blocking type and alpha.
///
/// How to handle interactions.
/// Alpha for CanvasGroup.
public static void SetActive(this CanvasGroup group, CanvasGroupBlockingType blockingType, float alpha)
{
group.SetBlockingType(blockingType);
group.alpha = alpha;
}
///
/// Sets a canvasGroup active with specified alpha.
///
public static void SetActive(this CanvasGroup group, float alpha)
{
group.SetActive(true, false);
group.alpha = alpha;
}
///
/// Sets a canvasGroup inactive with specified alpha.
///
public static void SetInactive(this CanvasGroup group, float alpha)
{
group.SetActive(false, false);
group.alpha = alpha;
}
///
/// Sets a group active state by changing alpha and interaction toggles.
///
public static void SetActive(this CanvasGroup group, bool active, bool setAlpha)
{
if (group == null)
return;
if (setAlpha)
{
if (active)
group.alpha = 1f;
else
group.alpha = 0f;
}
group.interactable = active;
group.blocksRaycasts = active;
}
///
/// Sets a group active state by changing alpha and interaction toggles with a custom alpha.
///
public static void SetActive(this CanvasGroup group, bool active, float alpha)
{
if (group == null)
return;
group.alpha = alpha;
group.interactable = active;
group.blocksRaycasts = active;
}
}
}