83 lines
2.6 KiB
C#
83 lines
2.6 KiB
C#
using System;
|
|
using Script.Map;
|
|
using UnityEngine;
|
|
using Random = UnityEngine.Random;
|
|
|
|
namespace Script
|
|
{
|
|
public class GameManager : MonoBehaviour
|
|
{
|
|
public static GameManager ins;
|
|
[SerializeField] private PassengerObject _passengerObject;
|
|
[SerializeField] private Transform passengerParent;
|
|
|
|
private void Awake()
|
|
{
|
|
ins = this;
|
|
}
|
|
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
MapManager.ins.InitPlayData();
|
|
foreach (var grid in MapManager.ins.MapGrid)
|
|
{
|
|
if (!grid.Open) continue;
|
|
var colorIndex =Random.Range(0, 3);
|
|
var passenger = Instantiate(_passengerObject.gameObject, passengerParent).GetComponent<PassengerObject>();
|
|
passenger.transform.position=grid.transform.position;
|
|
passenger.passColor = (ColorEnum)colorIndex;
|
|
grid.passenger = passenger;
|
|
grid.buttonAction = grid.PlaySystemEvent;
|
|
}
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
|
|
}
|
|
|
|
public void MoveWaitEvent(Grid grid)
|
|
{
|
|
if (MapManager.ins.WaitSlot.MoveOpen(out var moveGrid))
|
|
{
|
|
if (grid.NorthOpen())
|
|
{
|
|
moveGrid.passenger = grid.passenger;
|
|
grid.passenger = null;
|
|
moveGrid.PassengerAni();
|
|
}
|
|
}
|
|
}
|
|
|
|
public void MoveCarEvent()
|
|
{
|
|
foreach (var waitSlot in MapManager.ins.WaitSlot.waits)
|
|
{
|
|
if (MapManager.ins.seleCar.CarMove(out var carGrid))
|
|
{
|
|
if (waitSlot.passenger.passColor==MapManager.ins.seleCar.carColor)
|
|
{
|
|
carGrid.passenger = waitSlot.passenger;
|
|
waitSlot.passenger = null;
|
|
carGrid.passenger.transform.parent = carGrid.transform;
|
|
carGrid.PassengerAni();
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public void NextCar()
|
|
{
|
|
MapManager.ins.seleCarObject.movePostion = MapManager.ins.endCar;
|
|
MapManager.ins.seleCarObject.CarAni();
|
|
MapManager.ins.carObjects.Remove(MapManager.ins.seleCarObject);
|
|
MapManager.ins.seleCarObject = MapManager.ins.carObjects[0];
|
|
MapManager.ins.seleCarObject.movePostion = MapManager.ins.waitCar;
|
|
MapManager.ins.seleCarObject.CarAni();
|
|
}
|
|
}
|
|
} |