string getPrefabName(List <MapDir> mapDirList, GameObject curCellGo, MapConnection mapConnectionData, ref Quaternion rotation) { string s = ""; int neighborCount = mapDirList.Count; switch (neighborCount) { case 0: s = getAssetPath(mapConnectionData.Default.Go); rotation = Quaternion.Euler(0, mapConnectionData.Default.Angle, 0) * curCellGo.transform.rotation; break; case 1: s = getAssetPath(mapConnectionData.End.Go); rotation = Quaternion.Euler(0, mapConnectionData.End.Angle, 0) * getRotationByMapDir(mapDirList[0]); break; case 2: { if (Mathf.Abs(mapDirList[0] - mapDirList[1]) == 2) { s = getAssetPath(mapConnectionData.Forward.Go); if (mapDirList[0] == MapDir.UP || mapDirList[0] == MapDir.DOWN) { rotation = Quaternion.Euler(0, mapConnectionData.Forward.Angle, 0) * Quaternion.identity; } else { rotation = Quaternion.Euler(0, mapConnectionData.Forward.Angle, 0) * Quaternion.Euler(0, 90, 0); } } else { s = getAssetPath(mapConnectionData.Turn.Go); rotation = Quaternion.Euler(0, mapConnectionData.Turn.Angle, 0) * getTurnRotationByMapDir(mapDirList[0], mapDirList[1]); } } break; case 3: s = getAssetPath(mapConnectionData.Tform.Go); rotation = Quaternion.Euler(0, mapConnectionData.Tform.Angle, 0) * getRotationByMapDir(mapDirList[0], mapDirList[1], mapDirList[2]); break; case 4: s = getAssetPath(mapConnectionData.Cross.Go); rotation = Quaternion.Euler(0, mapConnectionData.Cross.Angle, 0) * Quaternion.identity; break; default: break; } return(s); }
public void stepOnTile(Tile t) { isMoving = false; /*int xr = xa; * int yr = ya; * if (xr < -1) xr = -1; * if (xr > 1) xr = 1; * if (yr < -1) yr = -1; * if (yr > 1) yr = 1;*/ if (map.isMapConnection((x >> 4), (y >> 4))) { MapConnection con = map.getConnection((x >> 4), (y >> 4)); if (con != null) { changeMap(con.mapid); if (con.direction == ConnectionDirection.LEFT) { x = (map.w - 1) << 4; y -= con.offset << 4; } else if (con.direction == ConnectionDirection.UP) { y = (map.h - 1) << 4; x -= con.offset << 4; } else if (con.direction == ConnectionDirection.RIGHT) { x = 0; y -= con.offset << 4; } else if (con.direction == ConnectionDirection.DOWN) { y = 0; x -= con.offset << 4; } } } xa = 0; ya = 0; }
public Map(PokeEngine engine, int id) { this.engine = engine; this.mapid = id; entities = new List <Entity>(); initialize(id); if (!(this is MapConnection)) { if (MapProvider.getInstance().getConnections(id) != null) { foreach (ConnectionInfo info in MapProvider.getInstance().getConnections(id)) { if (info.dir == ConnectionDirection.LEFT) { connectionLeft = info.createConnectionFromInfo(this); } else if (info.dir == ConnectionDirection.UP) { connectionUp = info.createConnectionFromInfo(this); } else if (info.dir == ConnectionDirection.RIGHT) { connectionRight = info.createConnectionFromInfo(this); } else if (info.dir == ConnectionDirection.DOWN) { connectionDown = info.createConnectionFromInfo(this); } } } /*connectionLeft = new MapConnection(engine, this, ConnectionDirection.LEFT, 2, 0); * connectionUp = new MapConnection(engine, this, ConnectionDirection.UP, 2, 0); * connectionRight = new MapConnection(engine, this, ConnectionDirection.RIGHT, 2, 1); * connectionDown = new MapConnection(engine, this, ConnectionDirection.DOWN, 2, 0);*/ } }
//cellGo -> default gameObject //prefabName -> Map Connection prefab public override void Action(string prefabName, GameObject cellGo, AssetCellData cellData, DataMode dataMode, bool isObstacle, List <MapIndex> mapIndexList) { mapIndexList.Clear(); base.Action(prefabName, cellGo, cellData, dataMode, isObstacle, mapIndexList); if (Input.GetMouseButton(0)) { if (dataMode == DataMode.ADD) { int xIndex = -1; int zIndex = -1; MapUtility.CalCellIndexByMousePosition(mapController.CenterPosition, mapController.MapSizeX, mapController.MapSizeZ, rayCastMapLayer, ref xIndex, ref zIndex); if (xIndex >= 0 && zIndex >= 0) { int id = MapUtility.CoordinateToId(xIndex, zIndex, mapController.MapSizeX); if (!buildMapId.Contains(id)) { if (!isPress) { if (totalBuildMapId.ContainsKey(id)) { buildHeight = totalBuildMapId[id]; } else { buildHeight = MapUtility.CalCellHeightPosition(mapController.MapDataCollection, xIndex, zIndex, cellData); } } if (mapController.MapDataCollection.CanBuildOnTheMap(xIndex, zIndex, buildHeight, cellData.Size) || totalBuildMapId.ContainsKey(id)) { buildMapId.Add(id); //Draw dummy object GameObject dummy = Object.Instantiate(dummyObject) as GameObject; dummy.transform.parent = dummyParent.transform; Vector3 pos = mapController.GetCellPosition(xIndex, zIndex); dummy.transform.position = new Vector3(pos.x, buildHeight, pos.z); isPress = true; } } } } else if (dataMode == DataMode.ERASE) { GameObject hitObject = MapUtility.GetRayCastMapObjectByMousePosition(rayCastLayer); if (hitObject != null) { AssetCellData cd = hitObject.GetComponent <AssetCellData>(); mapController.EraseCellData(cd); totalBuildMapId.Remove(cd.MapObj.Id); } } } else if (Input.GetMouseButtonUp(0) && isPress) { if (buildMapId.Count == 0) { return; } MapConnection mapConn = (Resources.Load(MapSetting.MAP_CONNECT_TILE_FOLDER_NAME + prefabName.GetPathWidthoutExtension()) as GameObject).GetComponent <MapConnection>(); checkIfNeedReBuild(mapController); List <MapDir> neighBorList = new List <MapDir>(); foreach (var item in buildMapId) { int curXIndex = -1; int curZIndex = -1; MapUtility.IdToCoordinate(item, mapController.MapSizeX, ref curXIndex, ref curZIndex); getNeighborDir(curXIndex, curZIndex, mapController, neighBorList); Quaternion rot = Quaternion.identity; string p = getPrefabName(neighBorList, cellGo, mapConn, ref rot); if (!isObstacle) { mapController.UpdateCellData(p, curXIndex, curZIndex, buildHeight, cellData.Size, rot); } else { mapController.UpdateCellData(p, curXIndex, curZIndex, buildHeight, cellData.Size, rot, UnitType.OBSTACLE); } AddMapIndex(curXIndex, curZIndex, mapIndexList); totalBuildMapId[item] = buildHeight; } buildMapId.Clear(); isPress = false; for (int i = dummyParent.transform.childCount - 1; i >= 0; i--) { Object.Destroy(dummyParent.transform.GetChild(i).gameObject); } } }
public void GetMapConnections() { Connections = new List <MapConnection>(); var mapData = (JObject)(Loader.data.maps)[MapID]; foreach (var door in mapData["doors"]) { var values = door.Values().ToArray(); var connection = new MapConnection(); connection.isRoot = false; connection.MapName = MapID; connection.SpawnID = (int)values[6].ToObject(typeof(int)); connection.ConnectedSpawnID = (int)values[5].ToObject(typeof(int)); //if(connection.ConnectedSpawnID == 4 && connection.MapName == "level3") //{ // connection.ConnectedSpawnID = 2; //} connection.ConnectedMap = (string)values[4].ToObject(typeof(string)); var spawn = mapData["spawns"][connection.SpawnID]; connection.SpawnPoint = new PointStruct((int)spawn[0].ToObject(typeof(int)), (int)spawn[1].ToObject(typeof(int))); var connectedMapData = (JObject)(Loader.data.maps)[connection.ConnectedMap]; var connectedSpawn = connectedMapData["spawns"][connection.ConnectedSpawnID]; connection.ConnectedSpawnPoint = new PointStruct((int)connectedSpawn[0].ToObject(typeof(int)), (int)connectedSpawn[1].ToObject(typeof(int))); Connections.Add(connection); } var transportPlaces = (JObject)Loader.data.npcs.transporter.places; var transporterMaps = transportPlaces.Properties().Select(p => p.Name); if (transporterMaps.Contains(MapID)) { var transportSpawn = (int)transportPlaces[MapID].ToObject(typeof(int)); foreach (var otherMap in transporterMaps) { if (otherMap != MapID) { var otherSpawn = (int)transportPlaces[otherMap].ToObject(typeof(int)); var connection = new MapConnection(); connection.isRoot = false; connection.MapName = MapID; connection.SpawnID = transportSpawn; connection.ConnectedMap = otherMap; connection.ConnectedSpawnID = otherSpawn; var spawn = mapData["spawns"][connection.SpawnID]; connection.SpawnPoint = new PointStruct((int)spawn[0].ToObject(typeof(int)), (int)spawn[1].ToObject(typeof(int))); var connectedMapData = (JObject)(Loader.data.maps)[connection.ConnectedMap]; var connectedSpawn = connectedMapData["spawns"][connection.ConnectedSpawnID]; connection.ConnectedSpawnPoint = new PointStruct((int)connectedSpawn[0].ToObject(typeof(int)), (int)connectedSpawn[1].ToObject(typeof(int))); Connections.Add(connection); } } } }