Files
Continentis/Assets/OtherPlugins/Feel/MMTools/Accessories/MMActivation/MMToggleActive.cs
SoulliesOfficial d09b58fd80 架构大更
2026-03-20 11:56:50 -04:00

34 lines
1.0 KiB
C#

using UnityEngine;
namespace MoreMountains.Tools
{
/// <summary>
/// This very simple class simply exposes a method to toggle the GameObject it's on (or a target one if left empty in
/// the inspector) active or inactive
/// </summary>
public class MMToggleActive : MonoBehaviour
{
[Header("Target - leave empty for self")]
/// the target gameobject to toggle. Leave blank for auto grab
public GameObject TargetGameObject;
/// a test button
[MMInspectorButton("ToggleActive")] public bool ToggleActiveButton;
/// <summary>
/// On awake, grabs self if needed
/// </summary>
protected virtual void Awake()
{
if (TargetGameObject == null) TargetGameObject = gameObject;
}
/// <summary>
/// Toggles the target gameobject's active state
/// </summary>
public virtual void ToggleActive()
{
TargetGameObject.SetActive(!TargetGameObject.activeInHierarchy);
}
}
}