public void CreateNewBlock() { if (scene_data == null) { Init(); } if (newdata == null) { Debug.LogError("New data is null. Are you Roland? Aborting."); return; } //We must first find if there is already a world/level inside the file identified_block = FindBlockDataScene(scene_data, display_world, display_level); if (identified_block != null) { Debug.LogError("I found a world/level that is the same as the block I'm saving! Aborting save!"); } Array.Resize <block_data>(ref scene_data.data, scene_data.data.Length + 1); scene_data.data[scene_data.data.Length - 1] = newdata; if (BinaryData.SaveBinaryData(scene_data)) { Debug.Log("Successfully saved"); } else { Debug.Log("Something failed..."); } }
block_data LoadPlayerPrefScore(int world, int level) { block_data newScore = new block_data(); newScore.world = world; newScore.level = level; newScore.gold = PlayerPrefs.GetInt("GoldRank_" + world + "_" + level, 4); newScore.silver = PlayerPrefs.GetInt("SilverRank_" + world + "_" + level, 6); newScore.bronze = PlayerPrefs.GetInt("BronzeRank_" + world + "_" + level, 8); return(newScore); }
void LoadWorld() { if (scene_data == null) { Init(); } if (display_level == 0 || display_world == 0) { Debug.LogError("Please give a world/level to load!"); return; } identified_block = FindBlockDataScene(scene_data, display_world, display_level); if (identified_block == null) { Debug.LogError("Cannot find corresponding world/level"); } Current_Gold = identified_block.gold; Current_Silver = identified_block.silver; Current_Bronze = identified_block.bronze; }
//Don't use this at runtime. PLEASE. public void SaveScene(bool edit = false) { int world, level; if (!edit) { //If the scenes are the deprecated scenes we are using. if (EditorSceneManager.GetActiveScene().name.Contains("Level")) { //OLD METHOD Vector2 temp = updateinternalworldlevel(); world = (int)temp.x; level = (int)temp.y; } else { //this must be the new method, aka using the masterscene world = new_world; level = new_level; GameObject GameSystem = GameObject.FindGameObjectWithTag("GameController"); GameSystem.GetComponent <ScoreSystem>().World = world; GameSystem.GetComponent <ScoreSystem>().level = level; } } else { world = Current_World; level = Current_Level; GameObject GameSystem = GameObject.FindGameObjectWithTag("GameController"); GameSystem.GetComponent <ScoreSystem>().World = world; GameSystem.GetComponent <ScoreSystem>().level = level; SaveParentFolder = Application.streamingAssetsPath + "/Data"; } Scene_Block saveData = new Scene_Block(); //find all the blocks List <Transform> blks = new List <Transform>(); List <block_data> temp_blks = new List <block_data>(); Transform[] allobj = GameObject.FindObjectsOfType <Transform>(); foreach (Transform obj in allobj) { if (obj.gameObject.activeInHierarchy) { //we use game component snapobject to identify if its a block... if (obj.GetComponent <SnapObject>() != null || obj.CompareTag("PlacedWallBlock")) { if (obj.root != GameObject.Find("FakeScene").transform) { blks.Add(obj); } } } } //create and place each new block_data foreach (Transform blk in blks) { block_data data = new block_data(); data.pos = new custom_vector_4(blk.transform.position); data.scale = new custom_vector_4(blk.transform.localScale); data.type = ParseBlockType(blk.gameObject); //hardcore handle portals if (data.type == blockType.portal) { data.portal_ref_pos = new custom_vector_4(blk.GetComponent <Portal>().OtherPortal.transform.position); } if (blk.GetComponent <OneWayBlock>() != null) { data.direction = blk.GetComponent <OneWayBlock>().currentDirection; } else if (blk.GetComponent <OneWayGate>() != null) { data.direction = blk.GetComponent <OneWayGate>().currentDirection; } temp_blks.Add(data); } saveData.blocks = temp_blks.ToArray(); saveData.world = world; saveData.level = level; //now we actually save the data. if (BinarySerializor.SerializeToBinary <Scene_Block>(SaveParentFolder + "/" + world + "-" + level + ".dat", saveData)) { Debug.Log("Successfully saved"); } }