44 lines
1.0 KiB
C#
44 lines
1.0 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace TcgEngine.UI
|
|
{
|
|
public class ToggleImage : MonoBehaviour
|
|
{
|
|
public Sprite onSprite;
|
|
public Sprite offSprite;
|
|
|
|
private Button _button;
|
|
private Image _image;
|
|
private bool _isShowOnSprite = false;
|
|
|
|
private void Awake()
|
|
{
|
|
_button = GetComponent<Button>();
|
|
if (_button != null)
|
|
{
|
|
_button.onClick.AddListener(SwitchButtonStatus);
|
|
_image = _button.GetComponent<Image>();
|
|
}
|
|
else
|
|
{
|
|
Debug.LogError("请检查是否存在按钮!");
|
|
}
|
|
}
|
|
|
|
private void SwitchButtonStatus()
|
|
{
|
|
_isShowOnSprite = !_isShowOnSprite;
|
|
|
|
_image.sprite = _isShowOnSprite ? onSprite : offSprite;
|
|
}
|
|
|
|
public bool GetButtonStatus()
|
|
{
|
|
return _isShowOnSprite;
|
|
}
|
|
}
|
|
} |