private static TiledSharp.Map Load(LevelDef def) { var path = "Level/episode" + def.World.ToNumber() + "/" + def.Level.ToNumber(); if (def.Difficulty == Difficulty.Easy) { path += "e"; } var tmxContent = Resources.Load <TextAsset>(path); if (tmxContent == null) { Debug.LogError("map is not exists: " + path); return(null); } var tmxReader = new StringReader(tmxContent.text); var tmx = new TiledSharp.Map(tmxReader, pathToLoad => { Debug.Log(pathToLoad); return(null); }); return(tmx); }
public static Map Generate(TiledSharp.Map map) { var go = new GameObject(); go.name = "Level"; var ret = go.AddComponent <Map>(); ret.Load(map); return(ret); }
private static TiledSharp.Map Load(LevelDef def) { var path = "Level/episode" + def.World.ToNumber() + "/" + def.Level.ToNumber(); if (def.Difficulty == Difficulty.Easy) path += "e"; var tmxContent = Resources.Load<TextAsset>(path); if (tmxContent == null) { Debug.LogError("map is not exists: " + path); return null; } var tmxReader = new StringReader(tmxContent.text); var tmx = new TiledSharp.Map(tmxReader, pathToLoad => { Debug.Log(pathToLoad); return null; }); return tmx; }
public void Load(TiledSharp.Map map) { foreach (var tile in map.Layers[0].Tiles) { var coor = new Coor(tile.X, MapHeight - tile.Y); GameObject go = null; switch (tile.Gid) { case StartGid: StartPoisition = coor; break; case StarGid: { var star = MapFactory.InstantiateStar(coor); Stars.Add(star); go = star.gameObject; break; } default: { var gid = MapHelper.MapGidToBlockType(tile.Gid); if (gid.HasValue) { var block = MapFactory.Instantiate(gid.Value, coor); go = block.gameObject; } break; } } if (go != null) { go.transform.SetParent(transform, false); } } }