MapElement GenerateElementRoot(E_MapElementType elementType, int startX, int startZ) { switch (elementType) { case E_MapElementType.Room: currentElement = new GameObject("Room").transform; currentElement.parent = transform; currentElement.position = new Vector3(startX * tileWidth, 0, startZ * tileWidth); layerRooms.Add(currentElement); currentElement.name = "Room_" + layerRooms.Count.ToString(); break; case E_MapElementType.Corridor: currentElement = new GameObject("Corridor").transform; currentElement.parent = transform; currentElement.position = new Vector3(startX * tileWidth, 0, startZ * tileWidth); layerCorridors.Add(currentElement); currentElement.name = "Corridor_" + layerCorridors.Count.ToString(); break; default: return(null); } MapElement currentMapElementScript = currentElement.gameObject.AddComponent <MapElement> (); currentMapElementScript.startX = startX; currentMapElementScript.startZ = startZ; return(currentMapElementScript); }
void CancelRecentMapElement(E_MapElementType targetType, GameObject target) { //GameObject target; switch (targetType) { case E_MapElementType.Corridor: //target = layerCorridors[layerCorridors.Count-1].gameObject; MapElement mapElemCorridor = target.GetComponent <MapElement>(); for (int i = 0; i < mapElemCorridor.tileSingle.Length; i++) { layerTile[mapElemCorridor.startX + mapElemCorridor.dirX * i, mapElemCorridor.startZ + mapElemCorridor.dirZ * i] = E_TileType.empty; } //补上被删除通道所连接的mapElem的缺口 mapElemCorridor.removedWall.gameObject.SetActive(true); //layerCorridors.RemoveAt(layerCorridors.Count-1); layerCorridors.Remove(target.transform); Destroy(target); break; case E_MapElementType.Room: //target = layerRooms[layerRooms.Count-1].gameObject; MapElement mapElemRoom = target.GetComponent <MapElement>(); for (int i = 0; i < mapElemRoom.tile.GetLength(0); i++) { for (int j = 0; j < mapElemRoom.tile.GetLength(1); j++) { layerTile[mapElemRoom.startX + i, mapElemRoom.startZ + j] = E_TileType.empty; } } layerRooms.Remove(target.transform); Destroy(target); break; default: break; } }