From 8a7a6f9424aaa100eaf6fc5c0c089266de3b5a97 Mon Sep 17 00:00:00 2001 From: baletiballo <75846481+baletiballo@users.noreply.github.com> Date: Tue, 25 Feb 2025 09:19:48 +0100 Subject: [PATCH] Trying to make scroll loading async. Doesn't quite work yet --- Assets/Scripts/GlobalBehaviour.cs | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/Assets/Scripts/GlobalBehaviour.cs b/Assets/Scripts/GlobalBehaviour.cs index 8fb3b5ca..934e34cf 100644 --- a/Assets/Scripts/GlobalBehaviour.cs +++ b/Assets/Scripts/GlobalBehaviour.cs @@ -55,7 +55,7 @@ public static GlobalBehaviour Instance /// <summary> Default Setting for all JSONConvert operations </summary> public static JsonSerializerSettings JsonConvertDefaultSettings = new() { MaxDepth = 256 }; - private void Awake() + private void Start() { Instance = this; if (Instance != this) @@ -64,8 +64,12 @@ private void Awake() JsonConvert.DefaultSettings = () => JsonConvertDefaultSettings; DontDestroyOnLoad(this); - GetScrollsfromServer(); - GetContextfromServer(); + + InitiateScrolls = GetScrollsfromServer(); + StartCoroutine(InitiateScrolls); + + InitiateContext = GetContextfromServer(); + StartCoroutine(InitiateContext); } //TODO: Move where appropiate @@ -75,12 +79,8 @@ private void Awake() public static IEnumerator InitiateScrolls = IEnumeratorExtensions.yield_break; public static bool AttemptScrollList = true; //false; - private void GetScrollsfromServer() + private IEnumerator GetScrollsfromServer() { - StartCoroutine(InitiateScrolls = _GetScrollsfromServer()); - - IEnumerator _GetScrollsfromServer() - { //Try /scroll/listall endpoint when scroll/list is not working //UnityWebRequest request = UnityWebRequest.Get(CommunicationEvents.ServerAdress + "/scroll/listall"); //Postman-Echo-Mock @@ -141,7 +141,7 @@ IEnumerator _GetScrollsfromServer() System.DateTime parseTime = System.DateTime.UtcNow; List<Scroll> _AvailableScrolls = JsonConvert.DeserializeObject<List<Scroll>>(jsonString); - + System.DateTime processTime = System.DateTime.UtcNow; AvailableScrolls = new(); foreach (Scroll scroll in _AvailableScrolls) @@ -156,20 +156,15 @@ IEnumerator _GetScrollsfromServer() $"Processing\t{(System.DateTime.UtcNow - processTime).TotalMilliseconds}ms"); yield break; - } } - + public static FactRecorder Context = new(); public static IEnumerator InitiateContext = IEnumeratorExtensions.yield_break; public static bool ContextLoaded = false; public static bool AttemptContextLoad = true; //false; - private void GetContextfromServer() + private IEnumerator GetContextfromServer() { - StartCoroutine(InitiateContext = _GetContextfromServer()); - - IEnumerator _GetContextfromServer() - { ContextLoaded = false; System.DateTime requestTime = System.DateTime.UtcNow; @@ -275,7 +270,6 @@ IEnumerator _GetContextfromServer() ContextLoaded = true; yield break; - } } /// <summary> -- GitLab