73 lines
2.4 KiB
C#
73 lines
2.4 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using UnityEngine.SceneManagement;
|
|
using System.Runtime.Serialization.Formatters.Binary;
|
|
using System;
|
|
using System.IO;
|
|
|
|
public class LoaderScreen : MonoBehaviour
|
|
{
|
|
// Start is called before the first frame update
|
|
public InputField id;
|
|
public Button start;
|
|
|
|
void Start()
|
|
{
|
|
start.gameObject.SetActive(false);
|
|
}
|
|
|
|
public void OnEditEnded() {
|
|
//check if user is there///
|
|
///if not, create new user entry///
|
|
//Gamestate.Instance.createPlayerData();
|
|
Debug.Log("endEdit... " + id.text);
|
|
Gamestate.Instance.setID(id.text);
|
|
|
|
/*if (!loadPlayerData())
|
|
{
|
|
Debug.Log("File with ID: " + Application.persistentDataPath+ "/playerInfo"+Gamestate.Instance.GetPlayerData().ID + ".dat created...");
|
|
}*/
|
|
|
|
start.gameObject.SetActive(true);
|
|
//PlayerPrefs.SetString("ID",id.text);
|
|
//if user created activate button
|
|
|
|
}
|
|
|
|
public void startGameSelect() {
|
|
//if (!Gamestate.Instance.GetPlayerData().loadPlayerInfo())
|
|
// Gamestate.Instance.GetPlayerData().savePlayerInfo();
|
|
DontDestroyOnLoad(Gamestate.Instance);
|
|
Gamestate.Instance.menuState();
|
|
}
|
|
|
|
public bool loadPlayerData() {
|
|
if (id.text != "99") {
|
|
if (File.Exists(Application.persistentDataPath+"/playerData"+Gamestate.Instance.GetPlayerData().ID+".dat")) {
|
|
BinaryFormatter bf = new BinaryFormatter();
|
|
FileStream file = File.Open(Application.persistentDataPath+"/playerData"+Gamestate.Instance.GetPlayerData().ID+".dat", FileMode.Open);
|
|
Gamestate.PlayerData pd = (Gamestate.PlayerData)bf.Deserialize(file);
|
|
Gamestate.Instance.setPlayerData(pd);
|
|
file.Close();
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
File.Create(Application.persistentDataPath+"/playerData"+Gamestate.Instance.GetPlayerData().ID+".dat");
|
|
return false;
|
|
}
|
|
|
|
} else {
|
|
if (!File.Exists(Application.persistentDataPath+"/playerData"+Gamestate.Instance.GetPlayerData().ID+".dat")) {
|
|
File.Create(Application.persistentDataPath+"/playerData"+Gamestate.Instance.GetPlayerData().ID+".dat");
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
}
|
|
|
|
}
|