|
|
|
|
using DG.Tweening;
|
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
|
|
|
|
|
public class MiniMap : ResourcePool
|
|
|
|
|
{
|
|
|
|
|
public RectTransform rect;
|
|
|
|
|
public RectTransform rectContent;
|
|
|
|
|
public GridLayoutGroup grid;
|
|
|
|
|
public ContentSizeFitter fitter;
|
|
|
|
|
public Text txtDungeon;
|
|
|
|
|
public Text txtDungeon2;
|
|
|
|
|
|
|
|
|
|
[Space(10)]
|
|
|
|
|
public MiniMapItem prefabItem;
|
|
|
|
|
public List<MiniMapItem> items;
|
|
|
|
|
public bool SHOW_PATH = false;
|
|
|
|
|
|
|
|
|
|
Dictionary<Vector2, MapBlock> dicBlks;
|
|
|
|
|
Dictionary<Vector2, MiniMapItem> dicItem;
|
|
|
|
|
List<MapBlock> blocks;
|
|
|
|
|
|
|
|
|
|
Vector2 min = new Vector2(999,999);
|
|
|
|
|
Vector2 max = new Vector2(-999, -999);
|
|
|
|
|
Vector3 posDivision = new Vector3(-50, 30, 0);
|
|
|
|
|
|
|
|
|
|
public void OnInitialized(MapManager mapManager)
|
|
|
|
|
{
|
|
|
|
|
txtDungeon2.text = txtDungeon.text = $"{mapManager.dungeonName} Dungeon {mapManager.floor + 1}F";
|
|
|
|
|
|
|
|
|
|
itemBefore = null;
|
|
|
|
|
|
|
|
|
|
fitter.enabled = true;
|
|
|
|
|
grid.enabled = true;
|
|
|
|
|
|
|
|
|
|
posDivision.x = grid.cellSize.x;
|
|
|
|
|
posDivision.y = -grid.cellSize.y;
|
|
|
|
|
|
|
|
|
|
ObjectAllHide();
|
|
|
|
|
|
|
|
|
|
this.dicBlks = mapManager.blocks;
|
|
|
|
|
blocks = dicBlks.Values.ToList();
|
|
|
|
|
|
|
|
|
|
blocks.Sort((a, b) => a.idx.x < b.idx.x ? -1 : 1);
|
|
|
|
|
min.x = blocks[0].idx.x;
|
|
|
|
|
max.x = blocks[blocks.Count - 1].idx.x;
|
|
|
|
|
|
|
|
|
|
blocks.Sort((a, b) => a.idx.y < b.idx.y ? -1 : 1);
|
|
|
|
|
min.y = blocks[0].idx.y;
|
|
|
|
|
max.y = blocks[blocks.Count - 1].idx.y;
|
|
|
|
|
|
|
|
|
|
dicItem = new Dictionary<Vector2, MiniMapItem>();
|
|
|
|
|
items.Clear();
|
|
|
|
|
|
|
|
|
|
Vector2 idx = Vector2.zero;
|
|
|
|
|
grid.constraint = GridLayoutGroup.Constraint.FixedColumnCount;
|
|
|
|
|
grid.constraintCount = (int)(Mathf.Abs(min.x) + max.x) + 1;
|
|
|
|
|
//grid.cellSize = new Vector2(rect.rect.width / (int)(Mathf.Abs(min.x) + max.x + 1), rect.rect.height / (int)(Mathf.Abs(min.y) + max.y + 1));
|
|
|
|
|
|
|
|
|
|
MiniMapItem item = null;
|
|
|
|
|
for (int j = (int)max.y; (int)min.y <= j; j--)
|
|
|
|
|
{
|
|
|
|
|
for (int i = (int)min.x; i < (int)max.x + 1; i++)
|
|
|
|
|
{
|
|
|
|
|
item = ObjectCreateLocalPos(prefabItem.gameObject, rectContent.transform, Vector3.one, Vector3.zero).GetComponent<MiniMapItem>();
|
|
|
|
|
items.Add(item);
|
|
|
|
|
|
|
|
|
|
idx.Set(i, j);
|
|
|
|
|
|
|
|
|
|
if (dicBlks.Keys.Contains(idx))
|
|
|
|
|
{
|
|
|
|
|
item.OnInitialized(this, dicBlks[idx], SHOW_PATH);
|
|
|
|
|
dicItem.Add(idx, item);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
StartCoroutine(Wait());
|
|
|
|
|
}
|
|
|
|
|
IEnumerator Wait()
|
|
|
|
|
{
|
|
|
|
|
yield return null;
|
|
|
|
|
fitter.enabled = true;
|
|
|
|
|
yield return null;
|
|
|
|
|
grid.enabled = true;
|
|
|
|
|
|
|
|
|
|
yield return null;
|
|
|
|
|
fitter.enabled = false;
|
|
|
|
|
yield return null;
|
|
|
|
|
grid.enabled = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<Vector2> dir = new List<Vector2>() { new Vector2(-1, 0), new Vector2(1, 0), new Vector2(0, -1), new Vector2(0, 1) };
|
|
|
|
|
public void OnNear(MapBlock blk, Vector2 idx)
|
|
|
|
|
{
|
|
|
|
|
for(int i = 0; i < dir.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
if (blk.doors[i] == null)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
Vector2 idxNear = idx + dir[i];
|
|
|
|
|
if (dicItem.ContainsKey(idxNear))
|
|
|
|
|
dicItem[idxNear].MapChanged(dicItem[idxNear].blk, false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MiniMapItem itemBefore;
|
|
|
|
|
MapBlock blkBefore;
|
|
|
|
|
public void OnChanged(MapBlock blk)
|
|
|
|
|
{
|
|
|
|
|
MiniMapItem item = items.Find(a => a.blk == blk);
|
|
|
|
|
if (item != null)
|
|
|
|
|
item.MapChanged(blk);
|
|
|
|
|
|
|
|
|
|
if (itemBefore != null)
|
|
|
|
|
itemBefore.MapChanged(blk);
|
|
|
|
|
|
|
|
|
|
itemBefore = item;
|
|
|
|
|
}
|
|
|
|
|
}
|