commit1e4ffae4f6Author: bance <90307762+bance23@users.noreply.github.com> Date: Sat May 13 14:23:47 2023 +0200 proba athozas veszelyes commit0297a2cb78Merge:604088e31b9214Author: bance <90307762+bance23@users.noreply.github.com> Date: Sat May 13 14:09:48 2023 +0200 Merge branch 'master' of https://github.com/playmaker1210/PuzzleColorBall commit31b9214f35Merge:184d2e889976bbAuthor: Playmaker1210 <hatvanitamas09@gmail.com> Date: Mon May 8 14:42:34 2023 +0200 Merge https://github.com/playmaker1210/PuzzleColorBall commit184d2e84daAuthor: Playmaker1210 <hatvanitamas09@gmail.com> Date: Mon May 8 14:41:59 2023 +0200 server mukodik commit89976bbcf8Author: playmaker1210 <75033623+playmaker1210@users.noreply.github.com> Date: Fri May 5 12:49:28 2023 +0200 Update README.md commit250cc0ffeeAuthor: playmaker1210 <75033623+playmaker1210@users.noreply.github.com> Date: Fri May 5 12:49:01 2023 +0200 Create README.md commit2f0ae77e35Author: playmaker1210 <hatvanitamas09@gmail.com> Date: Thu May 4 12:56:56 2023 +0200 update commitb94c80b293Author: Playmaker1210 <hatvanitamas09@gmail.com> Date: Tue May 2 13:46:38 2023 +0200 coin db working commit25d792e0fdAuthor: playmaker1210 <hatvanitamas09@gmail.com> Date: Sat Apr 29 17:07:23 2023 +0200 update
111 lines
3.0 KiB
C#
111 lines
3.0 KiB
C#
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 CoinCounter cc;
|
|
|
|
private void Awake() {
|
|
input.gameObject.SetActive(false);
|
|
inputBackground.SetActive(false);
|
|
path = Application.persistentDataPath + "/username.txt";
|
|
cc = FindObjectOfType<CoinCounter>();
|
|
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;
|
|
}
|
|
}
|
|
|
|
db.GetCoinDataCall(userid);
|
|
}
|
|
|
|
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();
|
|
|
|
//StartCoroutine(waitForCoins());
|
|
|
|
|
|
|
|
input.gameObject.SetActive(false);
|
|
inputBackground.SetActive(false);
|
|
usernameInputCanvas.gameObject.SetActive(false);
|
|
}
|
|
}
|
|
}
|
|
|
|
private IEnumerator waitForCoins(){
|
|
yield return new WaitUntil(() => db.coins != 0);
|
|
|
|
cc.SetCoin(db.GetCoins(userid));
|
|
Debug.Log("uh coin"+cc.coin);
|
|
}
|
|
} |