using System.Collections.Generic;
using UnityEditor.ShaderGraph.Internal;
using UnityEngine;
using UnityEngine.Tilemaps;
public class Room : MonoBehaviour
{
// Start is called once before the first execution of Update after the MonoBehaviour is created
public List<Room> Enter = new List<Room>();
public List<Room> Exit = new List<Room>();
public Vector2 pos;
public Tilemap wall;
/**
* 방향에 맞춰 벽 뚫기
*/
public void setUp()
{
foreach (Room room in Enter)
{
makeCorr(room.pos);
}
foreach (Room room in Exit)
{
makeCorr(room.pos);
}
}
public void makeCorr(Vector2 from)
{
float x = from.x - pos.x;
float y = from.y - pos.y;
if(Mathf.Abs(x) > Mathf.Abs(y))
{
if(x > 0)
{
RemoveWall(Vector2Int.right);
}
else
{
RemoveWall(Vector2Int.left);
}
}
else
{
if (y > 0)
{
RemoveWall(Vector2Int.up);
}
else
{
RemoveWall(Vector2Int.down);
}
}
}
public void RemoveWall(Vector2Int direc)
{
wall.CompressBounds();
Vector3Int cellPos = wall.WorldToCell(transform.position);
Vector3Int tileToRemove = cellPos;
Vector3Int size = wall.size;
int halfWidth = Mathf.FloorToInt(wall.size.x / 2f);
int halfHeight = Mathf.FloorToInt(wall.size.y / 2f);
if (direc == Vector2Int.right)
{
tileToRemove += new Vector3Int(halfWidth, 0, 0);
wall.SetTile(tileToRemove + Vector3Int.up, null);
wall.SetTile(tileToRemove + Vector3Int.down, null);
}
else if (direc == Vector2Int.left)
{
tileToRemove += new Vector3Int(-halfWidth, 0, 0);
wall.SetTile(tileToRemove + Vector3Int.up, null);
wall.SetTile(tileToRemove + Vector3Int.down, null);
}
else if (direc == Vector2Int.up)
{
tileToRemove += new Vector3Int(0, halfHeight, 0);
wall.SetTile(tileToRemove + Vector3Int.left, null);
wall.SetTile(tileToRemove + Vector3Int.right, null);
}
else if (direc == Vector2Int.down)
{
tileToRemove += new Vector3Int(0, -halfHeight, 0);
wall.SetTile(tileToRemove + Vector3Int.left, null);
wall.SetTile(tileToRemove + Vector3Int.right, null);
}
wall.SetTile(tileToRemove, null);
}
}
양방향으로 뚫려야하는데 어디는 Exit만 뚫리고 어디는 Enter만 뚫리고 이럼
심지어 Exit 4개있으면 3개만 뚫린놈도 있음 ㄱ-
뭔 좃버그인지 감도 안잡히고 AI들도 잘 몰르는 눈치임...
float x = from.x - pos.x; float y = from.y - pos.y; 여기서 pos 값이 뭐임? from은 방향 벡터이고
from방 위치 - 현재방 위치
grid 좌표 문제일 가능성이 높음
시작값 0 문제였네 +값에 -1 하니까 됨