WXGame/d2/Assets/Script/GameManager.cs

83 lines
2.6 KiB
C#
Raw Permalink Normal View History

2024-10-22 11:31:23 +08:00
using System;
using Script.Map;
2024-10-22 09:17:28 +08:00
using UnityEngine;
2024-10-22 11:31:23 +08:00
using Random = UnityEngine.Random;
2024-10-22 09:17:28 +08:00
namespace Script
{
public class GameManager : MonoBehaviour
{
2024-10-22 11:31:23 +08:00
public static GameManager ins;
[SerializeField] private PassengerObject _passengerObject;
[SerializeField] private Transform passengerParent;
private void Awake()
{
ins = this;
}
2024-10-22 09:17:28 +08:00
// Start is called before the first frame update
void Start()
{
2024-10-22 11:31:23 +08:00
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;
}
2024-10-22 09:17:28 +08:00
}
// Update is called once per frame
void Update()
{
}
2024-10-22 11:31:23 +08:00
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()
{
2024-10-23 09:12:15 +08:00
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();
}
}
}
2024-10-22 11:31:23 +08:00
}
2024-10-23 09:12:15 +08:00
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();
}
2024-10-22 09:17:28 +08:00
}
2024-10-23 09:12:15 +08:00
}