54 lines
1.3 KiB
C#
54 lines
1.3 KiB
C#
using System;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace Studio
|
|
{
|
|
public class UVCToggleButton : Button
|
|
{
|
|
Transform image_On;
|
|
Transform image_Off;
|
|
bool isOn;
|
|
public Action onClickEvent;
|
|
protected override void Awake()
|
|
{
|
|
image_Off = transform.Find(nameof(image_Off));
|
|
image_On = transform.Find(nameof(image_On));
|
|
isOn = true;
|
|
OnClick();
|
|
onClick.AddListener(OnClick);
|
|
}
|
|
|
|
public void SetOn(bool on)
|
|
{
|
|
isOn = on;
|
|
if (isOn)
|
|
{
|
|
image_On.gameObject.SetActive(true);
|
|
image_Off.gameObject.SetActive(false);
|
|
}
|
|
else
|
|
{
|
|
image_On.gameObject.SetActive(false);
|
|
image_Off.gameObject.SetActive(true);
|
|
}
|
|
}
|
|
|
|
private void OnClick()
|
|
{
|
|
isOn = !isOn;
|
|
if (isOn)
|
|
{
|
|
image_On.gameObject.SetActive(true);
|
|
image_Off.gameObject.SetActive(false);
|
|
}
|
|
else
|
|
{
|
|
image_On.gameObject.SetActive(false);
|
|
image_Off.gameObject.SetActive(true);
|
|
}
|
|
onClickEvent?.Invoke();
|
|
}
|
|
}
|
|
}
|