finish add summy loading task UI

This commit is contained in:
NguyenVanDat
2025-12-16 16:53:01 +07:00
parent 5a0ad3ad4f
commit 717eef48cb
7 changed files with 63 additions and 29 deletions
@@ -82,7 +82,6 @@ namespace BrewMonster
{
progressBar.value = progress;
percentText.text = $"{Mathf.RoundToInt(progress * 100f)}%";
Debug.LogError($"UpdateUI: {progress}");
}
public void SetLoadingText(string content)
{
@@ -4,6 +4,7 @@ using ModelRenderer.Scripts.GameData;
using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;
using System.Threading;
using CSNetwork.GPDataType;
using Cysharp.Threading.Tasks;
using UnityEngine;
@@ -80,7 +81,7 @@ namespace BrewMonster.Scripts.Task
m_pEleDataMan = pMan;
}
public async UniTask<bool> LoadTasksFromPack(string szPackPath, bool bLoadDescript, Action<float> onProgress)
public async UniTask<bool> LoadTasksFromPack(string szPackPath, bool bLoadDescript, Action<float> onProgress, CancellationToken token)
{
// //TaskInterface::WriteLog(0, 0, 2, "LoadPack begin");
// BMLogger.Log("[Dat]- szPackPath: " + szPackPath);
@@ -177,8 +178,7 @@ namespace BrewMonster.Scripts.Task
try
{
// background thread
loadedTasks = await UniTask.RunOnThreadPool(() => LoadTasksFromPack_Internal(szPackPath, onProgress)
);
loadedTasks = await UniTask.RunOnThreadPool(() => LoadTasksFromPack_Internal(szPackPath, onProgress, token), cancellationToken: token);
}
catch (Exception e)
{
@@ -228,7 +228,7 @@ namespace BrewMonster.Scripts.Task
return true;
}
private static List<ATaskTempl> LoadTasksFromPack_Internal(string szPackPath, Action<float> onProgress)
private static List<ATaskTempl> LoadTasksFromPack_Internal(string szPackPath, Action<float> onProgress, CancellationToken token)
{
long readBytes = 0;
var tasks = new List<ATaskTempl>();
@@ -251,12 +251,16 @@ namespace BrewMonster.Scripts.Task
uint[] pOffs =
AAssit.ReadArrayFromBinary<uint>(fs, (int)tph.item_count, ref readBytes);
float percent = 80.0f / tph.item_count;
float percentCount = 0;
const float TASK_LOAD_WEIGHT = 0.8f;
for (int i = 0; i < tph.item_count; i++)
{
percentCount += percent;
onProgress?.Invoke(percentCount);
if (token.IsCancellationRequested)
return tasks;
// percentCount += percent;
float progress =
((i + 1) / (float)tph.item_count) * TASK_LOAD_WEIGHT;
onProgress?.Invoke(progress);
// LoadingSceneController.Instance.UpdateUI(percentCount);
// Debug.LogError($"pc: {percentCount}");
fs.Seek(pOffs[i], SeekOrigin.Begin);
@@ -4,6 +4,7 @@ using PerfectWorld.Scripts.Task;
using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;
using System.Threading;
using BrewMonster.UI;
using CSNetwork;
using Cysharp.Threading.Tasks;
@@ -309,6 +310,14 @@ namespace BrewMonster.Scripts.Task
}
public class CECTaskInterface : TaskInterface
{
private CancellationTokenSource _cts;
public void Despose()
{
_cts?.Cancel();
_cts?.Dispose();
}
public int GetCurHistoryStageIndex()
{
return EC_Game.GetGameRun().GetCurStageIndex() + 1;
@@ -374,6 +383,7 @@ namespace BrewMonster.Scripts.Task
int iFinishedListLen, byte[] pFinishedTimeListBuf, int iFinishedTimeListLen,
byte[] pFinishedCountListBuf, int iFinishedCountListLen, byte[] pStorageTaskListBuf, int iStorageTaskListLen)
{
_cts = new CancellationTokenSource();
// basic argument check (converted from ASSERT)
if (pActiveListBuf == null || pFinishedListBuf == null || pFinishedTimeListBuf == null || pFinishedCountListBuf == null)
{
@@ -432,30 +442,24 @@ namespace BrewMonster.Scripts.Task
string task_data_path = Path.Combine(Application.streamingAssetsPath, "data/tasks.data");
await pTaskMan.LoadTasksFromPack(task_data_path, true, (x) =>
{
LoadingSceneController.Instance.UpdateUI(x);
});
UniTask.Void(async () =>
{
await UniTask.SwitchToMainThread();
LoadingSceneController.Instance.UpdateUI(x);
});
}, _cts.Token);
}
#else
string task_data_path = Path.Combine(Application.streamingAssetsPath, "data/tasks.data");
await pTaskMan.LoadTasksFromPack(task_data_path, true);
#endif
SceneLoader.LoadingProgress = 60;
LoadingSceneController.Instance.UpdateUI(0.7f);
LoadingSceneController.Instance.SetLoadingText("Loading NPC From Pack");
var task_npc_path = Path.Combine(Application.streamingAssetsPath, "data/task_npc.data");
await pTaskMan.LoadNPCInfoFromPack(task_npc_path);
Debug.LogError("End LoadNPCInfoFromPack");
SceneLoader.LoadingProgress = 75;
LoadingSceneController.Instance.UpdateUI(0.75f);
LoadingSceneController.Instance.SetLoadingText("Verify Dynamic Tasks Pack");
var dyn_tasks_path = Path.Combine(Application.streamingAssetsPath, "data/dyn_tasks.data");
await pTaskMan.VerifyDynTasksPack(dyn_tasks_path);
InitActiveTaskList();
SceneLoader.LoadingProgress = 100;
LoadingSceneController.Instance.UpdateUI(1f);
LoadingSceneController.Instance.SetLoadingText("Entering Game");
SceneLoader.SceneLoadProcess = SceneLoadProcess.EndLoading;
LoadingSceneController.Instance.ShowLoadingScene(false);
+22 -1
View File
@@ -2,6 +2,7 @@ using System;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Threading;
using BrewMonster.Scripts.Task.UI;
using BrewMonster.Scripts.UI;
using ModelRenderer.Scripts.Common;
@@ -20,6 +21,15 @@ namespace BrewMonster.Scripts.Task
[Header("Test Dlg Award Options")]
[SerializeField] private uint _awardItemID = 1001;
[SerializeField] private KeyCode _awardkey = KeyCode.A;
private CancellationTokenSource _cts;
protected override void Awake()
{
base.Awake();
_cts = new CancellationTokenSource();
}
private void OnValidate()
{
@@ -29,6 +39,17 @@ namespace BrewMonster.Scripts.Task
LoadTaskData();
}
}
private void OnDestroy()
{
_cts?.Cancel();
_cts?.Dispose();
}
private void OnApplicationQuit()
{
_cts?.Cancel();
}
private void Update()
{
@@ -109,7 +130,7 @@ namespace BrewMonster.Scripts.Task
}
string path = Path.Combine(Application.streamingAssetsPath, "data/tasks.data");
WasLoadTaskData = await m_pTaskMan.LoadTasksFromPack(path, true,(x)=>{});
WasLoadTaskData = await m_pTaskMan.LoadTasksFromPack(path, true,(x)=>{},_cts.Token);
}
[ContextMenu("Test Size")]
+5 -5
View File
@@ -65,7 +65,7 @@ MonoBehaviour:
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_text: 23%
m_text: 0%
m_isRightToLeft: 0
m_fontAsset: {fileID: 11400000, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}
m_sharedMaterial: {fileID: 2180264, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}
@@ -245,7 +245,7 @@ RectTransform:
m_Father: {fileID: 1679867140415222605}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 10, y: 0}
m_Pivot: {x: 0.5, y: 0.5}
@@ -519,7 +519,7 @@ MonoBehaviour:
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_text: 23%
m_text: Loading
m_isRightToLeft: 0
m_fontAsset: {fileID: 11400000, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}
m_sharedMaterial: {fileID: 2180264, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}
@@ -747,8 +747,8 @@ RectTransform:
m_Children: []
m_Father: {fileID: 7448874308476023876}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 1, y: 0}
m_AnchorMax: {x: 1, y: 1}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 20, y: 20}
m_Pivot: {x: 0.5, y: 0.5}
+2 -2
View File
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:5ec8cc7321de76e090597eb869ffde3b1340d1fe396c26bfdf2e09554b70d54b
size 200521903
oid sha256:49dbfd3874bae260b9c7fd5cf05128cc19c395f788f891042d55cebf488bb41f
size 200520845
+6
View File
@@ -156,6 +156,12 @@ namespace BrewMonster
public EC_Inventory PackInventory => m_packInventory;
public EC_Inventory EquipInventory => m_equipInventory;
public EC_Inventory TaskInventory => m_taskInventory;
private void OnApplicationQuit()
{
if(m_pTaskInterface!=null)
m_pTaskInterface.Despose();
}
public bool IsMeleeing()
{