UI替换与对应代码进行调整
This commit is contained in:
44
Assets/TcgEngine/Scripts/UI/ToggleImage.cs
Normal file
44
Assets/TcgEngine/Scripts/UI/ToggleImage.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user