You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 lines
2.3 KiB
C#

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<TWS_SplashScreenStoryManager>
{
//===================================================
// FIELDS
//===================================================
[SerializeField] GameObject storyDataPrefab;
[Space]
// [ReadOnly]
// [SerializeField] TWS_Story_Data storyMetaData = new();
[ReadOnly]
[SerializeField] List<TWS_StoryDialogue_Data> storyDialogueData = new();
[ReadOnly]
[SerializeField] List<TWS_DialogueBG_Data> storyDialogueBGData = new();
//===================================================
// PRIVATE FIELDS
//===================================================
private Action<GameObject> callB;
private Transform UI_Parent;
public async void LoadStoryData(Action<GameObject> callback, Transform UI_Parent)
{
callB = callback;
this.UI_Parent = UI_Parent;
storyDialogueData = new();
storyDialogueData = await APIRequestHandler.GetRequestList<TWS_StoryDialogue_Data>(GameData.Instance.SplashDataAPI);
if(storyDialogueData != null && storyDialogueData.Count > 0)
LoadBackgroundImageData();
// else
// SkipSplash();
}//LoadStoryData() end
private async void LoadBackgroundImageData()
{
storyDialogueBGData = new();
IEnumerable<Task> 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<PI_StoryData>();
storyData.SetStoryData(storyDialogueBGData);
callB(storyData.gameObject);
}//CreateStoryDataObject() end
}//class end