SchoolFightingSimple/Assets/Scripts/SavedCharecterDisplay.cs

46 lines
1.1 KiB
C#
Raw Permalink Normal View History

using System.IO;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System.Threading.Tasks;
using TMPro;
public class SavedCharecterDisplay : MonoBehaviour
{
public Button[] Buttons;
public GameObject Disable, Enable;
private void Start()
{
for (int i = 0; i < Buttons.Length; i++)
{
if (!hasSaved(i))
{
var textComp = Buttons[i].GetComponentInChildren<TMP_Text>();
textComp.text = "Create new!";
JsonManager.SelectedSave = i;
Buttons[i].onClick.AddListener(() => { Disable.SetActive(false); Enable.SetActive(true); });
}
else
{
JsonManager.SelectedSave = i;
Buttons[i].onClick.AddListener(() => { AppManager.LoadScene(1); });
}
}
}
bool hasSaved(int index)
{
string basePath = JsonManager.JsonDir;
if (!Directory.Exists(basePath)) return false;
if (!File.Exists(Path.Combine(basePath, $"Save_{index}.json"))) return false;
return true;
}
}