/// <summary> /// When starting, load the game. /// </summary> private void Start() { if (loadOnStart && SaveSystem.HasSavedGameInSlot(saveSlotNumber)) { SaveSystem.LoadFromSlot(saveSlotNumber); } }
void OnGUI() { var originalSkin = GUI.skin; if (guiSkin != null) { GUI.skin = guiSkin; } // Draw instructions if within the timeframe to do so: if (Time.time < m_instructionsDoneTime) { GUILayout.Label(instructions); } // Draw menu if visible: if (!m_isVisible) { return; } var buttonWidth = buttonSize.x; var buttonHeight = buttonSize.y; GUILayout.BeginArea(new Rect((Screen.width - buttonWidth) / 2, (Screen.height - 4 * buttonHeight) / 2, buttonWidth, 4 * (buttonHeight + 10))); if (GUILayout.Button("Resume", GUILayout.Height(buttonHeight))) { ToggleMenu(); } if (GUILayout.Button("Save", GUILayout.Height(buttonHeight))) { ToggleMenu(); Debug.Log("Saving game to slot " + saveSlot); SaveSystem.SaveToSlot(saveSlot); } if (GUILayout.Button("Load", GUILayout.Height(buttonHeight))) { ToggleMenu(); Debug.Log("Loading game from slot " + saveSlot); SaveSystem.LoadFromSlot(saveSlot); } if (GUILayout.Button("Quit", GUILayout.Height(buttonHeight))) { ToggleMenu(); Debug.Log("Quitting"); Application.Quit(); #if UNITY_EDITOR UnityEditor.EditorApplication.isPlaying = false; #endif } GUILayout.EndArea(); if (guiSkin != null) { GUI.skin = originalSkin; } }
/// <summary> /// Load the specified slot, or restart the game from the default /// starting scene if no save exists yet. /// </summary> /// <param name="slotNumber">Slot number to load.</param> public void LoadOrRestart(int slotNumber) { if (SaveSystem.HasSavedGameInSlot(slotNumber)) { SaveSystem.LoadFromSlot(slotNumber); } else { SaveSystem.RestartGame(defaultStartingSceneName); } }
void OnGUI() { // Draw instructions if within the timeframe to do so: if (Time.time < instructionsDoneTime) { GUILayout.Label(instructions); } // Draw menu if visible: if (!m_isVisible) { return; } const int ButtonWidth = 200; const int ButtonHeight = 30; GUILayout.BeginArea(new Rect((Screen.width - ButtonWidth) / 2, (Screen.height - 4 * ButtonHeight) / 2, ButtonWidth, 4 * (ButtonHeight + 10))); if (GUILayout.Button("Resume", GUILayout.Height(ButtonHeight))) { ToggleMenu(); } if (GUILayout.Button("Save", GUILayout.Height(ButtonHeight))) { ToggleMenu(); Debug.Log("Saving game to slot " + saveSlot); SaveSystem.SaveToSlot(saveSlot); } if (GUILayout.Button("Load", GUILayout.Height(ButtonHeight))) { ToggleMenu(); Debug.Log("Loading game from slot " + saveSlot); SaveSystem.LoadFromSlot(saveSlot); } if (GUILayout.Button("Quit", GUILayout.Height(ButtonHeight))) { ToggleMenu(); Debug.Log("Quitting"); Application.Quit(); #if UNITY_EDITOR UnityEditor.EditorApplication.isPlaying = false; #endif } GUILayout.EndArea(); }
/// <summary> /// Loads the game previously-saved in the specified slot. /// </summary> /// <param name="slotNumber"></param> public void LoadFromSlot(int slotNumber) { SaveSystem.LoadFromSlot(slotNumber); }