public void Setup(World.Info world) { this.world = world; nameText.text = world.name; lastPlayText.text = string.Format("{0} days", (System.DateTime.Today - world.lastPlayed).Days); }
private void Awake() { hostButton.onClick.AddListener(OnClickedHost); worlds = new MonoBehaviourPooler<World.Info, SavedWorldPanel>(worldPrefab, worldParent, InitialiseWorld); generateToggle.onValueChanged.AddListener(active => { if (active) selectedWorld = null; }); }
public void SetWorld(World.Info world) { nameInput.text = world.name; selectedWorld = world; }
public void HostGame(string name, string password) { world = new World(); info = new World.Info { version = version, lastPlayed = System.DateTime.Now, name = name, root = string.Format("{0}-{1}", name, System.DateTime.Now.Ticks), }; for (int i = 0; i < 1024; ++i) world.tilemap[i] = (byte) Random.Range(0, 23); for (int i = 0; i < 256; ++i) { if (Random.value > 0.5f) world.walls.Add((byte)i); } world.tileset.SetPixels32(testtex.GetPixels32()); world.RandomisePalette(); world.PalettiseTexture(world.tileset); SetWorld(world); var create = new CreateMatchRequest(); create.name = name; create.size = 8; create.advertise = true; create.password = password; create.name += "!" + (int)version + "?0"; testLAN.broadcastData = create.name; match.CreateMatch(create, OnMatchCreate); testLAN.StopBroadcast(); testLAN.StartAsServer(); }
private void SaveWorld(string path, string name=null) { var root = Application.persistentDataPath; var dir = root + "/worlds/" + path; var info = new World.Info { version = version, name = name ?? path, root = path, lastPlayed = System.DateTime.Now, }; Directory.CreateDirectory(dir); File.WriteAllBytes(dir + "/tileset.png", world.tileset.EncodeToPNG()); File.WriteAllText(dir + "/world.json", JsonWrapper.Serialise(world)); File.WriteAllText(dir + "/info.json", JsonWrapper.Serialise(info)); }
public static IEnumerable<World.Info> GetSavedWorlds() { var worlds = Application.persistentDataPath + "/worlds"; Directory.CreateDirectory(worlds); foreach (var folder in Directory.GetDirectories(worlds)) { string root = Path.GetFileName(folder); World.Info info = null; try { info = JsonWrapper.Deserialise<World.Info>(File.ReadAllText(folder + "/info.json")); info.root = root; } catch (System.Exception exception) { Debug.LogWarningFormat("Couldn't read world info for {0}\n{1}", root, exception); } if (info != null) yield return info; } }