Update, Maintaince Mode
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
#if UNITY_IOS
|
||||
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
@@ -90,3 +92,4 @@ public class AppleLogin : MonoBehaviour
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
||||
11
Assets/Scripts/AppleLogin.cs.meta
Normal file
11
Assets/Scripts/AppleLogin.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 88036cc12e1cd5d428bed7c251d00fc1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
46
Assets/Scripts/CheckUpdates.cs
Normal file
46
Assets/Scripts/CheckUpdates.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class CheckUpdates : MonoBehaviour
|
||||
{
|
||||
public static int ClientVersion = 1;
|
||||
public static int ServerVersion;
|
||||
|
||||
public static bool EverythingOkay => ClientVersion == ServerVersion;
|
||||
|
||||
public float interval = 30;
|
||||
|
||||
float t;
|
||||
|
||||
void Awake(){
|
||||
DontDestroyOnLoad(gameObject);
|
||||
CheckUpdate();
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
t+=Time.deltaTime;
|
||||
|
||||
if(t > interval){ t=0; CheckUpdate();}
|
||||
}
|
||||
|
||||
public void CheckUpdate(){
|
||||
StartCoroutine(checkUpdate());
|
||||
}
|
||||
|
||||
|
||||
IEnumerator checkUpdate(){
|
||||
WWW req= new WWW(DataManager.API_ENDPOINT + "get_version.php");
|
||||
yield return req;
|
||||
|
||||
Debug.Log("Server version: " + req.text);
|
||||
|
||||
ServerVersion = int.Parse(req.text);
|
||||
if(ServerVersion <= 0){
|
||||
LoadingScreen.LoadLevel("maintaince");
|
||||
}else if(ServerVersion != ClientVersion){
|
||||
LoadingScreen.LoadLevel("update");
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/CheckUpdates.cs.meta
Normal file
11
Assets/Scripts/CheckUpdates.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4359e4884e976494fa9b4dd41b10243c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -53,7 +53,7 @@ public static class DataManager{
|
||||
}catch(Exception e){
|
||||
Debug.Log("Error parsing userdata");
|
||||
UserData u = new UserData();
|
||||
Debug.Log( JsonConvert.SerializeObject(u));
|
||||
Debug.Log( JsonConvert.SerializeObject(u));
|
||||
Debug.LogError(e.Message);
|
||||
Debug.LogError(e.Source + e.StackTrace);
|
||||
}
|
||||
@@ -68,8 +68,9 @@ public static class DataManager{
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
LoadingScreen.LoadLevel("MainMenu");
|
||||
if(CheckUpdates.EverythingOkay){
|
||||
LoadingScreen.LoadLevel("MainMenu");
|
||||
}
|
||||
return 0;
|
||||
|
||||
}
|
||||
@@ -124,6 +125,7 @@ public static class DataManager{
|
||||
if(request.downloadHandler.text.Contains("{")){
|
||||
try{
|
||||
userData = JsonConvert.DeserializeObject<UserData>(request.downloadHandler.text);
|
||||
|
||||
if(userData == null){
|
||||
throw new NullReferenceException();
|
||||
}
|
||||
@@ -149,7 +151,9 @@ public static class DataManager{
|
||||
|
||||
}
|
||||
|
||||
LoadingScreen.LoadLevel("MainMenu");
|
||||
if(CheckUpdates.EverythingOkay){
|
||||
LoadingScreen.LoadLevel("MainMenu");
|
||||
}
|
||||
}
|
||||
|
||||
public static async void AddScores(int amount){
|
||||
|
||||
@@ -22,6 +22,8 @@ public class LoginManager : MonoBehaviour
|
||||
}
|
||||
|
||||
async void Start(){
|
||||
// DataManager.GoogleLogin("sewmina7d@gmail.com");
|
||||
// return;
|
||||
if(PlayerPrefs.HasKey("username") && PlayerPrefs.HasKey("password")){
|
||||
int result = await DataManager.Login(PlayerPrefs.GetString("username"), PlayerPrefs.GetString("password"));
|
||||
if(result == 0){return;}
|
||||
|
||||
@@ -21,7 +21,7 @@ public class MainMenu : MonoBehaviour
|
||||
|
||||
void Start()
|
||||
{
|
||||
if(!DataManager.isLogged){Application.LoadLevel(0);}
|
||||
if(!DataManager.isLogged){Debug.LogError("Not Logged in, Loading to login screen");Application.LoadLevel(0);}
|
||||
foreach(Text txtStat in txtStats){
|
||||
txtStat.text = txtStat.text.Replace("{score}",DataManager.userData.score).Replace("{top_score}",DataManager.userData.top_score).Replace("{play_time}",Helpers.SecondsToTime(int.Parse(DataManager.userData.play_time),showSeconds:false)).Replace("{asteroids}",DataManager.userData.asteroids).Replace("{near_miss}",DataManager.userData.near_miss).Replace("{total_games}",DataManager.userData.total_games);
|
||||
}
|
||||
|
||||
10
Assets/Scripts/UI_Helpers.cs
Normal file
10
Assets/Scripts/UI_Helpers.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class UI_Helpers : MonoBehaviour
|
||||
{
|
||||
public void OpenUrl(string url){
|
||||
Application.OpenURL(url);
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/UI_Helpers.cs.meta
Normal file
11
Assets/Scripts/UI_Helpers.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bc9187c17be357c458d80fb6c653cab9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user