public void EditLevel() { PuzzleLoader pl = Instantiate(puzzleLoader).GetComponent <PuzzleLoader>(); pl.loadMode = LevelManager.LevelMode.Editor; pl.levelToLoad = BinarySaveSystem.LoadFile <Level>(Path.Combine(Application.persistentDataPath, "Levels", lastLevelShown.id)); }
private void Awake() { if (BSSInstanse == null) { BSSInstanse = this; } }
static public void SaveLevel(Level level) { if (!Directory.Exists(Path.Combine(Application.persistentDataPath, "Levels"))) { Directory.CreateDirectory(Path.Combine(Application.persistentDataPath, "Levels")); } if (level.id == -1) { int id = Random.Range(0, 1000000); string[] paths = Directory.GetFiles(Path.Combine(Application.persistentDataPath, "Levels")); List <string> ids = new List <string>(); for (int i = 0; i < paths.Length; ++i) { ids.Add(Path.GetFileName(paths[i])); } while (!CheckIds(ids, id)) { id = Random.Range(0, 1000000); } level.id = id; } BinarySaveSystem.SaveFile(Path.Combine(Application.persistentDataPath, "Levels", level.id.ToString()), level); LevelManager.instance.ShowSaveLevelMenu(false); LevelManager.instance.ShowSuccessMenu(); }
private void Awake() { instance = this; if (File.Exists(Path.Combine(Application.persistentDataPath, "Data", "playerAccount.data"))) { username = BinarySaveSystem.LoadFile <AccountFile>(Path.Combine(Application.persistentDataPath, "Data", "playerAccount.data")).Username; } }
static public Level LoadLevel(string levelName) { string path = Path.Combine(Application.persistentDataPath, "Levels", levelName); if (File.Exists(path)) { return(BinarySaveSystem.LoadFile <Level>(path)); } return(null); }
public void PlayLevel() { switch (lastLevelShown.type) { case LevelInfo.LevelType.Online: DataTransferer.instance.DownloadLevel(lastLevelShown.id); break; case LevelInfo.LevelType.Local: PuzzleLoader pl = Instantiate(puzzleLoader).GetComponent <PuzzleLoader>(); pl.loadMode = LevelManager.LevelMode.Play; pl.levelToLoad = BinarySaveSystem.LoadFile <Level>(Path.Combine(Application.persistentDataPath, "Levels", lastLevelShown.id)); break; } }
IEnumerator StartUploadingLevel(Level level, int id) { WWWForm w = new WWWForm(); w.AddField("id", id); w.AddField("levelName", level.name); w.AddField("levelDescription", level.description); w.AddField("likes", 0); w.AddField("creatorName", level.creatorName); w.AddField("levelSize", level.size); using (UnityWebRequest www = UnityWebRequest.Post(serverURL + "AddPuzzle.php", w)) { yield return(www.SendWebRequest()); if (www.error != null) { Debug.Log("404 not found"); yield break; } else if (www.downloadHandler.text.Contains("Error")) { Debug.Log(www.downloadHandler.text); yield break; } } WWWForm form = new WWWForm(); form.AddBinaryData("myfile", BinarySaveSystem.ObjectToByteArray(level), id.ToString(), "text/plain"); UnityWebRequest wL = UnityWebRequest.Post(serverURL + "index.php", form); yield return(wL.SendWebRequest()); LevelManager.instance.ShowPublishLevelMenu(false); if (wL.error != null) { LevelManager.instance.ShowSuccessMenu(wL.error); } else { LevelManager.instance.ShowSuccessMenu(); } wL.Dispose(); }
// Start is called before the first frame update void Start() { if (File.Exists(accountDataPath)) { accountFile = BinarySaveSystem.LoadFile <AccountFile>(accountDataPath); if (!firstTime) { ChangeMenu(Menu_States.Selector); return; } ChangeMenu(Menu_States.ACCOUNTDETECTED); return; } ChangeMenu(current_state); }
IEnumerator StartDownloadLevel(string id) { string url = serverURL + "levels/" + id; UnityWebRequest w = UnityWebRequest.Get(url); yield return(w.SendWebRequest()); if (w.error != null) { Debug.Log("Error: " + w.error); } else { PuzzleLoader puzzleLoader = Instantiate(PuzzleSelectorManager.instance.puzzleLoader).GetComponent <PuzzleLoader>(); puzzleLoader.loadMode = LevelManager.LevelMode.Play; puzzleLoader.levelToLoad = (Level)BinarySaveSystem.ByteArrayToObject(w.downloadHandler.data); } w.Dispose(); }
/// <summary> /// 今回のプレイ情報をセーブする /// </summary> public void SaveGameData() { //前のプレイ段階の情報を取得する RankingData prevRanking = BinarySaveSystem.Load <RankingData>(kSaveFileName[PlayedMode]); //今回のプレイのスコアを追加する var list = prevRanking.playerDatas.ToList(); list.Add(new GameData(Score)); //上から既定の人数になるようにリストを作る //降順にソートし、 最後の要素を削除することで実現する list.Sort((a, b) => b.score - a.score); list.RemoveAt(list.Count - 1); //新しくなったランキングデータを保存する RankingData currentRanking = new RankingData(list.ToArray()); BinarySaveSystem.Save(currentRanking, kSaveFileName[PlayedMode]); }
public void LoadSavedLevels() { string path = Path.Combine(Application.persistentDataPath, "Levels"); if (!Directory.Exists(path)) { return; } var levels = Directory.GetFiles(path); for (int i = 0; i < levels.Length; ++i) { if (Path.GetExtension(levels[i]) == ".data") { continue; } LevelInfo levelInfo = new LevelInfo(LevelInfo.LevelType.Local); LevelSummary ls = Instantiate(levelSummary, communityLocal.transform).GetComponent <LevelSummary>(); levelInfo.levelSummary = ls; Level level = BinarySaveSystem.LoadFile <Level>(levels[i]); levelInfo.id = Path.GetFileName(levels[i]); levelInfo.levelname = level.name; levelInfo.size = level.size; levelInfo.username = level.creatorName; levelInfo.description = level.description; ls.ApplyInfo(levelInfo); } communityLocal.padding.right = levels.Length > 12 ? 60 : 15; scrollbarLocal.enabled = levels.Length > 12; Invoke(nameof(SetLocalLevelsSize), 0.1f); }
/// <summary> /// modeに対応したセーブされているランキング情報を取得する /// </summary> /// <param name="mode"></param> /// <returns></returns> public RankingData GetSavedRankingData(PlayMode mode) { RankingData res = BinarySaveSystem.Load <RankingData>(kSaveFileName[mode]); return(res); }
void SaveAccountFile(string username, string password) { BinarySaveSystem.SaveFile(accountDataPath, new AccountFile(username, password)); }