66 lines
1.7 KiB
C#
66 lines
1.7 KiB
C#
|
using System;
|
||
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using UnityEngine;
|
||
|
using UnityEngine.Serialization;
|
||
|
|
||
|
namespace Script.Map
|
||
|
{
|
||
|
public class MapManager : MonoBehaviour
|
||
|
{
|
||
|
public static MapManager ins;
|
||
|
[SerializeField] private CarObject seleCarObject;
|
||
|
|
||
|
[SerializeField] private List<CarObject> carObjects;
|
||
|
[SerializeField] private GameObject templateGrid;
|
||
|
|
||
|
public Grid[,] MapGrid ;
|
||
|
[SerializeField] private Transform gridParent;
|
||
|
public int x { get; private set; }
|
||
|
public int y { get; private set; }
|
||
|
public bool InitReady { get; private set; } = false;
|
||
|
|
||
|
private void Awake()
|
||
|
{
|
||
|
ins = this;
|
||
|
Init(10, 10);
|
||
|
}
|
||
|
|
||
|
public void Init(int _x,int _y)
|
||
|
{
|
||
|
InitReady = false;
|
||
|
x = _x;
|
||
|
y = _y;
|
||
|
MapGrid = new Grid[x, y];
|
||
|
StartCoroutine(InitGrid());
|
||
|
}
|
||
|
|
||
|
private IEnumerator InitGrid(Action action=null)
|
||
|
{
|
||
|
for (var i = 0; i < x; i++)
|
||
|
{
|
||
|
for (var j = 0; j < y; j++)
|
||
|
{
|
||
|
MapGrid[i, j] = Instantiate(templateGrid,gridParent).GetComponent<Grid>();
|
||
|
MapGrid[i,j].SetData(i,j);
|
||
|
MapGrid[i,j].SetBool(true);
|
||
|
MapGrid[i, j].SetRestPostion();
|
||
|
yield return null;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
foreach (var grid in MapGrid)
|
||
|
{
|
||
|
grid.SetAdjacentGrid();
|
||
|
}
|
||
|
action?.Invoke();
|
||
|
InitReady = true;
|
||
|
}
|
||
|
|
||
|
public void RestGrid(int _gx,int _gy,bool bo)
|
||
|
{
|
||
|
MapGrid[_gx,_gy].SetBool(bo);
|
||
|
}
|
||
|
}
|
||
|
}
|