kommentek + update
This commit is contained in:
@@ -4,20 +4,19 @@ using UnityEngine;
|
||||
|
||||
public class CameraController : MonoBehaviour
|
||||
{
|
||||
public GameObject player;
|
||||
public Camera camera;
|
||||
private Vector3 offset;
|
||||
public float xPostion = 0;
|
||||
public GameObject player; //jatekos objektum
|
||||
public Camera camera; //fo kamera
|
||||
private Vector3 offset; //kamera pozicio
|
||||
public float xPostion = 0; //x tengely pozicio
|
||||
|
||||
void Start(){
|
||||
private void Start(){ //kezdeskor a kamera ugorjon a jatekos moge
|
||||
offset.x = xPostion;
|
||||
offset.y = camera.transform.position.y - player.transform.position.y;
|
||||
offset.z = camera.transform.position.z - player.transform.position.z;
|
||||
|
||||
}
|
||||
|
||||
void LateUpdate()
|
||||
{
|
||||
private void LateUpdate(){ //kamera pozicio frissitese
|
||||
if(player.transform.position.x != 3 || player.transform.position.x != -3)
|
||||
camera.transform.position = player.transform.position + offset;
|
||||
}
|
||||
|
||||
@@ -4,22 +4,23 @@ using UnityEngine;
|
||||
|
||||
public class Date
|
||||
{
|
||||
private int year;
|
||||
private int month;
|
||||
private int day;
|
||||
private int year; //ev
|
||||
private int month; //honap
|
||||
private int day; //nap
|
||||
|
||||
public Date(string date) {
|
||||
date = date.Substring(0, date.Length - 14);
|
||||
string[] sp = date.Split('-');
|
||||
date = date.Substring(0, date.Length - 14); //idozona levagasa
|
||||
string[] sp = date.Split('-'); //szoveg feladarabolasa
|
||||
year = int.Parse(sp[0]);
|
||||
month = int.Parse(sp[1]);
|
||||
day = int.Parse(sp[2]);
|
||||
}
|
||||
|
||||
public string printDate() {
|
||||
public string printDate() { //datum kiiratasa
|
||||
return getYear() + "." + getMonth() + "." + getDay();
|
||||
}
|
||||
|
||||
//get fv-k
|
||||
public int getYear() {
|
||||
return year;
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ public class GroundController : MonoBehaviour
|
||||
public GameObject[] sideObjects;
|
||||
private float groundMoveSpeed = 10f;
|
||||
|
||||
|
||||
private void Awake() {
|
||||
//Loading modules
|
||||
loadFrom = LoadPrefabs("Prefabs/Modulok");
|
||||
@@ -76,13 +75,9 @@ public class GroundController : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void CreateNewGround(){
|
||||
int random = UnityEngine.Random.Range(0, loadFrom.Length);
|
||||
//ketto modullal elobb tolt be, annak az iranyanak megfeleloen, +80 a ket modull hossza
|
||||
Instantiate(loadFrom[random], new Vector3(0,0, ground[ground.Length-2].transform.position.z + 80), ground[ground.Length-2].transform.rotation);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -5,13 +5,54 @@ using TMPro;
|
||||
|
||||
public class HighScoreTable : MonoBehaviour
|
||||
{
|
||||
public Transform entryContainer;
|
||||
public Transform entryTemplate;
|
||||
public Transform entryContainer; //A helyezeseket tartalmazo helyhez referencia
|
||||
public Transform entryTemplate; //Egy helyezeshez egy template (tartalmazza a helyezest, nevet, pontszamot, es idot), ebbol letrehozott masolatok lesznek az entryContainerbe
|
||||
|
||||
private DatabaseData dbData;
|
||||
private HighScoreTableDataContainer htdc;
|
||||
private DatabaseData dbData; //Database osztalyhoz referencia
|
||||
private HighScoreTableDataContainer htdc; //A tombot tarolo osztalyhoz referencia
|
||||
|
||||
/*private void Awake() {
|
||||
public void CreateTable(HighScoreTableData[] htd){
|
||||
foreach(HighScoreTableData item in htd){
|
||||
item.kiir(); //konzolra Debug miatt kiirja az adatokat
|
||||
}
|
||||
|
||||
entryTemplate.gameObject.SetActive(false); //Objektum kikapcsolasa hogy ne legyen lathato
|
||||
|
||||
float templateHight = 35f; //Egy sor magassaga
|
||||
|
||||
for (int i = 0; i < htd.Length; i++){ //minden adaton vegigmegyunk a tombben
|
||||
Transform entryTransform = Instantiate(entryTemplate, entryContainer); //uj sor letrehozasa az entryContainerben
|
||||
RectTransform entryRectTransform = entryTransform.GetComponent<RectTransform>();
|
||||
RectTransform entryContainerRect = entryContainer.GetComponent<RectTransform>();
|
||||
entryRectTransform.anchoredPosition = new Vector2(0, -templateHight * i + (entryContainerRect.rect.height / 2) - 20); //A sor poziciojanak beallitasa x,y koordinataval
|
||||
entryTransform.gameObject.SetActive(true); //Objektum megjelenitese
|
||||
|
||||
|
||||
//a helyezes szoveg letrehozasa 1.: 1st, 2.: 2nd, 3.: 3rd, 4.: 4th...
|
||||
int rank = i+1;
|
||||
string rankString;
|
||||
|
||||
switch(rank){
|
||||
default: rankString = rank + "th"; break;
|
||||
case 1: rankString = rank + "st"; break;
|
||||
case 2: rankString = rank + "nd"; break;
|
||||
case 3: rankString = rank + "rd"; break;
|
||||
}
|
||||
|
||||
//a tombben levo adatok beirasa
|
||||
entryTransform.Find("posText").GetComponent<TMP_Text>().text = rankString;
|
||||
entryTransform.Find("nameText").GetComponent<TMP_Text>().text = htd[i].player_name;
|
||||
entryTransform.Find("scoreText").GetComponent<TMP_Text>().text = htd[i].score_points.ToString();
|
||||
entryTransform.Find("timeText").GetComponent<TMP_Text>().text = htd[i].score_time;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//////////
|
||||
|
||||
/*private void Awake() {
|
||||
dbData = FindObjectOfType<DatabaseData>();
|
||||
dbData.GetHighScoreData(1);
|
||||
htdc = dbData.htdcReturn();
|
||||
@@ -50,38 +91,4 @@ public class HighScoreTable : MonoBehaviour
|
||||
|
||||
}
|
||||
}*/
|
||||
|
||||
public void CreateTable(HighScoreTableData[] htda){
|
||||
foreach(HighScoreTableData item in htda){
|
||||
item.kiir();
|
||||
}
|
||||
|
||||
entryTemplate.gameObject.SetActive(false);
|
||||
|
||||
float templateHight = 35f;
|
||||
|
||||
for (int i = 0; i < htda.Length; i++){ //for size of player list or highscore data lekerdezes meret
|
||||
Transform entryTransform = Instantiate(entryTemplate, entryContainer);
|
||||
RectTransform entryRectTransform = entryTransform.GetComponent<RectTransform>();
|
||||
RectTransform entryContainerRect = entryContainer.GetComponent<RectTransform>();
|
||||
entryRectTransform.anchoredPosition = new Vector2(0, -templateHight * i + (entryContainerRect.rect.height / 2) - 20);
|
||||
entryTransform.gameObject.SetActive(true);
|
||||
|
||||
int rank = i+1;
|
||||
string rankString;
|
||||
|
||||
switch(rank){
|
||||
default: rankString = rank + "th"; break;
|
||||
case 1: rankString = rank + "st"; break;
|
||||
case 2: rankString = rank + "nd"; break;
|
||||
case 3: rankString = rank + "rd"; break;
|
||||
}
|
||||
|
||||
entryTransform.Find("posText").GetComponent<TMP_Text>().text = rankString;
|
||||
entryTransform.Find("nameText").GetComponent<TMP_Text>().text = htda[i].player_name;
|
||||
entryTransform.Find("scoreText").GetComponent<TMP_Text>().text = htda[i].score_points.ToString();
|
||||
entryTransform.Find("timeText").GetComponent<TMP_Text>().text = htda[i].score_time;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,13 +4,11 @@ using UnityEngine;
|
||||
|
||||
[System.Serializable]
|
||||
public class HighScoreTableData {
|
||||
public string player_name;
|
||||
public int score_points;
|
||||
public string score_time;
|
||||
public string player_name; //Jatekos neve
|
||||
public int score_points; //A jatekos altal elert pontszam a palyan
|
||||
public string score_time; //A jatekos mennyi idot toltott a palyan
|
||||
|
||||
public void kiir(){
|
||||
Debug.Log("kiir name: " + player_name + " points: " + score_points + " time: " + score_time);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -4,33 +4,33 @@ using UnityEngine;
|
||||
using TMPro;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
|
||||
public class DatabaseData : MonoBehaviour
|
||||
{
|
||||
public TMP_InputField input;
|
||||
public PlayerList players;
|
||||
public HighScoreTableDataContainer htdc;
|
||||
public HighScoreTable hst;
|
||||
public string jsondata;
|
||||
public TMP_InputField input; //szoveg megjelenitese
|
||||
public PlayerList players; //jatekos adatok
|
||||
public HighScoreTableDataContainer htdc; //itt van a tomb
|
||||
public HighScoreTable hst; //high score table ui
|
||||
public string jsondata; //json szoveg
|
||||
|
||||
private void Awake() {
|
||||
hst = FindObjectOfType<HighScoreTable>();
|
||||
htdc = new HighScoreTableDataContainer();
|
||||
players = new PlayerList();
|
||||
hst = FindObjectOfType<HighScoreTable>(); //High Score Table referencia
|
||||
htdc = new HighScoreTableDataContainer(); //High Score Table Container objektum
|
||||
players = new PlayerList(); //jatekos lista osztaly
|
||||
}
|
||||
|
||||
public HighScoreTableDataContainer htdcReturn(){
|
||||
return htdc;
|
||||
private void Start() {
|
||||
GetHighScoreData(2);
|
||||
}
|
||||
|
||||
public void jsonParser(string jsondata) {
|
||||
public void jsonParser(string jsondata) { //beerkezo json adat eltarolasa
|
||||
players = JsonUtility.FromJson<PlayerList>("{\"player\":" + jsondata + "}");
|
||||
}
|
||||
|
||||
public void jsonParserHighScore(string jsondata) {
|
||||
public void jsonParserHighScore(string jsondata) { //beerkezo json adat eltarolasa
|
||||
htdc = JsonUtility.FromJson<HighScoreTableDataContainer>("{\"htd\":" + jsondata + "}");
|
||||
}
|
||||
|
||||
//fuggvenyek amik meghivjak a rutint
|
||||
public void GetPlayerData() => StartCoroutine(IGetPlayerData());
|
||||
public void GetHighScoreData(int palya_id) => StartCoroutine(IGetHighScoreData(palya_id));
|
||||
public void PostNewPlayerData() => StartCoroutine(IPostNewPlayerData());
|
||||
@@ -38,42 +38,40 @@ public class DatabaseData : MonoBehaviour
|
||||
public void PostNewPalyaData() => StartCoroutine(IPostNewPalyaData());
|
||||
|
||||
private IEnumerator IGetPlayerData() {
|
||||
input.text = "Loading...";
|
||||
input.text = "Loading..."; //ideiglenes szoveg amig nem jelenik meg az adat szoveg
|
||||
|
||||
string uri = "http://localhost:3000/player";
|
||||
string uri = "http://localhost:3000/player"; //backend vegpont linkje
|
||||
|
||||
using (UnityWebRequest request = UnityWebRequest.Get(uri)) {
|
||||
yield return request.SendWebRequest();
|
||||
using (UnityWebRequest request = UnityWebRequest.Get(uri)) { //uj webrequest objektum letrehozasa, aminek megadjuk hogy ez egy get-es lekerdezes
|
||||
yield return request.SendWebRequest(); //amig be nem fejezodik az fv ide fog visszaterni
|
||||
|
||||
if(request.isNetworkError || request.isHttpError) {
|
||||
if(request.isNetworkError || request.isHttpError) { //ha valami hiba tortent kiirjuk a kepernyore
|
||||
input.text = request.error;
|
||||
} else {
|
||||
jsondata = request.downloadHandler.text;
|
||||
jsonParser(jsondata);
|
||||
jsondata = request.downloadHandler.text; //json szoveg eltarolasa
|
||||
jsonParser(jsondata); //json adat atalakitasa
|
||||
foreach(var p in players.player) {
|
||||
p.ConvertDate();
|
||||
p.ConvertDate(); //datum eltarolasa es atalakitasa datum tipussa
|
||||
Debug.Log("p_id: " + p.player_id + " username: " + p.player_name + " join date: " + p.joindate.printDate() + "\n");
|
||||
}
|
||||
|
||||
input.text = "";
|
||||
foreach(var p in players.player) {
|
||||
p.ConvertDate();
|
||||
//adatok kiirasa kepernyore
|
||||
input.text += "p_id: " + p.player_id + " username: " + p.player_name + " join date: " + p.joindate.printDate() + "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void Start() {
|
||||
GetHighScoreData(2);
|
||||
}
|
||||
|
||||
private IEnumerator IGetHighScoreData(int palya_id){
|
||||
string uri = "http://localhost:3000/toplist";
|
||||
|
||||
var uwr = new UnityWebRequest(uri, "POST");
|
||||
byte[] jsonToSend = new System.Text.UTF8Encoding().GetBytes("{\"bevitel1\":"+palya_id+"}");
|
||||
uwr.uploadHandler = (UploadHandler)new UploadHandlerRaw(jsonToSend);
|
||||
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");
|
||||
|
||||
@@ -85,7 +83,7 @@ public class DatabaseData : MonoBehaviour
|
||||
input.text = uwr.downloadHandler.text;
|
||||
Debug.Log(uwr.downloadHandler.text);
|
||||
jsonParserHighScore(uwr.downloadHandler.text);
|
||||
hst.CreateTable(htdc.htd);
|
||||
hst.CreateTable(htdc.htd); //high score tabla letrehozasa
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,8 +92,8 @@ public class DatabaseData : MonoBehaviour
|
||||
|
||||
string uri = "http://localhost:3000/newplayer";
|
||||
|
||||
var uwr = new UnityWebRequest(uri, "POST");
|
||||
byte[] jsonToSend = new System.Text.UTF8Encoding().GetBytes("{ \"bevitel1\":\"postusername\"}");
|
||||
var uwr = new UnityWebRequest(uri, "POST"); //post beallitasa
|
||||
byte[] jsonToSend = new System.Text.UTF8Encoding().GetBytes("{ \"bevitel1\":\"postusername\"}"); //felviteli json
|
||||
uwr.uploadHandler = (UploadHandler)new UploadHandlerRaw(jsonToSend);
|
||||
uwr.downloadHandler = (DownloadHandler)new DownloadHandlerBuffer();
|
||||
uwr.SetRequestHeader("Content-Type", "application/json");
|
||||
@@ -105,7 +103,7 @@ public class DatabaseData : MonoBehaviour
|
||||
if (uwr.isNetworkError) {
|
||||
Debug.Log(uwr.error);
|
||||
} else {
|
||||
input.text = uwr.downloadHandler.text;
|
||||
input.text = uwr.downloadHandler.text; //vissza erzkezes arrol hogy sikeres a felvitel vagy nem
|
||||
Debug.Log(uwr.downloadHandler.text);
|
||||
}
|
||||
}
|
||||
@@ -151,4 +149,4 @@ public class DatabaseData : MonoBehaviour
|
||||
Debug.Log(uwr.downloadHandler.text);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,14 +4,12 @@ using UnityEngine;
|
||||
|
||||
[System.Serializable]
|
||||
public class Player {
|
||||
public int player_id;
|
||||
public string player_name;
|
||||
public Date joindate;
|
||||
public string player_join_date;
|
||||
public int player_id; //jatkos id-ja
|
||||
public string player_name; //jatekos neve
|
||||
public Date joindate; //elso csatlakozasi datuma
|
||||
public string player_join_date;
|
||||
|
||||
public void ConvertDate() { //mindig meg kell hivni
|
||||
joindate = new Date(player_join_date);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -4,83 +4,73 @@ using UnityEngine;
|
||||
|
||||
public class PlayerController : MonoBehaviour
|
||||
{
|
||||
public Rigidbody rb;
|
||||
public Rigidbody rb; //jatekos teste
|
||||
private CameraController cc;
|
||||
//public float moveSpeed = 5f;
|
||||
public float jumpforce = 5f;
|
||||
private float sideMovement = 3f;
|
||||
private Vector3 direction;
|
||||
private float horizontal, vertical;
|
||||
private bool isJumping;
|
||||
private bool isOnGround;
|
||||
|
||||
|
||||
//
|
||||
public float holdTime = 0.3f;
|
||||
private bool isTapped = false;
|
||||
private float timeSinceLastTap = 0f;
|
||||
|
||||
//swipe movement
|
||||
private Vector2 startTouchPosition;
|
||||
private Vector2 endTouchPosition;
|
||||
public float jumpforce = 5f; //mekkorat tudjon ugorni
|
||||
private float sideMovement = 3f; //oldalra mennyit mozogjon
|
||||
private Vector3 direction; //jatkos pozicio
|
||||
private bool isJumping; //levegobe van e
|
||||
public float holdTime = 0.3f; //meddig kell nyomni egy érintéshez
|
||||
private bool isTapped = false; //kattintas erzekeles
|
||||
private float timeSinceLastTap = 0f; //mennyi ido telt el a legutolso erintes ota
|
||||
private Vector2 startTouchPosition; //erintes kezdo pozicio
|
||||
private Vector2 endTouchPosition; //erintes vegpozicio
|
||||
|
||||
private void Awake() {
|
||||
cc = FindObjectOfType<CameraController>();
|
||||
cc = FindObjectOfType<CameraController>(); //kamera vezerlo referencia
|
||||
}
|
||||
|
||||
private void Update(){
|
||||
//jumping
|
||||
if(Input.touchCount > 0){
|
||||
Touch touch = Input.GetTouch(0);
|
||||
Touch touch = Input.GetTouch(0); //elso erintes lekerese
|
||||
|
||||
if(touch.phase == TouchPhase.Began){
|
||||
if(touch.phase == TouchPhase.Began){ //ha az erintes elkezdotott
|
||||
isTapped = true;
|
||||
timeSinceLastTap = Time.time;
|
||||
}
|
||||
|
||||
if(touch.phase == TouchPhase.Ended){
|
||||
if(touch.phase == TouchPhase.Ended){ //ha az erintes befejezodott
|
||||
isTapped = false;
|
||||
timeSinceLastTap = 0f;
|
||||
}
|
||||
|
||||
if(isTapped && rb.transform.position.y <= 0.16f){
|
||||
if(Time.time - timeSinceLastTap >= holdTime){
|
||||
if(Time.time - timeSinceLastTap >= holdTime){ //ha nyomva tartotta a beallitott ideig
|
||||
Debug.Log("Long tapped");
|
||||
rb.AddForce(new Vector3(0, jumpforce, 0));
|
||||
rb.AddForce(new Vector3(0, jumpforce, 0)); //ugras
|
||||
isTapped = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//new character controller with swipe lane changing
|
||||
if(Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began){
|
||||
startTouchPosition = Input.GetTouch(0).position;
|
||||
if(Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began){ //elso erintes elkezdodott
|
||||
startTouchPosition = Input.GetTouch(0).position;
|
||||
}
|
||||
if(Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Ended){
|
||||
if(Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Ended){ //elso erintes befejezodott
|
||||
endTouchPosition = Input.GetTouch(0).position;
|
||||
|
||||
if(endTouchPosition.x < startTouchPosition.x){
|
||||
if(endTouchPosition.x < startTouchPosition.x){ //balra huzott
|
||||
//left
|
||||
goLeft();
|
||||
|
||||
}else if(endTouchPosition.x > startTouchPosition.x){
|
||||
}else if(endTouchPosition.x > startTouchPosition.x){ //jobbra huzott
|
||||
//right
|
||||
goRight();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void goLeft(){
|
||||
private void goLeft(){ //helyezze at a jatekos objektumot a balra levo savba
|
||||
if(rb.transform.position.x >= 2.5f) return; //ne tudjon kimenni a savbol
|
||||
cc.xPostion = -3;
|
||||
//rb.transform.position = new Vector3(rb.transform.position.x + sideMovement, rb.transform.position.y, rb.transform.position.z);
|
||||
rb.AddForce(new Vector3(300f, 0, 0));
|
||||
cc.xPostion = -3; //kamera xPozicioja
|
||||
rb.transform.position = new Vector3(rb.transform.position.x + sideMovement, rb.transform.position.y, rb.transform.position.z);
|
||||
}
|
||||
|
||||
private void goRight(){
|
||||
private void goRight(){ //helyezze at a jatekos objektumot a jobbra levo savba
|
||||
if(rb.transform.position.x <= -2.5f) return; //ne tudjon kimenni a savbol
|
||||
cc.xPostion = 3;
|
||||
//rb.transform.position = new Vector3(rb.transform.position.x - sideMovement, rb.transform.position.y, rb.transform.position.z);
|
||||
rb.AddForce(new Vector3(-300f, 0, 0));
|
||||
cc.xPostion = 3; //kamera xPozicioja
|
||||
rb.transform.position = new Vector3(rb.transform.position.x - sideMovement, rb.transform.position.y, rb.transform.position.z);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,4 +6,4 @@ using UnityEngine;
|
||||
public class PlayerList
|
||||
{
|
||||
public Player[] player;
|
||||
}
|
||||
}
|
||||
@@ -26,8 +26,4 @@ public class SceneUIManager : MonoBehaviour
|
||||
public void LoadScene(int sceneIndex) {
|
||||
SceneManager.LoadScene(sceneIndex);
|
||||
}
|
||||
|
||||
public void DisableUI(string UIName) {
|
||||
//to be implemented when some ui is done
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user