using System; using UnityEngine; using System.Linq; using Sirenix.OdinInspector; using System.Threading.Tasks; using System.Collections.Generic; using HGR.Core.Singletons; using Newtonsoft.Json; public class TWS_SplashScreenStoryManager : Singleton { //=================================================== // FIELDS //=================================================== [SerializeField] GameObject storyDataPrefab; [Space] // [ReadOnly] // [SerializeField] TWS_Story_Data storyMetaData = new(); [ReadOnly] [SerializeField] List storyDialogueData = new(); [ReadOnly] [SerializeField] List storyDialogueBGData = new(); //=================================================== // PRIVATE FIELDS //=================================================== private Action callB; private Transform UI_Parent; public async void LoadStoryData(Action callback, Transform UI_Parent) { callB = callback; this.UI_Parent = UI_Parent; storyDialogueData = new(); storyDialogueData = await APIRequestHandler.GetRequestList(GameData.Instance.SplashDataAPI); if(storyDialogueData != null && storyDialogueData.Count > 0) LoadBackgroundImageData(); // else // SkipSplash(); }//LoadStoryData() end private async void LoadBackgroundImageData() { storyDialogueBGData = new(); IEnumerable tasks = storyDialogueData.Select(async x => { TWS_DialogueBG_Data dialogueBG = new() { dialogueData = x, dialogueBG = await APIRequestHandler.GetMedia(GameData.Instance.SplashImageAPI + x.splashImageName) }; storyDialogueBGData.Add(dialogueBG); }); await Task.WhenAll(tasks); CreateStoryDataObject(); }//LoadBackgroundImageData() end private void CreateStoryDataObject() { PI_StoryData storyData = Instantiate(storyDataPrefab, UI_Parent).GetComponent(); storyData.SetStoryData(storyDialogueBGData); callB(storyData.gameObject); }//CreateStoryDataObject() end }//class end