Fhub link
This commit is contained in:
parent
3db7622e7b
commit
6b9a2e7b80
File diff suppressed because it is too large
Load Diff
|
|
@ -189,12 +189,15 @@ public static class DataManager{
|
|||
LoadingScreen.LoadLevel("MainMenu");
|
||||
}
|
||||
|
||||
public static async Task RefreshLeaderboard(){
|
||||
public static async Task RefreshLeaderboard(bool total = false){
|
||||
WWWForm form = new WWWForm();
|
||||
|
||||
Debug.Log(userData.ToString());
|
||||
|
||||
form.AddField("username", userData.username);
|
||||
if(total){
|
||||
form.AddField("total", "1");
|
||||
}
|
||||
bool foundMe = false;
|
||||
|
||||
using (UnityWebRequest request = UnityWebRequest.Post(API_ENDPOINT + "get_leaderboard.php", form))
|
||||
{
|
||||
|
|
@ -203,32 +206,46 @@ public static class DataManager{
|
|||
{
|
||||
await Task.Yield();
|
||||
}
|
||||
Debug.Log("add scores response: " +request.downloadHandler.text);
|
||||
|
||||
Debug.Log("leaderboard response: " +request.downloadHandler.text);
|
||||
if(request.downloadHandler.text.Contains("{")){
|
||||
try{
|
||||
string[] items = request.downloadHandler.text.Split("<td>");
|
||||
Leaderboard = new List<LeaderboardItemData>();
|
||||
foreach(string item in items){
|
||||
if(item == DataManager.userData.username){
|
||||
foundMe=true;
|
||||
}
|
||||
LeaderboardItemData newItem = JsonConvert.DeserializeObject<LeaderboardItemData>(item);
|
||||
|
||||
Leaderboard.Add(newItem);
|
||||
}
|
||||
|
||||
Debug.Log("Success parsing userdata");
|
||||
|
||||
|
||||
}catch(Exception e){
|
||||
Debug.Log("Error parsing leaderboard");
|
||||
}
|
||||
}else{
|
||||
|
||||
MessageBox.ShowMessage("Error getting leaderboard, Server said\n" +request.downloadHandler.text);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if(!foundMe){
|
||||
form.AddField("id",DataManager.userData.id);
|
||||
form.AddField("topScore","1");
|
||||
|
||||
using (UnityWebRequest request = UnityWebRequest.Post(API_ENDPOINT + "get_player_position.php", form))
|
||||
{
|
||||
var operation = request.SendWebRequest();
|
||||
while (!operation.isDone)
|
||||
{
|
||||
await Task.Yield();
|
||||
}
|
||||
Debug.Log("my position: " +request.downloadHandler.text);
|
||||
|
||||
LeaderboardItemData newItem = new LeaderboardItemData(){position=int.Parse(request.downloadHandler.text), name= DataManager.userData.username, topScore = DataManager.userData.TopScore};
|
||||
Leaderboard.Add(newItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -254,6 +271,8 @@ public class LeaderboardItemData{
|
|||
public string name;
|
||||
public int topScore;
|
||||
|
||||
public int Score;
|
||||
|
||||
public string DisplayName{get{
|
||||
string _name= name;
|
||||
if(name.Contains("#0")){
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Google;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
|
@ -22,9 +24,13 @@ public class MainMenu : MonoBehaviour
|
|||
public Button signoutBtn;
|
||||
public Sprite muteIcon, unmuteIcon;
|
||||
|
||||
public Image totalScoreBG, scoreBG;
|
||||
|
||||
|
||||
public Text txtUserId;
|
||||
|
||||
public Text txtSeasonTimer;
|
||||
|
||||
void Awake(){
|
||||
if(!DataManager.isLogged){
|
||||
SceneManager.LoadScene(0);
|
||||
|
|
@ -61,6 +67,14 @@ public class MainMenu : MonoBehaviour
|
|||
}else{
|
||||
muteBtn.transform.GetChild(0).GetComponent<Image>().sprite = unmuteIcon;
|
||||
}
|
||||
DateTime now = DateTime.Now;
|
||||
DateTime nextSeason = new DateTime(now.Year, (now.Month < 12) ? now.Month+1 : 1,1);
|
||||
txtSeasonTimer.text = "Season Ends In : <size=80>" +(nextSeason - now).Days + "</size> Days";
|
||||
}
|
||||
|
||||
|
||||
public void ShowInfoSeason(){
|
||||
MessageBox.ShowMessage("When the new season begins your Score and Top Score will reset\n By the end of this season, Current scores will be preserved and can be seen on this season's leaderboard", "Season info");
|
||||
}
|
||||
|
||||
public void SettingsPage(){
|
||||
|
|
@ -71,7 +85,8 @@ public class MainMenu : MonoBehaviour
|
|||
public void LeaderboarPage(){
|
||||
LeanTween.moveX(MainMenuPanel, -10000, transitionTime).setEase(transitionEffect);
|
||||
LeanTween.moveX(LeaderboarPanel, defaultCenter.x, transitionTime).setEase(transitionEffect);
|
||||
RefreshLeaderboard();
|
||||
// RefreshLeaderboard();
|
||||
ToggleTotalScoreLeaderboardAsync(false);
|
||||
}
|
||||
|
||||
public void MainPage(){
|
||||
|
|
@ -137,15 +152,28 @@ public class MainMenu : MonoBehaviour
|
|||
}
|
||||
|
||||
void UpdateLeaderboardUI(){
|
||||
if(DataManager.Leaderboard == null){return;}
|
||||
if(DataManager.Leaderboard.Count <= 0){return;}
|
||||
for(int i =0; i < DataManager.Leaderboard.Count; i++){
|
||||
LeaderboardItemsParent.GetChild(i).GetChild(0).GetComponent<Text>().text = $"{i+1}." + DataManager.Leaderboard[i].DisplayName;
|
||||
LeaderboardItemsParent.GetChild(i).GetChild(0).GetComponent<Text>().text = $"{DataManager.Leaderboard[i].position}." + DataManager.Leaderboard[i].DisplayName;
|
||||
// LeaderboardItemsParent.GetChild(i).GetChild(0).GetComponent<Text>().text = $"{i+1}." + DataManager.Leaderboard[i].name;
|
||||
LeaderboardItemsParent.GetChild(i).GetChild(1).GetComponent<Text>().text = DataManager.Leaderboard[i].topScore.ToString();
|
||||
LeaderboardItemsParent.GetChild(i).GetChild(1).GetComponent<Text>().text = DataManager.Leaderboard[i].Score.ToString();
|
||||
LeaderboardItemsParent.GetChild(i).GetChild(2).GetComponent<Text>().text = DataManager.Leaderboard[i].topScore.ToString();
|
||||
|
||||
LeaderboardItemsParent.GetChild(i).GetComponent<Image>().CrossFadeAlpha((DataManager.Leaderboard[i].name == DataManager.userData.username) ? 0.9f : 0,0.5f,true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public async void ToggleTotalScoreLeaderboardAsync(bool total){
|
||||
totalScoreBG.color = new Color(totalScoreBG.color.r, totalScoreBG.color.g, totalScoreBG.color.b, total? 1 : 0.1f);
|
||||
scoreBG.color = new Color(scoreBG.color.r, scoreBG.color.g, scoreBG.color.b, total? 0.1f : 1f);
|
||||
|
||||
await DataManager.RefreshLeaderboard(total);
|
||||
UpdateLeaderboardUI();
|
||||
|
||||
}
|
||||
|
||||
void SignOut(){
|
||||
|
||||
|
||||
|
|
|
|||
3
debug.log
Normal file
3
debug.log
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
[0510/092001.461:ERROR:registration_protocol_win.cc(107)] CreateFile: The system cannot find the file specified. (0x2)
|
||||
[0510/110657.659:ERROR:registration_protocol_win.cc(107)] CreateFile: The system cannot find the file specified. (0x2)
|
||||
[0510/110746.417:ERROR:registration_protocol_win.cc(107)] CreateFile: The system cannot find the file specified. (0x2)
|
||||
Loading…
Reference in New Issue
Block a user