username handler, timer
This commit is contained in:
@@ -42,17 +42,17 @@ public class CoinCounter : MonoBehaviour
|
||||
coin += number;
|
||||
coinCounterUI.text = "Coins: " + coin.ToString();
|
||||
|
||||
writer = new StreamWriter(path, false, Encoding.Default);
|
||||
/*writer = new StreamWriter(path, false, Encoding.Default);
|
||||
writer.Write(coin);
|
||||
writer.Close();
|
||||
writer.Close();*/
|
||||
}
|
||||
|
||||
public void RemoveCoin(ulong number){
|
||||
coin -= number;
|
||||
//coinCounterUI.text = "Coins: " + coin.ToString();
|
||||
|
||||
writer = new StreamWriter(path, false, Encoding.Default);
|
||||
/*writer = new StreamWriter(path, false, Encoding.Default);
|
||||
writer.Write(coin);
|
||||
writer.Close();
|
||||
writer.Close();*/
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,12 +5,12 @@ using UnityEngine;
|
||||
public class DestroyObjects : MonoBehaviour
|
||||
{
|
||||
private void OnTriggerEnter(Collider other) {
|
||||
Debug.Log("destroy wall trigger");
|
||||
//Debug.Log("destroy wall trigger");
|
||||
Destroy(other.gameObject);
|
||||
}
|
||||
|
||||
private void OnCollisionEnter(Collision other) {
|
||||
Debug.Log("collision enter");
|
||||
//Debug.Log("collision enter");
|
||||
Destroy(other.gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@ using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using TMPro;
|
||||
using UnityEngine.Networking;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
public class DatabaseData : MonoBehaviour
|
||||
{
|
||||
@@ -10,25 +12,29 @@ public class DatabaseData : MonoBehaviour
|
||||
public PlayerList players; //jatekos adatok
|
||||
public HighScoreTableDataContainer htdc; //itt van a tomb
|
||||
public HighScoreTable hst; //high score table ui
|
||||
|
||||
private StreamWriter writer;
|
||||
public string jsondata; //json szoveg
|
||||
|
||||
private CoinCounter coinc;
|
||||
|
||||
private ulong coins = 0;
|
||||
public ulong coins = 0;
|
||||
|
||||
private void Awake() {
|
||||
hst = FindObjectOfType<HighScoreTable>(); //High Score Table referencia
|
||||
htdc = new HighScoreTableDataContainer(); //High Score Table Container objektum
|
||||
players = new PlayerList(); //jatekos lista osztaly
|
||||
|
||||
coinc = FindObjectOfType<CoinCounter>();
|
||||
//writer = new StreamWriter(Application.persistentDataPath + "/coins.txt", false, Encoding.Default);
|
||||
}
|
||||
|
||||
private void Start() {
|
||||
//GetHighScoreData(2);
|
||||
//GetHighScoreData();
|
||||
//StartCoroutine(GetCoinData(1));
|
||||
}
|
||||
|
||||
public void jsonParser(string jsondata) { //beerkezo json adat eltarolasa
|
||||
players = new PlayerList(); //jatekos lista osztaly
|
||||
players = JsonUtility.FromJson<PlayerList>("{\"player\":" + jsondata + "}");
|
||||
}
|
||||
|
||||
@@ -36,16 +42,23 @@ public class DatabaseData : MonoBehaviour
|
||||
htdc = JsonUtility.FromJson<HighScoreTableDataContainer>("{\"htd\":" + jsondata + "}");
|
||||
}
|
||||
|
||||
public void jsonParserCoin(string jsondata){
|
||||
coins = ulong.Parse(jsondata.Substring(14,2));
|
||||
Debug.Log(jsondata.Substring(14,2));
|
||||
public void ParserCoin(string jsondata){
|
||||
string data = "";
|
||||
for (int i = 0; i < jsondata.Length; i++)
|
||||
{
|
||||
if(jsondata[i] == '0' || jsondata[i] == '1' || jsondata[i] == '2' || jsondata[i] == '3' || jsondata[i] == '4' || jsondata[i] == '5' || jsondata[i] == '6' || jsondata[i] == '7' || jsondata[i] == '8' || jsondata[i] == '9'){
|
||||
data += jsondata[i]; //kiszedi a szamokat a stringbol
|
||||
}
|
||||
}
|
||||
Debug.Log(data);
|
||||
coins = ulong.Parse(data);
|
||||
}
|
||||
|
||||
//fuggvenyek amik meghivjak a rutint
|
||||
public void GetPlayerData() => StartCoroutine(IGetPlayerData());
|
||||
public void GetHighScoreData(int palya_id) => StartCoroutine(IGetHighScoreData(palya_id));
|
||||
public void GetHighScoreData() => StartCoroutine(IGetHighScoreData());
|
||||
public void PostNewPlayerData() => StartCoroutine(IPostNewPlayerData());
|
||||
public void PostNewScoreData() => StartCoroutine(IPostNewScoreData());
|
||||
public void PostNewScoreData(int playerid, ulong score, string time) => StartCoroutine(IPostNewScoreData(playerid, score, time));
|
||||
public void PostNewPalyaData() => StartCoroutine(IPostNewPalyaData());
|
||||
|
||||
public ulong GetCoins(int userid){
|
||||
@@ -70,7 +83,7 @@ public class DatabaseData : MonoBehaviour
|
||||
} else {
|
||||
jsondata = uwr.downloadHandler.text; //json szoveg eltarolasa
|
||||
Debug.Log(jsondata);
|
||||
jsonParserCoin(jsondata);
|
||||
ParserCoin(jsondata);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,12 +141,12 @@ public class DatabaseData : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerator IGetHighScoreData(int palya_id){
|
||||
private IEnumerator IGetHighScoreData(){
|
||||
string uri = "http://localhost:3000/toplist";
|
||||
|
||||
var uwr = new UnityWebRequest(uri, "POST");
|
||||
byte[] jsonToSend = new System.Text.UTF8Encoding().GetBytes("{\"bevitel1\":"+palya_id+"}"); //palya id megadasa
|
||||
uwr.uploadHandler = (UploadHandler)new UploadHandlerRaw(jsonToSend); //felkuldi a palya id-t
|
||||
//byte[] jsonToSend = new System.Text.UTF8Encoding().GetBytes("{\"bevitel1\":"+palya_id+"}"); //palya id megadasa
|
||||
//uwr.uploadHandler = (UploadHandler)new UploadHandlerRaw(jsonToSend); //felkuldi a palya id-t
|
||||
uwr.downloadHandler = (DownloadHandler)new DownloadHandlerBuffer();
|
||||
uwr.SetRequestHeader("Content-Type", "application/json");
|
||||
|
||||
@@ -213,14 +226,21 @@ public class DatabaseData : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerator IPostNewScoreData() {
|
||||
private IEnumerator IPostNewScoreData(int playerid, ulong score, string time) {
|
||||
//input.text = "loading...";
|
||||
|
||||
string uri = "http://localhost:3000/newscore";
|
||||
|
||||
//felhasznalonevet ki kell irni fajlba
|
||||
//ha username keresve lenne es ha nincs akkor kap egy uj id-t ami ideiglenesen tarolodik (ures string a visszateres?)
|
||||
//ha van akkor akkor lekeri az id-t es ideiglenesen tarolja
|
||||
|
||||
|
||||
var uwr = new UnityWebRequest(uri, "POST");
|
||||
byte[] jsonToSend =
|
||||
new System.Text.UTF8Encoding().GetBytes("{\"bevitel1\":2,\"bevitel2\":1,\"bevitel3\":400,\"bevitel4\":\"00:05:06\"}");
|
||||
new System.Text.UTF8Encoding().GetBytes("{\"bevitel1\":"+playerid+",\"bevitel2\":400,\"bevitel3\":\"00:05:06\"}");
|
||||
//playerid, points, time
|
||||
|
||||
uwr.uploadHandler = (UploadHandler)new UploadHandlerRaw(jsonToSend);
|
||||
uwr.downloadHandler = (DownloadHandler)new DownloadHandlerBuffer();
|
||||
uwr.SetRequestHeader("Content-Type", "application/json");
|
||||
|
||||
@@ -23,7 +23,7 @@ public class SceneUIManager : MonoBehaviour
|
||||
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
|
||||
}
|
||||
|
||||
public void LoadScene(int sceneIndex) {
|
||||
public static void LoadScene(int sceneIndex) {
|
||||
SceneManager.LoadScene(sceneIndex);
|
||||
}
|
||||
}
|
||||
26
Assets/Scripts/Timer.cs
Normal file
26
Assets/Scripts/Timer.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using System.Diagnostics;
|
||||
using TMPro;
|
||||
|
||||
|
||||
public class Timer : MonoBehaviour
|
||||
{
|
||||
public Stopwatch playTime;
|
||||
|
||||
public TMP_Text time;
|
||||
|
||||
private void Awake() {
|
||||
playTime = new Stopwatch();
|
||||
}
|
||||
private void Update() {
|
||||
time.text = playTime.Elapsed.Seconds.ToString();
|
||||
}
|
||||
|
||||
public string convertTimeToString(){
|
||||
UnityEngine.Debug.Log(playTime.Elapsed.ToString(@"hh\:mm\:ss"));
|
||||
return playTime.Elapsed.ToString(@"hh\:mm\:ss");
|
||||
}
|
||||
|
||||
}
|
||||
11
Assets/Scripts/Timer.cs.meta
Normal file
11
Assets/Scripts/Timer.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3c0512d5f0582734f99e51ebfb533bc4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
96
Assets/Scripts/UsernameHandler.cs
Normal file
96
Assets/Scripts/UsernameHandler.cs
Normal file
@@ -0,0 +1,96 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using TMPro;
|
||||
|
||||
public class UsernameHandler : MonoBehaviour
|
||||
{
|
||||
public string username; //playerlistbe benne van az id-val
|
||||
public int userid;
|
||||
private string path;
|
||||
|
||||
public TMP_InputField input;
|
||||
public GameObject inputBackground;
|
||||
public Canvas usernameInputCanvas;
|
||||
|
||||
private StreamWriter writer;
|
||||
private StreamReader reader;
|
||||
private DatabaseData db;
|
||||
private PlayerList playerList;
|
||||
|
||||
private void Awake() {
|
||||
input.gameObject.SetActive(false);
|
||||
inputBackground.SetActive(false);
|
||||
path = Application.persistentDataPath + "/username.txt";
|
||||
db = FindObjectOfType<DatabaseData>();
|
||||
db.GetPlayerData();
|
||||
}
|
||||
|
||||
private void Start() {
|
||||
usernameCheck();
|
||||
}
|
||||
|
||||
public void ReadUsername(string username){ //kiirja az inputbol kapott usernevet fajlba
|
||||
this.username = username;
|
||||
Debug.Log(this.username);
|
||||
|
||||
writer = new StreamWriter(path, false, Encoding.Default);
|
||||
writer.Write(username);
|
||||
writer.Close();
|
||||
|
||||
input.gameObject.SetActive(false);
|
||||
inputBackground.SetActive(false);
|
||||
usernameInputCanvas.gameObject.SetActive(false);
|
||||
|
||||
getId();
|
||||
}
|
||||
|
||||
private void getId(){
|
||||
foreach(var item in db.players.player){
|
||||
if(item.player_name.Equals(username)){
|
||||
userid = item.player_id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void usernameCheck(){
|
||||
string data = "";
|
||||
|
||||
try
|
||||
{
|
||||
reader = new StreamReader(path);
|
||||
}
|
||||
catch (System.IO.FileNotFoundException)
|
||||
{
|
||||
//ha nem letezik a fajl aktivalja az inputot
|
||||
usernameInputCanvas.gameObject.SetActive(true);
|
||||
inputBackground.SetActive(true);
|
||||
input.gameObject.SetActive(true);
|
||||
|
||||
}
|
||||
|
||||
if(File.Exists(path)){
|
||||
while(!reader.EndOfStream){
|
||||
data += reader.ReadLine();
|
||||
}
|
||||
|
||||
if(data.Equals("")){ //nincs username meg
|
||||
usernameInputCanvas.gameObject.SetActive(true);
|
||||
input.gameObject.SetActive(true);
|
||||
inputBackground.SetActive(true);
|
||||
}else{
|
||||
//van username
|
||||
username = data;
|
||||
Debug.Log("username: " + username);
|
||||
|
||||
getId();
|
||||
|
||||
input.gameObject.SetActive(false);
|
||||
inputBackground.SetActive(false);
|
||||
usernameInputCanvas.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/UsernameHandler.cs.meta
Normal file
11
Assets/Scripts/UsernameHandler.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d6b767d38cbe50a4d85298df361ad2aa
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -11,7 +11,7 @@ public class WallCollision : MonoBehaviour
|
||||
if(other.gameObject.tag == "Player"){
|
||||
|
||||
Debug.Log("neki ment a falnak");
|
||||
jatekmanager.UpdateGameState(jatekmanager.GameState.Meghaltal);
|
||||
jatekmanager.Instance.UpdateGameState(jatekmanager.GameState.Meghaltal);
|
||||
/*#if UNITY_EDITOR
|
||||
EditorApplication.isPlaying = false;
|
||||
#else
|
||||
|
||||
@@ -22,14 +22,24 @@ public class jatekmanager : MonoBehaviour
|
||||
public GameObject settingsGomb;
|
||||
public GameObject shopGomb;
|
||||
|
||||
|
||||
private DatabaseData db;
|
||||
private UsernameHandler usernameHandler;
|
||||
private Score score;
|
||||
private Timer timer;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
Application.targetFrameRate = 60;
|
||||
Instance = this;
|
||||
db = FindObjectOfType<DatabaseData>();
|
||||
usernameHandler = FindObjectOfType<UsernameHandler>();
|
||||
score = FindObjectOfType<Score>();
|
||||
timer = FindObjectOfType<Timer>();
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
|
||||
UpdateGameState(GameState.Home);
|
||||
}
|
||||
|
||||
@@ -114,10 +124,10 @@ public class jatekmanager : MonoBehaviour
|
||||
|
||||
public void ChangeToGame()
|
||||
{
|
||||
UpdateGameState(GameState.Game);
|
||||
homeGomb.SetActive(false);
|
||||
settingsGomb.SetActive(false);
|
||||
shopGomb.SetActive(false);
|
||||
UpdateGameState(GameState.Game);
|
||||
}
|
||||
|
||||
IEnumerator TimerGame()
|
||||
@@ -132,6 +142,7 @@ public class jatekmanager : MonoBehaviour
|
||||
StartCoroutine(TimerGame());
|
||||
GetComponent <GroundController> ().enabled = true;
|
||||
GetComponent <PlayerController>().enabled = true;
|
||||
timer.playTime.Start();
|
||||
}
|
||||
|
||||
public void ChangeToMeghaltal()
|
||||
@@ -141,15 +152,21 @@ public class jatekmanager : MonoBehaviour
|
||||
|
||||
private async void HandleMeghaltal()
|
||||
{
|
||||
playButton.SetActive(false);
|
||||
//ora leallitasa
|
||||
timer.playTime.Stop();
|
||||
|
||||
//Valtson at high score tabla scenebe utana ha megnyomott egy gombot ugy menjen vissza a menube
|
||||
//toltse fel az adatokat a run-rol
|
||||
db.PostNewScoreData(usernameHandler.userid, score.score, timer.convertTimeToString());
|
||||
|
||||
SceneUIManager.LoadScene(1); //HighScore scene
|
||||
|
||||
//
|
||||
|
||||
/*playButton.SetActive(false);
|
||||
homeGomb.SetActive(true);
|
||||
GetComponent<GroundController>().enabled = false;
|
||||
GetComponent<PlayerController>().enabled = false;
|
||||
garazs.SetActive(true);
|
||||
garazs.SetActive(true);*/
|
||||
}
|
||||
|
||||
|
||||
//application target frame rate
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -7,9 +7,7 @@ public class menumanager : MonoBehaviour
|
||||
{
|
||||
public CinemachineVirtualCamera currentCamera;
|
||||
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
private void Start()
|
||||
{
|
||||
currentCamera.Priority++;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user