76 lines
1.6 KiB
C#
76 lines
1.6 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
|
|
using DG.Tweening;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using UnityEngine.EventSystems;
|
|
|
|
[RequireComponent(typeof(Image))]
|
|
public class UITrainButton : MonoBehaviour, IPointerClickHandler
|
|
{
|
|
public TrainType trainType;
|
|
[SerializeField] private Color selectedColor;
|
|
private Color unselectedColor;
|
|
private Image buttonBase;
|
|
public bool isSelected { get; private set; }
|
|
|
|
LocomotionHandler locomotionHandler;
|
|
public bool ableToUse = true;
|
|
public bool hideInDepo;
|
|
|
|
void Awake()
|
|
{
|
|
buttonBase = GetComponent<Image>();
|
|
unselectedColor = buttonBase.color;
|
|
}
|
|
|
|
public void Select()
|
|
{
|
|
if(isSelected || !ableToUse) return;
|
|
|
|
if(locomotionHandler == null)
|
|
locomotionHandler = FindObjectOfType<LocomotionHandler>();
|
|
|
|
var buttons = FindObjectsOfType<UITrainButton>();
|
|
foreach(var item in buttons)
|
|
{
|
|
if(item.isSelected)
|
|
item.Unselect();
|
|
}
|
|
|
|
FindObjectOfType<UIMainMenu>()
|
|
.ShowAboutTrainButton();
|
|
|
|
locomotionHandler.ShowTrain(trainType);
|
|
buttonBase.DOColor(selectedColor, .2f);
|
|
|
|
isSelected = true;
|
|
}
|
|
|
|
public void Reset()
|
|
{
|
|
isSelected = false;
|
|
ableToUse = true;
|
|
|
|
try
|
|
{
|
|
buttonBase.color = unselectedColor;
|
|
}
|
|
catch {}
|
|
}
|
|
|
|
public void Unselect()
|
|
{
|
|
if(!isSelected) return;
|
|
|
|
buttonBase.DOColor(Color.white, .2f);
|
|
isSelected = false;
|
|
}
|
|
|
|
public void OnPointerClick(PointerEventData eventData)
|
|
{
|
|
Select();
|
|
}
|
|
}
|