1
This commit is contained in:
53
Assets/Scripts/UVCToggleButton.cs
Normal file
53
Assets/Scripts/UVCToggleButton.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user