177 lines
5.1 KiB
C#
177 lines
5.1 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using UnityEngine;
|
|
using WI;
|
|
using XED.Manage;
|
|
using static UnityEngine.Rendering.DebugUI;
|
|
|
|
namespace XED
|
|
{
|
|
[Serializable]
|
|
public class FloorCreateManager:MonoBehaviour,ISingle
|
|
{
|
|
[SerializeField]
|
|
private List<Room> allRoomsCase = new();
|
|
[SerializeField]
|
|
private List<Room> rooms = new();
|
|
private ConvexHull convexHull = new();
|
|
public Action<Floor> onCreateFloor;
|
|
public List<Floor> floors = new();
|
|
private Dictionary<Floor, List<LinePoint>> floorTable = new();
|
|
private Dictionary<LinePoint, List<Floor>> floorsMap = new();
|
|
|
|
//Wall 생성될때
|
|
//Point 움직임, 제거 이벤트 발생 할때
|
|
|
|
//메쉬는 유지해야함.
|
|
//계산은
|
|
public override void AfterAwake()
|
|
{
|
|
}
|
|
|
|
public void FindCycles(HashSet<LinePoint> linePoints)
|
|
{
|
|
allRoomsCase.Clear();
|
|
foreach (var point in linePoints)
|
|
{
|
|
FindOnePointCycle(point);
|
|
}
|
|
|
|
FindSmallRoom();
|
|
//Floor 생성 해야함
|
|
|
|
}
|
|
|
|
public void FindOnePointCycle(LinePoint point)
|
|
{
|
|
if (point.connectPoints.Count < 2)
|
|
return;
|
|
//Add할 타이밍
|
|
//분할될 타이밍
|
|
var connectPoints = point.connectPoints;
|
|
foreach (var connectPoint in connectPoints)
|
|
{
|
|
var room = new Room();
|
|
room.AddLinePoint(point);
|
|
AddConnectPoint(connectPoint, room);
|
|
}
|
|
}
|
|
private void AddConnectPoint(LinePoint point, Room room)
|
|
{
|
|
if (point.visited)
|
|
return;
|
|
if (room.IsContains(point))
|
|
{
|
|
if (room.points.Count < 3)
|
|
return;
|
|
room.firstPoints = room.points.First();
|
|
allRoomsCase.Add(room);
|
|
return;
|
|
}
|
|
|
|
point.visited = true;
|
|
room.AddLinePoint(point);
|
|
var connectPoints = point.connectPoints;
|
|
foreach (var connectPoint in connectPoints)
|
|
{
|
|
var temp = new Room();
|
|
temp.points = room.points.ToList();
|
|
AddConnectPoint(connectPoint, temp);
|
|
}
|
|
point.visited = false; ;
|
|
}
|
|
|
|
private void FindSmallRoom()
|
|
{
|
|
var roomFistPoint = new HashSet<LinePoint>();
|
|
|
|
foreach (var room in allRoomsCase)
|
|
{
|
|
roomFistPoint.Add(room.firstPoints);
|
|
}
|
|
|
|
foreach (var tt in roomFistPoint)
|
|
{
|
|
var re = allRoomsCase.Where(f => f.firstPoints.Equals(tt))
|
|
.OrderBy(f => f.points.Count).ToList();
|
|
//최소 points의 개수
|
|
var minCount = re.Select(f => f.points.Count).First();
|
|
foreach (var aa in re)
|
|
{
|
|
if (aa.points.Count != minCount)
|
|
continue;
|
|
if (CheckDuplicationRoom(aa))
|
|
continue;
|
|
|
|
convexHull.RoomLinePoint(aa);
|
|
rooms.Add(aa);
|
|
// CreateFloor(aa);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
void CreateFloor(Room room)
|
|
{
|
|
bool isequal = false;
|
|
foreach (var fl in floorTable)
|
|
{
|
|
isequal = Enumerable.SequenceEqual(room.points.OrderBy(x => x.name), fl.Value.OrderBy(z => z.name));
|
|
if (isequal)
|
|
break;
|
|
}
|
|
|
|
if(!isequal)
|
|
{
|
|
var poolManager = FindSingle<ObjectPoolManager>();
|
|
var floor = poolManager.Get<Floor>();
|
|
|
|
foreach (var value in room.points)
|
|
{
|
|
FloorTableAdd(floor, value);
|
|
FloorMap(value, floor);
|
|
}
|
|
floor.Set(room);
|
|
}
|
|
|
|
}
|
|
|
|
private void FloorTableAdd(Floor floor,LinePoint point)
|
|
{
|
|
if (!floorTable.ContainsKey(floor))
|
|
floorTable.Add(floor, new());
|
|
floorTable[floor].Add(point);
|
|
}
|
|
|
|
private void FloorMap(LinePoint point, Floor floor)
|
|
{
|
|
if (!floorsMap.ContainsKey(point))
|
|
floorsMap.Add(point, new());
|
|
floorsMap[point].Add(floor);
|
|
}
|
|
|
|
public void RemoveRoom(Room room)
|
|
{
|
|
|
|
}
|
|
private bool CheckDuplicationRoom(Room checkRoom)
|
|
{
|
|
foreach (var room in rooms)
|
|
{
|
|
if (checkRoom.points.Count != room.points.Count)
|
|
continue;
|
|
bool isequal = Enumerable.SequenceEqual(room.points.OrderBy(x => x.name), checkRoom.points.OrderBy(z => z.name));
|
|
if (isequal)
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
//Floor 지워지는 시점..
|
|
//재계산 하는 시점
|
|
//
|
|
}
|
|
}
|