Пример #1
0
		public Block AddBlock(MazeNode node)
		{
			if (node is MazeRoom)
			{
				MazeRoom room = node as MazeRoom;
				if (room.HasCreated)
				{
					return null;
				}
				else
				{
					room.HasCreated = true;
				}
			}

			Block block = Block.Create(node);
			int key = Block.GetBlockKey(node.Col, node.Row);
			if (blockDic.ContainsKey(key))
			{
				BaseLogger.LogFormat("Add same block: {0}", key.ToString());
			}
			blockDic.Add(key, block);
			node.AboveBlock = block;
            AddMockNode(node);

			return block;
		}
Пример #2
0
		private MazeNode CreateMazeNode(int col, int row)
		{
			MazeNode node = new MazeNode();
			node.Col = col;
			node.Row = row;
			return node;
		}
Пример #3
0
		public void Init()
		{
			mazeData = MazeDataManager.Instance.CurrentMazeData;
			MazeBuilder builder = new MazeBuilder(mazeData);
			mazeTable = builder.Build();
			StartNode = mazeTable.GetNode(mazeData.StartCol, mazeData.StartRow);

            InitGlobalExplorationPositions();
//            TestGlobalExplorationPositions();
		}
Пример #4
0
		public void Dispose()
		{
			blockDic.Clear();
			mockNodeSet.Clear();
            globalExplorationNodeList.Clear();

			ToDeleteNodeList.Clear();
			ToCreateNodeList.Clear();
			prevAroundList.Clear();
			mazeTable = null;
			StartNode = null;
			mazeData = null;
		}
Пример #5
0
		public static Block Create(MazeNode node)
		{
			if (node == null)
			{
				BaseLogger.Log("null node");
				return null;
			}

			ResourceManager resManager = ResourceManager.Instance;
			
			Block block = new Block();
			block.Uid = Guid.NewGuid().ToString();

			PassageType passageType = MazeUtil.GetPassageType(node);
			if (node is MazeRoom)
			{
				MazeRoom room = node as MazeRoom;
				block.Data = room.Data;
			}
			else
			{
				block.Data = BlockDataManager.Instance.GetRandomPassageData(passageType); 
			}

			block.Script = resManager.LoadAsset<BlockScript>(ObjectType.GameObject, block.Data.GetResPath());
            block.Script.Uid = block.Uid;
            block.Script.transform.parent = RootTransform.Instance.BlockRoot;

			if (node is MazeRoom)
			{
				MazeRoom room = node as MazeRoom;
				block.SetRotation(room.Direction);
				block.SetPosition(room.Col, room.Row);
			}
			else
			{
				block.SetPosition(node.Col, node.Row);
				int direction = MazeUtil.GetPassageDirection(node, passageType);
				block.SetRotation(direction);
				block.InitRandomDecorations();
			}

            block.ExplorationType = node.ExplorationType;

			return block;
		}
Пример #6
0
        private void CreateIndicator(MazeNode node)
        {
            float cubeSize = GlobalConfig.BlockConfig.MockCubeSize;
            float posY = GlobalConfig.BlockConfig.MockBlockPosY;

            GameObject indicator = ResourceManager.Instance.LoadGameObject(ObjectType.GameObject, GlobalConfig.BlockConfig.IndicatorPath);
            indicator.transform.position = new Vector3(node.Col * cubeSize, posY + 2f, node.Row * cubeSize);
            indicator.transform.parent = RootTransform.Instance.MockBlockRoot;
        }
Пример #7
0
		private void CreateMockPassage(MazeNode node)
		{
			float cubeSize = GlobalConfig.BlockConfig.MockCubeSize;
			float posY = GlobalConfig.BlockConfig.MockBlockPosY;

			GameObject cube = ResourceManager.Instance.LoadGameObject(ObjectType.GameObject, GlobalConfig.BlockConfig.MockPassagePath);
			cube.transform.position = new Vector3(node.Col * cubeSize, posY, node.Row * cubeSize);
			cube.transform.parent = RootTransform.Instance.MockBlockRoot;
            cube.GetComponent<Sparking>().IsEnabled = node.ExplorationType != ExplorationType.Common;

			GameObject link = null;
            float offsetSize = cubeSize * 0.5f;
			if (node.LinkList[0] != null)
			{
				link = ResourceManager.Instance.LoadGameObject(ObjectType.GameObject, GlobalConfig.BlockConfig.MockLinkPath);
				link.transform.localEulerAngles = Vector3.up * 90;
                link.transform.position = new Vector3(node.Col * cubeSize, posY, node.Row * cubeSize + offsetSize);
				link.transform.parent = RootTransform.Instance.MockBlockRoot;
			}
			if (node.LinkList[1] != null)
			{
				link = ResourceManager.Instance.LoadGameObject(ObjectType.GameObject, GlobalConfig.BlockConfig.MockLinkPath);
                link.transform.position = new Vector3(node.Col * cubeSize + offsetSize, posY, node.Row * cubeSize);
				link.transform.parent = RootTransform.Instance.MockBlockRoot;
			}
			if (node.LinkList[2] != null)
			{
				link = ResourceManager.Instance.LoadGameObject(ObjectType.GameObject, GlobalConfig.BlockConfig.MockLinkPath);
				link.transform.localEulerAngles = Vector3.up * 90;
                link.transform.position = new Vector3(node.Col * cubeSize, posY, node.Row * cubeSize - offsetSize);
				link.transform.parent = RootTransform.Instance.MockBlockRoot;
			}
			if (node.LinkList[3] != null)
			{
				link = ResourceManager.Instance.LoadGameObject(ObjectType.GameObject, GlobalConfig.BlockConfig.MockLinkPath);
                link.transform.position = new Vector3(node.Col * cubeSize - offsetSize, posY, node.Row * cubeSize);
				link.transform.parent = RootTransform.Instance.MockBlockRoot;
			}
		}
Пример #8
0
		private void ExpandNode(MazeNode node)
		{
			int col, row;
			int baseCol, baseRow;

			nodeList.Remove(node);

			for (int direction = 0; direction < 4; ++direction)
			{
				if (node.LinkList[direction] != null)
				{
					continue;
				}

				if (RandomUtils.Value() < mazeData.LinkRate)
				{
					int oppositeDirection = MazeUtil.GetOppositeDirection(direction);
					MazeUtil.GetNeighbor(direction, node.Col, node.Row, out col, out row);
					if (mazeTable.CheckRange(col, row))
					{
						if (RandomUtils.Value() < mazeData.PassageRate)
						{
							//Node
							if (!mazeTable.CheckOccupied(col, row))
							{
								MazeNode newNode = CreateMazeNode(col, row);
								node.LinkList[direction] = newNode;
								newNode.LinkList[oppositeDirection] = node;
								nodeList.Add(newNode);
								mazeTable.SetNode(newNode, newNode.Col, newNode.Row);
								mazeTable.AddMazeNode(newNode);
							}
							else
							{
								node.LinkList[direction] = null;
							}
						}
						else
						{
							//Room
							BlockData roomData = BlockDataManager.Instance.GetRandomRoomData();

							MazeUtil.GetRoomBasePos(direction, col, row, roomData.Cols, roomData.Rows, roomData.LeftOffset, out baseCol, out baseRow);
							if (mazeTable.CheckRoom(baseCol, baseRow, roomData.Cols, roomData.Rows))
						    {
								MazeRoom room = CreateMazeRoom(roomData, direction, col, row);
								for (int i = baseCol; i < baseCol + roomData.Cols; ++i)
								{
									for (int j = baseRow; j < baseRow + roomData.Rows; ++j)
									{
										mazeTable.SetNode(room, i, j);
									}
								}
								node.LinkList[direction] = room;
								room.LinkList[oppositeDirection] = node;
								mazeTable.AddMazeNode(room);
							}
							else
							{
								node.LinkList[direction] = null;
							}
						}
					}
					else
					{
						node.LinkList[direction] = null;
					}
				}
			}

		}
Пример #9
0
		public void RemoveBlock(MazeNode node)
		{
			if (node is MazeRoom)
			{
				MazeRoom room = node as MazeRoom;
				//Prevent deleting same block twice.
				if (room.HasCreated)
				{
					room.HasCreated = false;
				}
				else
				{
					return;
				}
			}

			int key = Block.GetBlockKey(node.Col, node.Row);
			if (!blockDic.ContainsKey(key))
			{
				BaseLogger.LogFormat("Remove none-exist block: {0}", key.ToString());
			}
			Block block = blockDic[key];
			blockDic.Remove(key);
			node.AboveBlock = null;

			Block.Recycle(block);
		}
Пример #10
0
		private void UpdateSearchIndexRecurrsively(MazeNode startNode, MazeNode searchNode, int distance)
		{
			int scope = GlobalConfig.BlockConfig.RefreshScope;
			if (Mathf.Abs(searchNode.Col - startNode.Col) > scope || Mathf.Abs(searchNode.Row - startNode.Row) > scope )
			{
				return;
			}
			
			searchNode.SearchIndex = distance++;
//			Logger.Log(searchNode.Col, searchNode.Row, searchNode.SearchIndex);
			for (int i = 0; i < searchNode.LinkList.Length; ++i)
			{
				MazeNode nextNode = searchNode.LinkList[i];
				if (nextNode != null && nextNode.SearchIndex == -1)
				{
					UpdateSearchIndexRecurrsively(startNode, nextNode, distance);
				}
			}
		}
Пример #11
0
        private void AddMockNode(MazeNode node)
		{
            if (!mockNodeSet.Contains(node))
				mockNodeSet.Add(node);
		}
Пример #12
0
		public void SetNode(MazeNode node, int col, int row)
		{
			if (!CheckRange(col, row))
			{
				BaseLogger.LogFormat("Maze node out of range: {0}, {1}", node.Col, node.Row);
			}
			allNodes[col, row] = node;
		}
Пример #13
0
		public void AddMazeNode(MazeNode node)
		{
			mazeNodesList.Add(node);
		}
Пример #14
0
		public static int GetPassageDirection(MazeNode node, PassageType type)
		{
			if (type == PassageType.One)
			{
				for (int i = 0; i < 4; ++i)
				{
					if (node.LinkList[i] != null)
					{
						return GetOppositeDirection(i);
					}
				}
			}
			else if (type == PassageType.TwoLine)
			{
				for (int i = 0; i < 4; ++i)
				{
					if (node.LinkList[i] != null)
					{
						return i;
					}
				}
			}
			else if (type == PassageType.TwoTurn)
			{
				for (int i = 0; i < 4; ++i)
				{
					if (node.LinkList[i] == null && node.LinkList[GetNextDirection(i)] != null)
					{
						return i;
					}
				}
			}
			else if (type == PassageType.Three)
			{
				for (int i = 0; i < 4; ++i)
				{
					if (node.LinkList[i] == null)
					{
						return i;
					}
				}
			}
			return 0;
		}
Пример #15
0
		public static PassageType GetPassageType(MazeNode node)
		{
			int linkCount = 0;
			for (int i = 0; i < 4; ++i)
			{
				linkCount += node.LinkList[i] != null ? 1 : 0;
			}
			if (linkCount == 1)
			{
				return PassageType.One;
			}
			else if (linkCount == 2)
			{
				if (node.LinkList[0] == null && node.LinkList[2] == null ||
				    node.LinkList[1] == null && node.LinkList[3] == null)
				{
					return PassageType.TwoLine;
				}
				else
				{
					return PassageType.TwoTurn;
				}
			}
			else if (linkCount == 3)
			{
				return PassageType.Three;
			}
			else
			{
				return PassageType.Four;
			}
		}
Пример #16
0
		public static int GetNodeLinkCount(MazeNode node)
		{
			int sum = 0;
			for (int i = 0; i < 4; ++i)
			{
				sum += node.LinkList[i] != null ? 1 : 0;
			}
			return sum;
		}