You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
CrowdControl/Assets/3rd/D2D_Scripts/UI/Buttons/SpriteButton.cs

57 lines
1.5 KiB
C#

using TMPro;
using UnityEngine;
namespace D2D.UI
{
/// <summary>
/// Big and juicy button. The opposite of flat button
/// </summary>
public class SpriteButton : DButton
{
[SerializeField] private RectTransform foreground;
[SerializeField] private RectTransform background;
[SerializeField] private TextMeshProUGUI text;
private Vector3 releasePosition;
private Vector3 pressPosition;
private RectTransform textRect;
private void OnEnable()
{
releasePosition = foreground.anchoredPosition;
pressPosition = background.anchoredPosition;
if (text != null)
textRect = text.GetComponent<RectTransform>();
PointerDown += SetPressed;
PointerUp += SetReleased;
}
private void OnDisable()
{
PointerDown -= SetPressed;
PointerUp -= SetReleased;
}
private void SetPressed()
{
foreground.anchoredPosition = pressPosition;
background.gameObject.SetActive(false);
if (text != null)
textRect.anchoredPosition = pressPosition;
}
private void SetReleased()
{
foreground.anchoredPosition = releasePosition;
background.gameObject.SetActive(true);
if (text != null)
textRect.anchoredPosition = releasePosition;
}
}
}