public EditorTileData GenerateData() { EditorTileData data = new EditorTileData(); data.mapXPos = transform.localPosition.x; data.mapYPos = transform.localPosition.y; data.assetCode = assetCode; data.angle = transform.localEulerAngles.z; return(data); }
public EditorMapData(Dictionary <string, object> rawData) { mapName = JsonUtility.GetString(rawData, TAG_NAME); width = JsonUtility.GetInt(rawData, TAG_WIDTH); height = JsonUtility.GetInt(rawData, TAG_HEIGHT); //Load tiles from given dictionary listTile = new List <EditorTileData>(); if (rawData.ContainsKey(TAG_TILES)) { var tiles = rawData[TAG_TILES] as List <object>; for (int i = 0; i < tiles.Count; i++) { var rawTile = tiles[i] as Dictionary <string, object>; EditorTileData tileData = new EditorTileData(rawTile); listTile.Add(tileData); } } //Load map features from given dictionary listFeature = new List <EditorMapFeatureData>(); if (rawData.ContainsKey(TAG_FEATURE)) { var features = rawData[TAG_FEATURE] as List <object>; for (int i = 0; i < features.Count; i++) { var rawFeature = features[i] as Dictionary <string, object>; EditorMapFeatureData featureData = new EditorMapFeatureData(rawFeature); listFeature.Add(featureData); } } //Load saved spawner data listSpawner = new List <EditorSpawnerData>(); if (rawData.ContainsKey(TAG_SPAWNER)) { var spawners = rawData[TAG_SPAWNER] as List <object>; for (int i = 0; i < spawners.Count; i++) { var rawSpanwer = spawners[i] as Dictionary <string, object>; EditorSpawnerData spawnerData = new EditorSpawnerData(rawSpanwer); listSpawner.Add(spawnerData); } } }
public void GenerateTile(List <EditorTileData> listTile) { for (int i = 0; i < listTile.Count; i++) { EditorTileData referenceData = listTile[i]; Object prefab = AssetManager.Instance.GetPrefabByKeyword(referenceData.assetCode); GameObject go = Instantiate(prefab) as GameObject; go.transform.SetParent(gridParent); go.transform.localScale = Vector3.one; go.transform.localPosition = new Vector3(referenceData.mapXPos, referenceData.mapYPos, 0); go.transform.localEulerAngles = new Vector3(0, 0, referenceData.angle); bool isEditable = true; //Make so the border and corner can not be edited if (referenceData.assetCode.Equals(MapEditorUtility.DEFAULT_TILE_BORDER) || referenceData.assetCode.Equals(MapEditorUtility.DEFAULT_TILE_CORNER)) { isEditable = false; } //If this is not the corner or border asset attach script so the gameobject can be edited go.AddComponent <MapEditorTileController>().Init(referenceData.assetCode, isEditable); } }
public static EditorMapData CreateDefaultMap(MapEditorSaveData data) { EditorMapData basicMap = new EditorMapData(); basicMap.mapName = data.mapName; basicMap.width = data.width; basicMap.height = data.height; //Create the default width x height tile with 0 angle //Also create it with the default asset for empty tile for (int x = 0; x < data.width; x++) { for (int y = 0; y < data.height; y++) { EditorTileData tileData = new EditorTileData(); tileData.angle = 0; tileData.assetCode = DEFAULT_TILE; //HARDCODED This is empty tile tileData.mapXPos = x + TILE_RADIUS; tileData.mapYPos = y + TILE_RADIUS; basicMap.listTile.Add(tileData); } } //Create the border for maps //Create TOP Border for (int x = 0; x < data.width; x++) { EditorTileData tileData = new EditorTileData(); tileData.angle = 0; tileData.assetCode = DEFAULT_TILE_BORDER; tileData.mapXPos = x + TILE_RADIUS; tileData.mapYPos = data.height + TILE_RADIUS; basicMap.listTile.Add(tileData); } //Create Bottom Border for (int x = 0; x < data.width; x++) { EditorTileData tileData = new EditorTileData(); tileData.angle = 180; tileData.assetCode = DEFAULT_TILE_BORDER; tileData.mapXPos = x + TILE_RADIUS; tileData.mapYPos = -TILE_RADIUS; basicMap.listTile.Add(tileData); } //Create Left Border for (int y = 0; y < data.height; y++) { EditorTileData tileData = new EditorTileData(); tileData.angle = 90; tileData.assetCode = DEFAULT_TILE_BORDER; tileData.mapXPos = -TILE_RADIUS; tileData.mapYPos = y + TILE_RADIUS; basicMap.listTile.Add(tileData); } //Create Right Border for (int y = 0; y < data.height; y++) { EditorTileData tileData = new EditorTileData(); tileData.angle = 270; tileData.assetCode = DEFAULT_TILE_BORDER; tileData.mapXPos = data.width + TILE_RADIUS; tileData.mapYPos = y + TILE_RADIUS; basicMap.listTile.Add(tileData); } //Create corner border for the map for (int x = 0; x < 2; x++) { for (int y = 0; y < 2; y++) { EditorTileData tileData = new EditorTileData(); tileData.assetCode = DEFAULT_TILE_CORNER; if (x == 0 && y == 0) //LEFT BOTTOM CORNER { tileData.angle = 90; tileData.mapXPos = -TILE_RADIUS; tileData.mapYPos = -TILE_RADIUS; } else if (x == 0 && y == 1) //LEFT TOP CORNER { tileData.angle = 0; tileData.mapXPos = -TILE_RADIUS; tileData.mapYPos = data.height + TILE_RADIUS; } else if (x == 1 && y == 0) //RIGHT BOTTOM CORNER { tileData.angle = 180; tileData.mapXPos = data.width + TILE_RADIUS; tileData.mapYPos = -TILE_RADIUS; } else { tileData.angle = 270; //RIGHT TOP CORNER tileData.mapXPos = data.width + TILE_RADIUS; tileData.mapYPos = data.height + TILE_RADIUS; } basicMap.listTile.Add(tileData); } } //Basic map doesn't have map feature nor spawners return(basicMap); }
IEnumerator GenerateMapTilesAndFeature() { if (!isTileLoaded) { //TODO Load map given by data here string mapName = "simple_map"; TextAsset textAsset = Resources.Load("Text/" + mapName) as TextAsset; string jsonText = textAsset.text; var jsonData = ProjectMiniJSON.Json.Deserialize(jsonText) as Dictionary <string, object>; FlooMapEditor.EditorMapData mapData = new FlooMapEditor.EditorMapData(jsonData); UIGameController.Instance.ShowNotificationMessage(LanguageManager.Instance.GetMessage("LOA0009")); yield return(new WaitForSeconds(0.1f)); //Load all tiles here for (int i = 0; i < mapData.listTile.Count; i++) { FlooMapEditor.EditorTileData tileData = mapData.listTile[i]; Object prefab = AssetManager.Instance.GetPrefabByKeyword(tileData.assetCode); GameObject go = Instantiate(prefab) as GameObject; go.transform.SetParent(parentTile); go.transform.localPosition = new Vector3(tileData.mapXPos, tileData.mapYPos, 0); go.transform.localEulerAngles = new Vector3(0, 0, tileData.angle); go.transform.localScale = Vector3.one; } UIGameController.Instance.ShowNotificationMessage(LanguageManager.Instance.GetMessage("LOA0010")); yield return(new WaitForSeconds(0.1f)); //Load all map features here for (int i = 0; i < mapData.listFeature.Count; i++) { FlooMapEditor.EditorMapFeatureData mapFeature = mapData.listFeature[i]; GameObject go = MapFeatureObjectPooling.Instance.GetGameObject(mapFeature.assetCode); if (mapFeature.mapFeatureType == (int)FlooMapEditor.MapFeatureTypeEditor.HidingPlace) { LayerController.Instance.SetSeaweedLayer(go); } else { LayerController.Instance.SetObstacleLayer(go); } go.transform.localPosition = new Vector3(mapFeature.mapXPos, mapFeature.mapYPos, 0); go.transform.localEulerAngles = new Vector3(0, 0, mapFeature.angle); go.transform.localScale = new Vector3(mapFeature.radius * 2, mapFeature.radius * 2, 1.0f); HidingPlaceClusterManager hidingCluster = go.GetComponent <HidingPlaceClusterManager>(); if (hidingCluster != null) { //Stabilize the hiding cluster hidingCluster.StabilizeHidingPlaces(); hidingCluster.Init(true); } } UIGameController.Instance.ShowNotificationMessage(LanguageManager.Instance.GetMessage("LOA0011")); yield return(new WaitForSeconds(0.1f)); //Place water ripple here for (float x = -1.0f; x < mapData.width + 1.0f; x += rippleSize) { for (float y = -1.0f; y < mapData.height + 1.0f; y += rippleSize) { GameObject rippleObj = Instantiate(waterRipplePrefab) as GameObject; rippleObj.transform.SetParent(parentWaterRipple); rippleObj.transform.localPosition = new Vector3(x, y, 0); rippleObj.transform.localScale = new Vector3(rippleSize, rippleSize, 1.0f); } } OcculsionManager.Instance.DisableAllMapFeature(); isTileLoaded = true; } DisplayGameController.Instance.StartObjectPooling(); yield return(true); }