Load balancer + kills text + most time and some other stuff
This commit is contained in:
@@ -20,6 +20,9 @@ public class DBmanager : MonoBehaviour
|
||||
private static int gems = 0;
|
||||
private static int metal = 0;
|
||||
private static int trophies = 0;
|
||||
private static int mostTime=0;
|
||||
private static int doubleKills,tripleKills,quadKills,pentaKills = 0;
|
||||
|
||||
private static List<InventoryEntry> inventory;
|
||||
private static List<int> expPassCollected = new List<int>();
|
||||
private static List<string> skinsPurchased = new List<string>();
|
||||
@@ -31,6 +34,11 @@ public class DBmanager : MonoBehaviour
|
||||
public static int Gems => gems;
|
||||
public static int Metal => metal;
|
||||
public static int Trophies => trophies;
|
||||
public static int MostTime=> mostTime;
|
||||
public static int DoubleKills => doubleKills;
|
||||
public static int TripleKills => tripleKills;
|
||||
public static int QuadKills => quadKills;
|
||||
public static int PentaKills => pentaKills;
|
||||
public static float Level => level;
|
||||
public static int LevelInt => Mathf.CeilToInt(level);
|
||||
public static List<int> ExpPassCollected => expPassCollected;
|
||||
@@ -293,6 +301,166 @@ public class DBmanager : MonoBehaviour
|
||||
OnStateChanged.Invoke();
|
||||
}
|
||||
|
||||
public async static void SetMostTime(int newValue, bool justOffline = false)
|
||||
{
|
||||
WWWForm form = new WWWForm();
|
||||
form.AddField("name", username);
|
||||
form.AddField("mostTime", newValue);
|
||||
int oldValue = mostTime;
|
||||
mostTime = newValue;
|
||||
if (justOffline) { return; }
|
||||
using (UnityWebRequest www = UnityWebRequest.Post(phpRoot + "set_mostTime.php", form))
|
||||
{
|
||||
var operation = www.SendWebRequest();
|
||||
while (!operation.isDone)
|
||||
{
|
||||
await Task.Yield();
|
||||
}
|
||||
|
||||
if (www.downloadHandler.text == "0")
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
mostTime = oldValue;
|
||||
Debug.Log("Response : " + www.downloadHandler.text);
|
||||
Debug.LogWarning("Failed to set most time to " + newValue);
|
||||
}
|
||||
}
|
||||
|
||||
GameManager.Refresh();
|
||||
OnStateChanged.Invoke();
|
||||
}
|
||||
|
||||
public async static void SetDoubleKills(int newValue, bool justOffline = false)
|
||||
{
|
||||
WWWForm form = new WWWForm();
|
||||
form.AddField("name", username);
|
||||
form.AddField("value", newValue);
|
||||
int oldValue = doubleKills;
|
||||
doubleKills = newValue;
|
||||
if (justOffline) { return; }
|
||||
using (UnityWebRequest www = UnityWebRequest.Post(phpRoot + "set_double_kills.php", form))
|
||||
{
|
||||
var operation = www.SendWebRequest();
|
||||
while (!operation.isDone)
|
||||
{
|
||||
await Task.Yield();
|
||||
}
|
||||
|
||||
if (www.downloadHandler.text == "0")
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
doubleKills = oldValue;
|
||||
Debug.Log("Response : " + www.downloadHandler.text);
|
||||
Debug.LogWarning("Failed to set double kills to " + newValue);
|
||||
}
|
||||
}
|
||||
|
||||
GameManager.Refresh();
|
||||
OnStateChanged.Invoke();
|
||||
}
|
||||
|
||||
public async static void SetTripleKills(int newValue, bool justOffline = false)
|
||||
{
|
||||
WWWForm form = new WWWForm();
|
||||
form.AddField("name", username);
|
||||
form.AddField("value", newValue);
|
||||
int oldValue = tripleKills;
|
||||
tripleKills = newValue;
|
||||
if (justOffline) { return; }
|
||||
using (UnityWebRequest www = UnityWebRequest.Post(phpRoot + "set_triple_kills.php", form))
|
||||
{
|
||||
var operation = www.SendWebRequest();
|
||||
while (!operation.isDone)
|
||||
{
|
||||
await Task.Yield();
|
||||
}
|
||||
|
||||
if (www.downloadHandler.text == "0")
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
tripleKills = oldValue;
|
||||
Debug.Log("Response : " + www.downloadHandler.text);
|
||||
Debug.LogWarning("Failed to set triple kills to " + newValue);
|
||||
}
|
||||
}
|
||||
|
||||
GameManager.Refresh();
|
||||
OnStateChanged.Invoke();
|
||||
}
|
||||
|
||||
public async static void SetQuadKills(int newValue, bool justOffline = false)
|
||||
{
|
||||
WWWForm form = new WWWForm();
|
||||
form.AddField("name", username);
|
||||
form.AddField("value", newValue);
|
||||
int oldValue = quadKills;
|
||||
quadKills = newValue;
|
||||
if (justOffline) { return; }
|
||||
using (UnityWebRequest www = UnityWebRequest.Post(phpRoot + "set_quad_kills.php", form))
|
||||
{
|
||||
var operation = www.SendWebRequest();
|
||||
while (!operation.isDone)
|
||||
{
|
||||
await Task.Yield();
|
||||
}
|
||||
|
||||
if (www.downloadHandler.text == "0")
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
quadKills = oldValue;
|
||||
Debug.Log("Response : " + www.downloadHandler.text);
|
||||
Debug.LogWarning("Failed to set quad kills to " + newValue);
|
||||
}
|
||||
}
|
||||
|
||||
GameManager.Refresh();
|
||||
OnStateChanged.Invoke();
|
||||
}
|
||||
|
||||
public async static void SetPentaKills(int newValue, bool justOffline = false)
|
||||
{
|
||||
WWWForm form = new WWWForm();
|
||||
form.AddField("name", username);
|
||||
form.AddField("value", newValue);
|
||||
int oldValue = pentaKills;
|
||||
pentaKills = newValue;
|
||||
if (justOffline) { return; }
|
||||
using (UnityWebRequest www = UnityWebRequest.Post(phpRoot + "set_penta_kills.php", form))
|
||||
{
|
||||
var operation = www.SendWebRequest();
|
||||
while (!operation.isDone)
|
||||
{
|
||||
await Task.Yield();
|
||||
}
|
||||
|
||||
if (www.downloadHandler.text == "0")
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
pentaKills = oldValue;
|
||||
Debug.Log("Response : " + www.downloadHandler.text);
|
||||
Debug.LogWarning("Failed to set penta kills to " + newValue);
|
||||
}
|
||||
}
|
||||
|
||||
GameManager.Refresh();
|
||||
OnStateChanged.Invoke();
|
||||
}
|
||||
|
||||
public static void SetExpPassCollected(string rawData, bool justOffline = false)
|
||||
{
|
||||
try
|
||||
|
||||
@@ -17,11 +17,18 @@ public class GameManager : MonoBehaviour
|
||||
public TMP_Text metalTxt;
|
||||
// public TMP_Text oxygenTxt;
|
||||
public TMP_Text[] trophiesTxts;
|
||||
public TMP_Text[] mostTimeTxts;
|
||||
public TMP_Text doubleKillsTxt;
|
||||
public TMP_Text tripleKillsTxt;
|
||||
public TMP_Text quadKillsTxt;
|
||||
public TMP_Text pentaKillsTxt;
|
||||
|
||||
|
||||
public TMP_Text[] levelTxts;
|
||||
public Slider[] levelSliders;
|
||||
public TMP_Text[] levelProgressTxts;
|
||||
|
||||
public GameObject loadingScreen;
|
||||
// public GameObject loadingScreen;
|
||||
|
||||
[Header("Profile")]
|
||||
public GameObject profilePopup;
|
||||
@@ -47,8 +54,6 @@ public class GameManager : MonoBehaviour
|
||||
RefreshData();
|
||||
}
|
||||
|
||||
loadingScreen.SetActive(false);
|
||||
|
||||
}
|
||||
|
||||
float networkCheckTimer = 0;
|
||||
@@ -88,6 +93,15 @@ public class GameManager : MonoBehaviour
|
||||
foreach(TMP_Text trophiesTxt in trophiesTxts){
|
||||
trophiesTxt.text = DBmanager.Trophies.ToString();
|
||||
}
|
||||
foreach(TMP_Text mostTimeTxt in mostTimeTxts){
|
||||
mostTimeTxt.text = SceneData.SecondsToText(DBmanager.MostTime);
|
||||
}
|
||||
|
||||
doubleKillsTxt.text = DBmanager.DoubleKills.ToString();
|
||||
tripleKillsTxt.text = DBmanager.TripleKills.ToString();
|
||||
quadKillsTxt.text = DBmanager.QuadKills.ToString();
|
||||
pentaKillsTxt.text = DBmanager.PentaKills.ToString();
|
||||
|
||||
// oxygenTxt.text = DBmanager.Trophies.ToString();
|
||||
foreach (TMP_Text levelTxt in levelTxts)
|
||||
{
|
||||
@@ -109,9 +123,10 @@ public class GameManager : MonoBehaviour
|
||||
|
||||
public async void LoadMinigame()
|
||||
{
|
||||
loadingScreen.SetActive(true);
|
||||
await Task.Delay(1000);
|
||||
SceneManager.LoadScene("MinigameMenu");
|
||||
// loadingScreen.SetActive(true);
|
||||
// await Task.Delay(1000);
|
||||
// SceneManager.LoadScene("Minigame");
|
||||
LoadingScreen.instance.LoadLevel("Minigame");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
62
Assets/Game/Scripts/LoadingScreen.cs
Normal file
62
Assets/Game/Scripts/LoadingScreen.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
public class LoadingScreen : MonoBehaviour
|
||||
{
|
||||
public static LoadingScreen instance;
|
||||
CanvasGroup canvasGroup;
|
||||
public Slider loadingProgress;
|
||||
public TMPro.TMP_Text loadingProgressTxt;
|
||||
|
||||
void Awake(){
|
||||
instance =this;
|
||||
}
|
||||
void Start()
|
||||
{
|
||||
DontDestroyOnLoad(gameObject);
|
||||
canvasGroup = GetComponent<CanvasGroup>();
|
||||
}
|
||||
|
||||
public void LoadLevel(string levelName){
|
||||
StartCoroutine(loadlLevel(levelName));
|
||||
}
|
||||
|
||||
IEnumerator loadlLevel(string levelName){
|
||||
canvasGroup.alpha=0;
|
||||
canvasGroup.blocksRaycasts=true;
|
||||
SetProgress(0);
|
||||
while(canvasGroup.alpha< 1f){
|
||||
canvasGroup.alpha+=0.03f;
|
||||
yield return new WaitForFixedUpdate();
|
||||
}
|
||||
while(RegionManager.selectedServer == null){
|
||||
loadingProgressTxt.text = "Preparing";
|
||||
yield return new WaitForSeconds(0.5f);
|
||||
}
|
||||
AsyncOperation asyncOperation = SceneManager.LoadSceneAsync(levelName);
|
||||
// asyncOperation.allowSceneActivation = false;
|
||||
while (!asyncOperation.isDone)
|
||||
{
|
||||
//Output the current progress
|
||||
// m_Text.text = "Loading progress: " + (asyncOperation.progress * 100) + "%";
|
||||
// Check if the load has finished
|
||||
SetProgress(asyncOperation.progress);
|
||||
yield return null;
|
||||
}
|
||||
yield return new WaitForSeconds(0.2f);
|
||||
|
||||
canvasGroup.blocksRaycasts=false;
|
||||
|
||||
while(canvasGroup.alpha> 0){
|
||||
canvasGroup.alpha-=0.03f;
|
||||
yield return new WaitForFixedUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
void SetProgress(float value){
|
||||
loadingProgress.value = value;
|
||||
loadingProgressTxt.text = (int)(value*100) + "%";
|
||||
}
|
||||
}
|
||||
11
Assets/Game/Scripts/LoadingScreen.cs.meta
Normal file
11
Assets/Game/Scripts/LoadingScreen.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c5c8585324f167adeb5f7768975c64fa
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -80,6 +80,13 @@ public class LoginManager : MonoBehaviour
|
||||
PlayerPrefs.SetString("password", login_password.text);
|
||||
PlayerPrefs.Save();}
|
||||
DBmanager.username = login_username.text;
|
||||
|
||||
DBmanager.SetPentaKills(int.Parse(www.text.Split('\t')[14]),true);
|
||||
DBmanager.SetQuadKills(int.Parse(www.text.Split('\t')[13]),true);
|
||||
DBmanager.SetTripleKills(int.Parse(www.text.Split('\t')[12]),true);
|
||||
DBmanager.SetDoubleKills(int.Parse(www.text.Split('\t')[11]),true);
|
||||
DBmanager.SetMostTime(int.Parse(www.text.Split('\t')[10]),true);
|
||||
|
||||
DBmanager.SetPurchasedSkins(www.text.Split('\t')[9]);
|
||||
DBmanager.GetInventoryFromServer(www.text.Split('\t')[8]);
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ public class AutoConnect : MonoBehaviour
|
||||
void Start()
|
||||
{
|
||||
if(isClient){
|
||||
FindObjectOfType<NetworkManager>().networkAddress = RegionManager.selectedServer.ip;
|
||||
FindObjectOfType<NetworkManager>().StartClient();
|
||||
}
|
||||
}
|
||||
|
||||
56
Assets/Game/Scripts/Minigame/KillText.cs
Normal file
56
Assets/Game/Scripts/Minigame/KillText.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using TMPro;
|
||||
using UnityEngine.UI;
|
||||
public class KillText : MonoBehaviour
|
||||
{
|
||||
private static KillText instance;
|
||||
|
||||
void Awake(){
|
||||
instance = this;
|
||||
}
|
||||
public static void Show(int kills){
|
||||
if(instance==null){
|
||||
Debug.LogError("No KillText instance was found!");
|
||||
return;
|
||||
}
|
||||
Debug.Log("Showin kills for " + kills);
|
||||
instance.m_show((kills > 5) ? 5: kills);
|
||||
}
|
||||
|
||||
private void m_show(int kills){
|
||||
if(kills < 2){return;}
|
||||
imgKills.sprite= sprites[kills-2];
|
||||
|
||||
instance.anim.CrossFadeInFixedTime("anim",0.1f);
|
||||
|
||||
switch(kills){
|
||||
case 2:
|
||||
txtKills.text = "Double Kill!";
|
||||
DBmanager.SetDoubleKills(DBmanager.DoubleKills+1);
|
||||
break;
|
||||
|
||||
case 3:
|
||||
txtKills.text = "Triple Kill!";
|
||||
DBmanager.SetTripleKills(DBmanager.TripleKills+1);
|
||||
|
||||
break;
|
||||
case 4:
|
||||
txtKills.text = "Quad Kill!";
|
||||
DBmanager.SetQuadKills(DBmanager.QuadKills+1);
|
||||
|
||||
break;
|
||||
case 5:
|
||||
txtKills.text = "Penta Kill!";
|
||||
DBmanager.SetPentaKills(DBmanager.PentaKills+1);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public Animator anim;
|
||||
public Sprite[] sprites;
|
||||
public Image imgKills;
|
||||
public TMP_Text txtKills;
|
||||
}
|
||||
11
Assets/Game/Scripts/Minigame/KillText.cs.meta
Normal file
11
Assets/Game/Scripts/Minigame/KillText.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 74b20ae065c1d6e57ae0380cb25bb83b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -22,6 +22,7 @@ public class MinigameManager : NetworkBehaviour
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
// if(!DBmanager.LoggedIn){SceneManager.LoadScene(0);}
|
||||
SceneData.GameManager = this;
|
||||
instance = this;
|
||||
|
||||
@@ -136,21 +137,27 @@ public class MinigameManager : NetworkBehaviour
|
||||
{
|
||||
StartCoroutine(setRespawn(player));
|
||||
}
|
||||
public void Restart(){
|
||||
if(SceneData.localPlayer.GetComponent<SpaceshipController>().dead){
|
||||
SetRespawn(SceneData.localPlayer);
|
||||
}else{
|
||||
Debug.LogError("You aren't dead, you can't restart unless you are dead.");
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator setRespawn(GameObject player)
|
||||
{
|
||||
if (isServer)
|
||||
{
|
||||
player.SetActive(false);
|
||||
yield return new WaitForSeconds(3);
|
||||
// if (isServer)
|
||||
// {
|
||||
// player.SetActive(false);
|
||||
// yield return new WaitForSeconds(0.1f);
|
||||
Vector3 RespawnPoint = NetworkManager.startPositions[Random.Range(0, NetworkManager.startPositions.Count - 1)].position;
|
||||
|
||||
player.GetComponent<SpaceshipController>().Respawn(RespawnPoint);
|
||||
}
|
||||
else
|
||||
{
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
yield return new WaitForSeconds(1);
|
||||
}
|
||||
// }
|
||||
}
|
||||
|
||||
Vector3 getRandomPositionOnMap()
|
||||
@@ -174,10 +181,12 @@ public class MinigameManager : NetworkBehaviour
|
||||
|
||||
public GameObject loadingScreen;
|
||||
public async void BackToBase(){
|
||||
loadingScreen.SetActive(true);
|
||||
await Task.Delay(1000);
|
||||
// loadingScreen.SetActive(true);
|
||||
// await Task.Delay(1000);
|
||||
LoadingScreen.instance.LoadLevel("GameScene");
|
||||
NetworkManager.singleton.StopClient();
|
||||
SceneManager.LoadScene("MinigameMenu");
|
||||
// SceneManager.LoadScene("GameScene");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -7,7 +7,12 @@ using TMPro;
|
||||
public class SceneDataHolder : MonoBehaviour
|
||||
{
|
||||
public Transform trailCollidersParent;
|
||||
[Header("Deadscreen")]
|
||||
public GameObject deadScreen;
|
||||
public GameObject xpEarnings;
|
||||
public GameObject metalEarnings;
|
||||
public TMP_Text survivalTimeTxt;
|
||||
public TMP_Text mostTimeTxt;
|
||||
public EventTrigger boostBtn;
|
||||
public TMP_Text timerTxt;
|
||||
void Awake()
|
||||
@@ -21,6 +26,16 @@ public class SceneDataHolder : MonoBehaviour
|
||||
public void OnBoostDown(){
|
||||
SceneData.OnBoostDown.Invoke();
|
||||
}
|
||||
|
||||
public void ShowDeadscreen(int xpEarned, int metalEarned, double survivalTime){
|
||||
deadScreen.SetActive(true);
|
||||
xpEarnings.SetActive(xpEarned > 0); metalEarnings.SetActive(metalEarned > 0);
|
||||
xpEarnings.GetComponentInChildren<TMP_Text>().text = xpEarned.ToString();
|
||||
metalEarnings.GetComponentInChildren<TMP_Text>().text = metalEarned.ToString();
|
||||
survivalTimeTxt.text = SceneData.SecondsToText(survivalTime);
|
||||
mostTimeTxt.text = SceneData.SecondsToText(DBmanager.MostTime);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -31,10 +46,13 @@ public static class SceneData{
|
||||
public static UnityEvent OnBoostDown = new UnityEvent();
|
||||
public static UnityEvent OnBoostUp = new UnityEvent();
|
||||
|
||||
public static void SetTimerTxt(double seconds){
|
||||
public static void SetTimerTxt(double seconds){
|
||||
holder.timerTxt.text = SecondsToText(seconds);
|
||||
}
|
||||
|
||||
public static string SecondsToText(double seconds){
|
||||
int secs = ((int)(seconds % 60));
|
||||
int mins = Mathf.FloorToInt((float)(seconds/60));
|
||||
|
||||
holder.timerTxt.text = mins + ":"+ secs.ToString("00");
|
||||
return mins + ":"+ secs.ToString("00");
|
||||
}
|
||||
}
|
||||
@@ -6,10 +6,16 @@ using UnityEngine.UI;
|
||||
|
||||
public class SpaceshipController : NetworkBehaviour
|
||||
{
|
||||
public SpriteRenderer playerImg;
|
||||
public SkinsData skins;
|
||||
[SyncVar(hook=nameof(OnSkinChanged))]
|
||||
public string skinName = null;
|
||||
[SyncVar(hook=nameof(OnPnameChanged))]
|
||||
public string pname;
|
||||
[SyncVar(hook=nameof(OnScoresChanged))]
|
||||
public int Scores;
|
||||
[SyncVar(hook=nameof(OnKillsChanged))]
|
||||
public int Kills;
|
||||
[SyncVar(hook=nameof(OnTrailTimeChanged))]
|
||||
public float trailTime;
|
||||
public float trailIncrementRate = 0.5f;
|
||||
@@ -48,6 +54,20 @@ public class SpaceshipController : NetworkBehaviour
|
||||
pnameTxt.text = newName;
|
||||
}
|
||||
|
||||
[Command]
|
||||
void CmdSetSkin(string newSkin){
|
||||
skinName = newSkin;
|
||||
}
|
||||
|
||||
void OnSkinChanged(string oldSkin, string newSkin){
|
||||
ChangeSkin(newSkin);
|
||||
}
|
||||
|
||||
void ChangeSkin(string name){
|
||||
Sprite newSprite = SkinManagerHelper.getSkinSprite(name,skins);
|
||||
playerImg.sprite = newSprite;
|
||||
}
|
||||
|
||||
|
||||
void OnScoresChanged(int oldScores, int newScores){
|
||||
Debug.Log($"Add scores { newScores - oldScores}, (total: {newScores})");
|
||||
@@ -89,21 +109,40 @@ public class SpaceshipController : NetworkBehaviour
|
||||
}
|
||||
[SyncVar]
|
||||
double startedTime = 0;
|
||||
|
||||
void ResetStats(){
|
||||
startedXp = DBmanager.Xp;
|
||||
startedMetal = DBmanager.Metal;
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
scaleMultiplier=1;
|
||||
if (isLocalPlayer)
|
||||
{
|
||||
ResetStats();
|
||||
if (joystick == null) { joystick = FindObjectOfType<Joystick>(); }
|
||||
FindObjectOfType<CameraFollower>().SetTarget(transform);
|
||||
string myName = PlayerPrefs.GetString("username");
|
||||
SceneData.localPlayer = gameObject;
|
||||
SceneData.OnBoostDown.AddListener(OnBoostDown);
|
||||
SceneData.OnBoostUp.AddListener(OnBoostUp);
|
||||
//Set username
|
||||
if(isServer){pname=myName;}else{
|
||||
CmdSetPname(myName);
|
||||
}
|
||||
|
||||
//Set Skin
|
||||
if(!DBmanager.SkinsPurchased.Contains(SkinShopManager.GetEquipedSkin())){
|
||||
//False skin purchase
|
||||
}else{
|
||||
if(isServer){
|
||||
skinName = SkinShopManager.GetEquipedSkin();
|
||||
}else{
|
||||
CmdSetSkin(SkinShopManager.GetEquipedSkin());
|
||||
}
|
||||
}
|
||||
|
||||
pnameTxt.text = myName;
|
||||
pnameTxt.gameObject.SetActive(false);
|
||||
|
||||
@@ -139,7 +178,11 @@ public class SpaceshipController : NetworkBehaviour
|
||||
CmdCheatKills();
|
||||
}
|
||||
// Debug.Log(startedTime-NetworkTime.time);
|
||||
SceneData.SetTimerTxt((startedTime ==0) ? 0 :NetworkTime.time - startedTime);
|
||||
double survivalTime = (startedTime ==0) ? 0 :NetworkTime.time - startedTime;
|
||||
if(DBmanager.MostTime < (int)survivalTime){
|
||||
DBmanager.SetMostTime((int)survivalTime);
|
||||
}
|
||||
SceneData.SetTimerTxt(survivalTime);
|
||||
}
|
||||
//Simulate on both client and server
|
||||
if (isLocalPlayer || isServer)
|
||||
@@ -401,12 +444,13 @@ public class SpaceshipController : NetworkBehaviour
|
||||
|
||||
public void TrailCollided(Collider2D hit){
|
||||
if(!isServer){
|
||||
Debug.Log("Got hit : " + hit.name);
|
||||
// Debug.Log("This cannot run on client, That's illegal!"); // <-- What this log says
|
||||
return;
|
||||
}
|
||||
|
||||
SpaceshipController deadPlayer = hit.GetComponent<SpaceshipController>();
|
||||
|
||||
Debug.Log("got hit by player? : " + deadPlayer != null);
|
||||
if(deadPlayer!=null && !deadPlayer.dead){ // <-- okay we killed someone | KILLCODE
|
||||
deadPlayer.Die(pname);
|
||||
Debug.Log($"{pname} killed {deadPlayer.pname}");
|
||||
@@ -415,10 +459,24 @@ public class SpaceshipController : NetworkBehaviour
|
||||
}
|
||||
|
||||
void OnKill(){
|
||||
Kills++;
|
||||
Scores+= 10; //TODO: Need to change Scores on kills?
|
||||
scaleMultiplier+=0.05f;
|
||||
OnScaleChanged(scaleMultiplier,scaleMultiplier);
|
||||
IncreaseTrail(trailIncrementRate);
|
||||
RpcOnKill();
|
||||
}
|
||||
|
||||
[ClientRpc]
|
||||
void RpcOnKill(){
|
||||
|
||||
}
|
||||
|
||||
void OnKillsChanged(int oldVal, int newVal){
|
||||
if(isLocalPlayer){
|
||||
Debug.Log("Show kills for " + newVal);
|
||||
KillText.Show(newVal);
|
||||
}
|
||||
}
|
||||
|
||||
void IncreaseTrail(float rate){
|
||||
@@ -464,13 +522,18 @@ public class SpaceshipController : NetworkBehaviour
|
||||
scaleMultiplier=1;
|
||||
dead=true;
|
||||
Scores=0;
|
||||
Kills=0;
|
||||
startedTime=NetworkTime.time;
|
||||
trailTime = 1;
|
||||
trailMgr.trail.time = trailTime;
|
||||
RpcDie(killer);
|
||||
MinigameManager.instance.SetRespawn(gameObject);
|
||||
gameObject.SetActive(false);
|
||||
//MinigameManager.instance.SetRespawn(gameObject);
|
||||
}
|
||||
|
||||
private int startedXp;
|
||||
private int startedMetal;
|
||||
|
||||
[ClientRpc]
|
||||
public void RpcDie(string killer){
|
||||
Debug.Log($"{killer} killed {pname} : isItMe? -> {isLocalPlayer}");
|
||||
@@ -478,11 +541,26 @@ public class SpaceshipController : NetworkBehaviour
|
||||
gameObject.SetActive(false);
|
||||
if(isLocalPlayer){
|
||||
//TODO: Death message goes here
|
||||
SceneData.holder.deadScreen.SetActive(true);
|
||||
SceneData.holder.ShowDeadscreen(DBmanager.Xp - startedXp, DBmanager.Metal - startedMetal, NetworkTime.time - startedTime);
|
||||
}
|
||||
}
|
||||
|
||||
public void Respawn(Vector3 respawnPoint){
|
||||
Debug.Log("Respawning " + pname);
|
||||
|
||||
if(isServer){
|
||||
respawn(respawnPoint);
|
||||
}else{
|
||||
CmdRespawn(respawnPoint);
|
||||
}
|
||||
}
|
||||
|
||||
[Command]
|
||||
void CmdRespawn(Vector3 respawnPoint){
|
||||
respawn(respawnPoint);
|
||||
}
|
||||
|
||||
public void respawn(Vector3 respawnPoint){
|
||||
dead=false;
|
||||
trailMgr.trail.emitting =false;
|
||||
trailMgr.trail.Clear();
|
||||
@@ -506,6 +584,7 @@ public class SpaceshipController : NetworkBehaviour
|
||||
|
||||
if(isLocalPlayer){
|
||||
SceneData.holder.deadScreen.SetActive(false);
|
||||
ResetStats();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,30 +4,7 @@ using UnityEngine;
|
||||
|
||||
public class SpaceshipSkin : MonoBehaviour
|
||||
{
|
||||
public SpriteRenderer playerImg;
|
||||
public SkinsData skinsData;
|
||||
private bool initialized=false;
|
||||
void Update()
|
||||
{
|
||||
if(!DBmanager.LoggedIn) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(!initialized){
|
||||
|
||||
//Validate the ownership of skin here
|
||||
if(!DBmanager.SkinsPurchased.Contains(SkinShopManager.GetEquipedSkin())){
|
||||
return; //False skin purchase
|
||||
}
|
||||
|
||||
Sprite newSprite = SkinManagerHelper.getSkinSprite(SkinShopManager.GetEquipedSkin(),skinsData);
|
||||
if(newSprite==null){return;}
|
||||
|
||||
playerImg.sprite = newSprite;
|
||||
|
||||
initialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class SkinManagerHelper{
|
||||
|
||||
@@ -17,7 +17,7 @@ public class TrailMgr : MonoBehaviour
|
||||
|
||||
// Update is called once per frame
|
||||
void Update(){
|
||||
#if PLATFORM_ANDROID
|
||||
// #if PLATFORM_ANDROID
|
||||
positions = new Vector3[trail.positionCount];
|
||||
int length = trail.GetPositions(positions);
|
||||
if(length > trailsPool.Count){
|
||||
@@ -38,13 +38,14 @@ public class TrailMgr : MonoBehaviour
|
||||
trailsPool[i].SetActive(false);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
// #endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void OnColliderHit(Collider2D hit){
|
||||
controller.TrailCollided(hit);
|
||||
Debug.Log("Got hit:" +hit.name);
|
||||
}
|
||||
|
||||
void OnValidate(){
|
||||
|
||||
93
Assets/Game/Scripts/RegionManager.cs
Normal file
93
Assets/Game/Scripts/RegionManager.cs
Normal file
@@ -0,0 +1,93 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using TMPro;
|
||||
public class RegionManager : MonoBehaviour
|
||||
{
|
||||
public static RegionManager instance;
|
||||
[SerializeField]
|
||||
public static RegionServerData selectedServer;
|
||||
[SerializeField]
|
||||
public List<RegionServerData> servers = new List<RegionServerData>();
|
||||
public Button btn_auto;
|
||||
public TMP_Text[] selectedServerTxts;
|
||||
void Start()
|
||||
{
|
||||
UpdateServerData();
|
||||
|
||||
UpdateSelectedRegion();
|
||||
|
||||
foreach(RegionServerData server in servers){
|
||||
server.btn_select.onClick.AddListener(()=>{SetRegionOverride(server.name);});
|
||||
}
|
||||
btn_auto.onClick.AddListener(()=>{ SetRegionOverride(""); });
|
||||
}
|
||||
|
||||
public void UpdateServerData(){
|
||||
StartCoroutine(updatePing());
|
||||
}
|
||||
|
||||
IEnumerator updatePing(){
|
||||
for(int i=0;i < servers.Count;i++){
|
||||
WaitForSeconds f = new WaitForSeconds(0.05f);
|
||||
Ping p = new Ping(servers[i].ip);
|
||||
while (p.isDone == false)
|
||||
{
|
||||
yield return f;
|
||||
}
|
||||
|
||||
servers[i].ping = p.time;
|
||||
foreach(TMPro.TMP_Text pingTxt in servers[i].pingTxts){
|
||||
pingTxt.text = p.time + " ms";
|
||||
pingTxt.color = (p.time < 90) ? Color.green : (p.time < 140) ? Color.yellow : Color.red;
|
||||
}
|
||||
if(selectedServer == null || (!PlayerPrefs.HasKey("regionOverride") && selectedServer.ping > p.time)){ // <-- Auto select best server
|
||||
selectedServer = servers[i];
|
||||
}
|
||||
}
|
||||
yield return new WaitForSeconds(2);
|
||||
StartCoroutine(updatePing());
|
||||
UpdateSelectedRegion();
|
||||
}
|
||||
|
||||
public void SetRegionOverride(string region){
|
||||
Debug.Log("Setting region override to " + region);
|
||||
foreach(RegionServerData server in servers){
|
||||
if(server.name == region){
|
||||
PlayerPrefs.SetString("regionOverride", region);
|
||||
PlayerPrefs.Save();
|
||||
selectedServer = server;
|
||||
UpdateSelectedRegion();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//No server found for the said region
|
||||
PlayerPrefs.DeleteKey("regionOverride");
|
||||
PlayerPrefs.Save();
|
||||
|
||||
UpdateSelectedRegion();
|
||||
}
|
||||
|
||||
void UpdateSelectedRegion(){
|
||||
btn_auto.interactable = PlayerPrefs.HasKey("regionOverride");
|
||||
|
||||
foreach(RegionServerData server in servers){
|
||||
server.btn_select.interactable = PlayerPrefs.HasKey("regionOverride") ? (server.name != PlayerPrefs.GetString("regionOverride")): true;
|
||||
}
|
||||
|
||||
foreach(TMP_Text selectedServerTxt in selectedServerTxts){
|
||||
selectedServerTxt.text = PlayerPrefs.HasKey("regionOverride") ? PlayerPrefs.GetString("regionOverride") : "Auto - " + (selectedServer == null ? "/" : selectedServer.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class RegionServerData{
|
||||
public string name;
|
||||
public string ip;
|
||||
public int ping;
|
||||
public TMPro.TMP_Text[] pingTxts;
|
||||
public Button btn_select;
|
||||
}
|
||||
11
Assets/Game/Scripts/RegionManager.cs.meta
Normal file
11
Assets/Game/Scripts/RegionManager.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b3c586ba0306111edb3dbf6fa10f8e46
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user