46 lines
970 B
C#
46 lines
970 B
C#
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
[RequireComponent(typeof(Button))]
|
|
public class UIToggleSwap : MonoBehaviour
|
|
{
|
|
public event Action<bool> OnSwitch;
|
|
|
|
public bool IsOn
|
|
{
|
|
get
|
|
{
|
|
return mIsOn;
|
|
}
|
|
set
|
|
{
|
|
mIsOn = value;
|
|
if (mSignOn != null) mSignOn.SetActive(mIsOn);
|
|
if (mSignOff != null) mSignOff.SetActive(!mIsOn);
|
|
|
|
OnSwitch?.Invoke(mIsOn);
|
|
}
|
|
}
|
|
|
|
[SerializeField] GameObject mSignOn;
|
|
[SerializeField] GameObject mSignOff;
|
|
[SerializeField] AudioType mClickSound = AudioType.None;
|
|
|
|
private Button mBtnClick;
|
|
private bool mIsOn;
|
|
|
|
private void Awake()
|
|
{
|
|
mBtnClick = GetComponent<Button>();
|
|
mBtnClick.onClick.AddListener(OnClick);
|
|
}
|
|
|
|
private void OnClick()
|
|
{
|
|
IsOn = !IsOn;
|
|
|
|
AudioManager.Instance.PlaySound(mClickSound);
|
|
}
|
|
} |