Make splash text use json (haven't done attributes yet)

This commit is contained in:
Lncvrt committed 2026-02-21 14:38:26 -07:00
1 parent b7d2a7c0ac
commit c865677098
2 files changed
+9 -5

No files matched your search

+3 -1
View File
@@ -26,7 +26,9 @@ public class MenuScript : MonoBehaviour {
updateText.text = "Latest: Loading...";
}
}
if (PresistentData.randomSplashes != null) splashText.text = PresistentData.randomSplashes[Random.Range(0, PresistentData.randomSplashes.Length)];
if (PresistentData.randomSplashes != null && PresistentData.randomSplashes.Count != 0) {
splashText.text = PresistentData.randomSplashes[Random.Range(0, PresistentData.randomSplashes.Count)]["content"].ToString();
}
copyrightText.text = $"\\u00A9 {System.DateTime.Now.Year} Lncvrt. All rights reserved.";
if (!Application.isMobilePlatform && !Application.isEditor) {
+6 -4
View File
@@ -1,4 +1,5 @@
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;
using TMPro;
using UnityEngine;
using UnityEngine.Networking;
@@ -8,7 +9,7 @@ public class PresistentData : MonoBehaviour {
public static PresistentData Instance;
private bool loadingDone = false;
public static string latestVersion = null;
public static string[] randomSplashes = null;
public static JArray randomSplashes = new();
private async void Awake() {
if (Instance != null && Instance != this) {
@@ -48,13 +49,14 @@ public class PresistentData : MonoBehaviour {
request.SetRequestHeader("ClientVersion", Application.version);
request.SetRequestHeader("ClientPlatform", Application.platform.ToString());
await request.SendWebRequest();
randomSplashes = request.downloadHandler.text.Split("\n") ?? null;
randomSplashes = JArray.Parse(request.downloadHandler.text);
if (
SceneManager.GetActiveScene().name == "MainMenu" &&
randomSplashes != null &&
GameObject.Find("Canvas/SplashText").TryGetComponent<TextMeshProUGUI>(out var text)
GameObject.Find("Canvas/SplashText").TryGetComponent<TextMeshProUGUI>(out var text) &&
randomSplashes.Count != 0
) {
text.text = randomSplashes[Random.Range(0, randomSplashes.Length)];
text.text = randomSplashes[Random.Range(0, randomSplashes.Count)]["content"].ToString();
}
}
}