Open-sourced some code

This commit is contained in:
2019-03-08 09:54:14 +11:00
commit 645272872c
142 changed files with 3028 additions and 0 deletions
@@ -0,0 +1,40 @@
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using UnityEngine.UI;
namespace MenuSystem {
public class LoadCanvas : MonoBehaviour {
//public access members
public GameObject saveSlotPrefab;
public GameObject confirmationCanvas;
void OnEnable() {
//load the save objects
DirectoryInfo info = new DirectoryInfo(Application.persistentDataPath);
//create the load menu
foreach(var file in info.GetFiles("*.sav")) {
GameObject saveSlot = Instantiate(saveSlotPrefab) as GameObject;
saveSlot.transform.SetParent(transform); //BUGFIX: unity bug
saveSlot.GetComponent<SaveSlot>().SetSaveSlotInfo(SaveFileManager.LoadData(file.FullName));
saveSlot.GetComponent<SaveSlot>().fileName = file.FullName;
saveSlot.GetComponent<SaveSlot>().loadCanvas = transform.gameObject;
saveSlot.GetComponent<SaveSlot>().confirmationCanvas = confirmationCanvas;
}
//Move the "back" option to the bottom
transform.GetChild(0).SetAsLastSibling();
}
void OnDisable() {
foreach (Transform child in transform) {
if (child.GetComponent<SaveSlot>() != null) {
GameObject.Destroy(child.gameObject);
}
}
}
}
}
@@ -0,0 +1,50 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
namespace MenuSystem {
public class SaveSlot : MenuOption {
public string fileName;
public GameObject loadCanvas;
public GameObject confirmationCanvas;
//private access members
SaveFileManager.SaveSlot saveData;
public void SetSaveSlotInfo(SaveFileManager.SaveSlot saveSlot) {
TextMeshProUGUI[] texts = GetComponentsInChildren<TextMeshProUGUI>(true);
texts[0].text = saveSlot.currentLocation;
TimeSpan time = TimeSpan.FromSeconds(saveSlot.secondsPlaying);
texts[1].text = time.ToString(@"hh\:mm\:ss");
saveData = saveSlot;
}
public override void Execute() {
//show a confirmation canvas
confirmationCanvas.transform.GetChild(0).GetComponent<ConfirmLoad>().saveData = saveData;
confirmationCanvas.transform.GetChild(0).GetComponent<ConfirmLoad>().fileName = fileName;
confirmationCanvas.transform.GetChild(1).GetComponent<ConfirmDelete>().fileName = fileName;
//BUGFIX: move the cursor somewhere safe
transform.Find("Cursor").SetParent(confirmationCanvas.transform.GetChild(0));
//BUGFIX: wait a frame to show the confirmation page, to make sure the cursor is safe
StartCoroutine(DoStuffNextFrame());
}
IEnumerator DoStuffNextFrame() {
yield return null;
loadCanvas.SetActive(false);
confirmationCanvas.SetActive(true);
}
public override void Scroll(float x) {
//DO NOTHING
}
}
}