summaryrefslogtreecommitdiff
path: root/WorldlineKeepers/Assets/Scripts/Data/DataManager_Load.cs
blob: bca064af4a3ecbf797d0783334b42003e452256b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using LitJson;
using System;
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
using MovementEffects;

namespace WK.Data
{
    public partial class DataManager : Singleton<DataManager>
    {
        private bool m_IsLoaded = false;
        public bool isLoaded => m_IsLoaded;

        private bool m_IsLoading = false;

        /// <summary>
        /// Òì²½¼ÓÔØÊý¾Ý
        /// </summary>
        /// <returns></returns>
        public CoroutineHandle AsyncLoadAll()
        {
            return Timing.Instance.RunCoroutineOnInstance(CoLoadAllData());
        }

        private IEnumerator<float> CoLoadAllData()
        {
            PreLoad();
            Load_Filelist();
            Load_DefaultStats();
            yield return Timing.WaitForSeconds(StaticDefine.IntervalLoadFile);
            PostLoad();
        }

        private void PreLoad()
        {
            m_IsLoading = true;
        }

        private void PostLoad()
        {
            m_IsLoading = false;
            m_IsLoaded = true;
        }

        private void Load_Filelist()
        {
            TextAsset text = ResourceManager.Instance.LoadAsset<TextAsset>(StaticDefine.FileList);
            string content = text.text;
            CSVReader.ReadDictionary<string, FileDescriptor>(m_Filelist, content, "key");
        }

        private void Load_DefaultStats()
        {
            TextAsset text = ResourceManager.Instance.LoadAsset<TextAsset>(StaticDefine.StatsFilePath);
            string content = text.text;
            CSVReader.ReadDictionary<string, CharacterStatsMetadata>(m_CharacterStatsMetadata, content, "uid");
        }

    }
}