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("资源解压完成");
|
}
|
}
|