90 lines
1.9 KiB
C#
90 lines
1.9 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using DG.Tweening;
|
|
using Script;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class CarObject : MonoBehaviour
|
|
{
|
|
[SerializeField] private List<Grid> _carGrids;
|
|
|
|
public ColorEnum carColor
|
|
{
|
|
get { return _colorEnum; }
|
|
set
|
|
{
|
|
_colorEnum = value;
|
|
if (_image==null)
|
|
{
|
|
_image = GetComponent<Image>();
|
|
}
|
|
|
|
_image.color = _colorEnum switch
|
|
{
|
|
ColorEnum.white => Color.white,
|
|
ColorEnum.red => Color.red,
|
|
ColorEnum.yellow => Color.yellow,
|
|
_ => throw new ArgumentOutOfRangeException()
|
|
};
|
|
}
|
|
}
|
|
[SerializeField] private ColorEnum _colorEnum;
|
|
public Transform movePostion;
|
|
private bool aniPlay=false;
|
|
[SerializeField] private Image _image;
|
|
private void Awake()
|
|
{
|
|
foreach (var grid in _carGrids)
|
|
{
|
|
grid.action = NextEvent;
|
|
}
|
|
|
|
aniPlay = false;
|
|
}
|
|
|
|
public bool CarMove(out Grid carGrid)
|
|
{
|
|
carGrid = null;
|
|
foreach (var grid in _carGrids.Where(grid => grid.passenger==null))
|
|
{
|
|
carGrid = grid;
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public void NextEvent()
|
|
{
|
|
bool _lsbo = true;
|
|
foreach (var grid in _carGrids)
|
|
{
|
|
if (grid.passenger==null)
|
|
{
|
|
_lsbo = false;
|
|
}
|
|
|
|
if (grid.aniPlay)
|
|
{
|
|
_lsbo = false;
|
|
}
|
|
}
|
|
|
|
if (_lsbo)
|
|
{
|
|
GameManager.ins.NextCar();
|
|
}
|
|
}
|
|
|
|
public void CarAni()
|
|
{
|
|
aniPlay = true;
|
|
transform.DOMove(movePostion.position, 0.2f).OnComplete(() =>
|
|
{
|
|
aniPlay = false;
|
|
});
|
|
}
|
|
}
|