add change trains
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
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 Image buttonBase;
|
||||
public bool isSelected { get; private set; }
|
||||
|
||||
LocomotionHandler locomotionHandler;
|
||||
|
||||
void Start()
|
||||
{
|
||||
buttonBase = GetComponent<Image>();
|
||||
locomotionHandler = FindObjectOfType<LocomotionHandler>();
|
||||
}
|
||||
|
||||
public void Select()
|
||||
{
|
||||
if(isSelected) return;
|
||||
|
||||
var buttons = FindObjectsOfType<UITrainButton>();
|
||||
foreach(var item in buttons)
|
||||
{
|
||||
if(item.isSelected)
|
||||
item.Unselect();
|
||||
}
|
||||
|
||||
locomotionHandler.ShowTrain(trainType);
|
||||
buttonBase.DOColor(selectedColor, .2f);
|
||||
isSelected = true;
|
||||
}
|
||||
|
||||
public void Unselect()
|
||||
{
|
||||
buttonBase.DOColor(Color.white, .2f);
|
||||
isSelected = false;
|
||||
}
|
||||
|
||||
public void OnPointerClick(PointerEventData eventData)
|
||||
{
|
||||
Select();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user