/// <summary> Process a TILE line from the level.txt and add it to the tile dictionary. </summary> // TILE ColourR,G,B,A TileVariant static void AddTileToLookup(string[] args) { Color32 colour = ParseColour(args[1]); TileVariant tile = Resources.Load <TileVariant>("Tiles/" + ParseString(args[2])); if (tile == null) { Debug.LogWarning("Could not find TileVariant " + ParseString(args[2]) + "!"); return; } colourBehaviours.Add(new KeyValuePair <Color32, IMapComponent>(colour, tile)); }
public Tile(TileVariant tileVariant) { variant = tileVariant; }
private void GenerateLevel(LevelModel[] levels) { TileCache = GenerateTileCache(levels.FirstOrDefault().floorLayer); VirtualEntityCache = GenerateEntityCache(levels.FirstOrDefault().entityLayer); if (MapRoot == null) { MapRoot = transform; } Debug.Log("Generating map and entities..."); TileCache.ForEach(tile => { // TODO: Initially add a type of decor for the asset to use on its decor slot. This will just instantiate over the top of the // wall (or floor). I was going to be cleverer about this but frankly for now it'll be fine as is. // Map editor will require a new update and type attached. TileVariant v = TileVariantMap.FirstOrDefault(x => x.scoreIndex == tile.score); if (v.prefab != null) { GameObject prefabType = tile.type == MAP_CELL_TYPE.BLOCKED ? v.prefab : v.floorPrefab; Vector3 ScaledPosition = new Vector3( tile.x, transform.position.y, tile.y ); var inst = Instantiate(prefabType, ScaledPosition, Quaternion.identity); inst.transform.SetParent(MapRoot); // For Debug inst.name = "TS: " + v.scoreIndex + " [x" + tile.x + "]:[y" + tile.y + "]"; } }); VirtualEntityCache.ForEach(entity => { EntityVariant v = EntityVariantMap.FirstOrDefault(x => x.type == entity.type); if (v != null && v.prefab != null) { Vector3 ScaledPosition = new Vector3( entity.x, // TODO: I don't understand why these must be flipped... research needed transform.position.y, // Temporary until I fix the prefabs entity.y ); // This provides a link between the actual prefab in the game world and how it's interpreted // when the player hits in within map data (such as passage checking). var inst = Instantiate(v.prefab, ScaledPosition, Quaternion.identity); inst.transform.SetParent(MapRoot); InstantiatedEntityCache.Add(inst); } }); if (OnMapGenerated != null) { OnMapGenerated(new MapResult() { StartPoint = VirtualEntityCache.FirstOrDefault(x => x.type == ENTITY_TYPE.START_POINT), EndPoint = VirtualEntityCache.FirstOrDefault(x => x.type == ENTITY_TYPE.END_POINT), InstanceCache = InstantiatedEntityCache }); } }
public void SetTileAt(int x, int y, TileVariant variant) { int position = y * Width + x; _tileArray[position] = variant.ToSoLTileDataSuperID(); }