Make the latest version request not resend each main menu load

This commit is contained in:
2025-06-05 15:29:51 -07:00
parent 73cf036569
commit 4a1b96d0bf
9 changed files with 380 additions and 29 deletions

View File

@@ -5,25 +5,40 @@ using UnityEngine.UI;
public class LatestVersionText : MonoBehaviour
{
public static LatestVersionText Instance;
public TMP_Text text;
public Button updateButton;
private TMP_Text text;
private string latest = null;
void Awake()
{
text = gameObject.GetComponent<TMP_Text>();
updateButton.onClick.AddListener(() =>
if (Instance != null && Instance != this)
{
Application.OpenURL("https://berrydash.lncvrt.xyz/download");
});
if (Application.platform == RuntimePlatform.WebGLPlayer)
Destroy(gameObject);
return;
}
Instance = this;
DontDestroyOnLoad(gameObject);
if (updateButton != null)
{
text.text = "";
updateButton.onClick.AddListener(() =>
{
Application.OpenURL("https://berrydash.lncvrt.xyz/download");
});
}
}
void Start()
{
if (Application.platform != RuntimePlatform.WebGLPlayer) GetLatestVersion();
RefreshText();
if (Application.platform != RuntimePlatform.WebGLPlayer && latest == null) GetLatestVersion();
}
void OnEnable()
{
RefreshText();
}
async void GetLatestVersion()
@@ -35,14 +50,26 @@ public class LatestVersionText : MonoBehaviour
await request.SendWebRequest();
if (request.result != UnityWebRequest.Result.Success)
{
text.text = "Latest: N/A";
return;
latest = "-1";
}
string response = request.downloadHandler.text;
text.text = "Latest: v" + response;
if (response != Application.version)
else
{
updateButton.gameObject.SetActive(true);
latest = request.downloadHandler.text;
}
RefreshText();
if (latest != Application.version && updateButton != null) updateButton.gameObject.SetActive(true);
}
public void RefreshText()
{
if (text == null) return;
if (Application.platform == RuntimePlatform.WebGLPlayer)
text.text = "";
else if (latest == null)
text.text = "Latest: Loading...";
else if (latest == "-1")
text.text = "Latest: N/A";
else
text.text = "Latest: " + latest;
}
}

View File

@@ -1,12 +1,19 @@
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class MenuScript : MonoBehaviour
{
public Button exitButton;
public TMP_Text updateText;
public Button updateButton;
void Awake()
{
LatestVersionText.Instance.text = updateText;
LatestVersionText.Instance.updateButton = updateButton;
LatestVersionText.Instance.RefreshText();
if (Application.isMobilePlatform || Application.isEditor || Application.platform == RuntimePlatform.WebGLPlayer)
{
exitButton.gameObject.SetActive(false);