void InitNodes() { foreach (RectNode node in _pageList) { node.AnchorPos = node.gameObject.GetComponent <RectTransform>().anchoredPosition; if (node.AnchorPos == Vector2.zero) { _nowPage = node; } } }
private void GenerateDungeon(ref DungeonComponent dungeon, ref DynamicBuffer <EntityBufferElement> cellsBuffer) { Debug.Assert(dungeon.IsPendingGenerate, "This dungeon is not pending generate."); dungeon.IsPendingGenerate = false; // Set all cells as wall SetWallAll(ref cellsBuffer, true); // Rooms Rect fullRect = new Rect(int2.zero, dungeon.SizeInCell.x, dungeon.SizeInCell.y); RectNode root = RectNode.CreateBspTree(fullRect, dungeon.MaxRoomLengthInCells, dungeon.MinSplitRatio, dungeon.MaxSplitRatio); List <RectNode> leafs = root.GetLeafs(); Dictionary <Rect, Room> rooms = new Dictionary <Rect, Room>(); foreach (RectNode leaf in leafs) { Room room = GenerateRoom(leaf.Rect, dungeon.MinRoomLengthInCells, dungeon.SizeInCell.x, ref cellsBuffer); rooms.Add(leaf.Rect, room); } // Paths Stack <RectNode> nodeStack = new Stack <RectNode>(); nodeStack.Push(root); while (nodeStack.Count > 0) { RectNode node = nodeStack.Pop(); if (node.LeftNode == null && node.RightNode == null) { continue; } Room roomLeft = rooms[node.LeftNode.GetRandomLeaf().Rect]; Room roomRight = rooms[node.RightNode.GetRandomLeaf().Rect]; GeneratePath(roomLeft, roomRight, dungeon.SizeInCell.x, ref cellsBuffer); nodeStack.Push(node.LeftNode); nodeStack.Push(node.RightNode); } // Extra paths if (root != null && root.LeftNode != null && root.RightNode != null) { for (int count = 0; count < dungeon.ExtraPathNum; count++) { Room roomLeft = rooms[root.LeftNode.GetRandomLeaf().Rect]; Room roomRight = rooms[root.RightNode.GetRandomLeaf().Rect]; GeneratePath(roomLeft, roomRight, dungeon.SizeInCell.x, ref cellsBuffer); } } }
public void Move2Left() { _targetPos = _nowPage.Left.AnchorPos; _nowPage = _nowPage.Left; }
public void Move2Right() { _targetPos = _nowPage.Right.AnchorPos; _nowPage = _nowPage.Right; }
public void Move2Bot() { _targetPos = _nowPage.Bottom.AnchorPos; _nowPage = _nowPage.Bottom; }
public void Move2Top() { _targetPos = _nowPage.Top.AnchorPos; _nowPage = _nowPage.Top; }