From 6b790028782b56d17891fe9dc97f140aaeb89d86 Mon Sep 17 00:00:00 2001 From: Mark Suckerberg Date: Mon, 19 Apr 2021 09:50:45 -0500 Subject: [PATCH] Fixes save system and block selection dropdown --- Blocktest/Assets/Scenes/MainScene.unity | 24 +++++++++---------- .../Scripts/Block System/BlockManager.cs | 13 +++++++++- Blocktest/Assets/Scripts/SaveSystem.cs | 4 ++-- 3 files changed, 26 insertions(+), 15 deletions(-) diff --git a/Blocktest/Assets/Scenes/MainScene.unity b/Blocktest/Assets/Scenes/MainScene.unity index 70de8f7..6013b48 100644 --- a/Blocktest/Assets/Scenes/MainScene.unity +++ b/Blocktest/Assets/Scenes/MainScene.unity @@ -875,7 +875,7 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: m_Navigation: - m_Mode: 3 + m_Mode: 0 m_WrapAround: 0 m_SelectOnUp: {fileID: 0} m_SelectOnDown: {fileID: 0} @@ -906,10 +906,10 @@ MonoBehaviour: m_OnClick: m_PersistentCalls: m_Calls: - - m_Target: {fileID: 0} - m_TargetAssemblyTypeName: PlayerUI, Assembly-CSharp + - m_Target: {fileID: 1372863295} + m_TargetAssemblyTypeName: BlockManager, Assembly-CSharp m_MethodName: PlayerSaveLevel - m_Mode: 3 + m_Mode: 1 m_Arguments: m_ObjectArgument: {fileID: 0} m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine @@ -1537,7 +1537,7 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: m_Navigation: - m_Mode: 3 + m_Mode: 0 m_WrapAround: 0 m_SelectOnUp: {fileID: 0} m_SelectOnDown: {fileID: 0} @@ -1568,10 +1568,10 @@ MonoBehaviour: m_OnClick: m_PersistentCalls: m_Calls: - - m_Target: {fileID: 0} - m_TargetAssemblyTypeName: PlayerUI, Assembly-CSharp + - m_Target: {fileID: 1372863295} + m_TargetAssemblyTypeName: BlockManager, Assembly-CSharp m_MethodName: PlayerLoadLevel - m_Mode: 3 + m_Mode: 1 m_Arguments: m_ObjectArgument: {fileID: 0} m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine @@ -1749,7 +1749,7 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: m_Navigation: - m_Mode: 3 + m_Mode: 0 m_WrapAround: 0 m_SelectOnUp: {fileID: 0} m_SelectOnDown: {fileID: 0} @@ -2336,7 +2336,7 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: m_Navigation: - m_Mode: 3 + m_Mode: 0 m_WrapAround: 0 m_SelectOnUp: {fileID: 0} m_SelectOnDown: {fileID: 0} @@ -2375,8 +2375,8 @@ MonoBehaviour: m_OnValueChanged: m_PersistentCalls: m_Calls: - - m_Target: {fileID: 0} - m_TargetAssemblyTypeName: PlayerUI, Assembly-CSharp + - m_Target: {fileID: 1372863295} + m_TargetAssemblyTypeName: BlockManager, Assembly-CSharp m_MethodName: ChangeBlockSelection m_Mode: 0 m_Arguments: diff --git a/Blocktest/Assets/Scripts/Block System/BlockManager.cs b/Blocktest/Assets/Scripts/Block System/BlockManager.cs index d198223..187cc0b 100644 --- a/Blocktest/Assets/Scripts/Block System/BlockManager.cs +++ b/Blocktest/Assets/Scripts/Block System/BlockManager.cs @@ -23,7 +23,6 @@ public class BlockManager : MonoBehaviour [SerializeField] private Tilemap backgroundTilemap; [SerializeField] public GameObject defaultPlayerPrefab; - private void Awake() { // Add this to the global variable @@ -60,4 +59,16 @@ where assemblyType.IsSubclassOf(typeof(Block)) selectionDropdown.AddOptions(blockNames.ToList()); WorldGen.GenerateMainMap(); // TODO: Move this to some sort of global initialization method } + + // Code bandaid for saving + public void PlayerLoadLevel() { + SaveSystem.LoadGame(0); + } + + public void PlayerSaveLevel() { + SaveSystem.SaveGame(0); + } + + // disgusting + public void ChangeBlockSelection(int slot) => Globals.characterObject.GetComponent().ChangeBlockSelection(slot); } diff --git a/Blocktest/Assets/Scripts/SaveSystem.cs b/Blocktest/Assets/Scripts/SaveSystem.cs index 9f8f572..d7dc078 100644 --- a/Blocktest/Assets/Scripts/SaveSystem.cs +++ b/Blocktest/Assets/Scripts/SaveSystem.cs @@ -10,7 +10,7 @@ public static void SaveGame(int saveIndex) { string path = Application.persistentDataPath + "/savegame-" + saveIndex + ".bt"; FileStream stream = new FileStream(path, FileMode.Create); - Vector3 playerPos3 = GameObject.Find("Player").transform.position; + Vector3 playerPos3 = Globals.characterObject.transform.position; float[] playerPos = new float[3] {playerPos3.x, playerPos3.y, playerPos3.z}; SaveData save = new SaveData(playerPos, BuildSystem.currentWorld); @@ -47,7 +47,7 @@ public static void LoadGame(int saveIndex) { BuildSystem.PlaceIDsCells(blocksToPlaceFore, true, positions); BuildSystem.PlaceIDsCells(blocksToPlaceBack, false, positions); - GameObject.Find("Player").transform.position = new Vector3(data.playerPosition[0], data.playerPosition[1], data.playerPosition[2]); + Globals.characterObject.transform.position = new Vector3(data.playerPosition[0], data.playerPosition[1], data.playerPosition[2]); BuildSystem.currentWorld = data.worldData; } else