三国卡牌客户端基础资源仓库
yyl
2025-04-23 7816f15f2e98a0faa2bdbc50307c7506cbb9a6b7
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Cysharp.Threading.Tasks;
using System.IO;
 
/// <summary>
/// 资源解压状态
/// </summary>
public class ExtractResourcesState : ILaunchState
{
    
    public string StateName => FirstPackLang.Instance.GetText(FirstPackLang.TextIndex.ExtractResources);
    
    public ExtractResourcesState()
    {
        
    }
    
    public async UniTask OnEnter()
    {
        Debug.Log("进入资源解压状态");
        
        // 使用硬编码索引设置当前状态
        LaunchLoadingWin.Instance.SetCurrentState(FirstPackLang.TextIndex.ExtractResources);
        await LaunchLoadingWin.Instance.ShowProgressAsync(0.3f, 0.4f);
    }
    
    public async UniTask<bool> OnExecute()
    {
        Debug.Log("执行资源解压");
        
        // 检查是否需要解压资源
        bool needExtract = CheckIfNeedExtract();
        
        if (needExtract)
        {
            // 更新加载界面提示
            LaunchLoadingWin.Instance.SetTip(FirstPackLang.Instance.GetText(FirstPackLang.TextIndex.ExtractingResources));
            
            
            // 执行资源解压
            await ExtractResources();
            
            // 更新进度
            await LaunchLoadingWin.Instance.ShowProgressAsync(0.5f, 0.5f);
            
        }
        else
        {
            Debug.Log("无需解压资源");
            
            // 更新进度
            LaunchLoadingWin.Instance.SetTip(FirstPackLang.Instance.GetText(FirstPackLang.TextIndex.ResourceCheckComplete));
            await LaunchLoadingWin.Instance.ShowProgressAsync(0.2f, 0.5f);
        }
        
        // 返回true表示该状态已完成,可以进入下一个状态
        return true;
    }
    
    public async UniTask OnExit()
    {
        Debug.Log("退出资源解压状态");
        await UniTask.CompletedTask;
    }
    
    /// <summary>
    /// 检查是否需要解压资源
    /// </summary>
    private bool CheckIfNeedExtract()
    {
        // 这里根据实际情况检查是否需要解压资源
        // 例如,检查特定目录是否存在,或者检查标记文件是否存在
        
        string extractFlagPath = Path.Combine(Application.persistentDataPath, "extracted.flag");
        bool hasExtracted = File.Exists(extractFlagPath);
        
        return !hasExtracted;
    }
    
    /// <summary>
    /// 执行资源解压
    /// </summary>
    private async UniTask ExtractResources()
    {
        // 这里实现资源解压逻辑
        // 例如,从StreamingAssets解压到PersistentDataPath
        
        Debug.Log("开始解压资源...");
        
        // 模拟解压过程
        await UniTask.Delay(1000);
        
        // 创建解压标记文件
        string extractFlagPath = Path.Combine(Application.persistentDataPath, "extracted.flag");
        File.WriteAllText(extractFlagPath, System.DateTime.Now.ToString());
        
        Debug.Log("资源解压完成");
    }
}