UI update 02
This commit is contained in:
@@ -17,6 +17,8 @@ public sealed class DailyTaskService : MonoBehaviour
|
||||
}
|
||||
|
||||
private const float OnlineDurationFlushStepSeconds = 5f;
|
||||
private const string GameplaySceneName = "gameplay_gameplay";
|
||||
private const string MainUiSceneName = "UI_UI";
|
||||
|
||||
private readonly Queue<DailyTaskEventData> pendingEvents = new Queue<DailyTaskEventData>();
|
||||
private readonly Dictionary<string, userTasksPool.TaskDefinition> definitionById = new Dictionary<string, userTasksPool.TaskDefinition>(StringComparer.Ordinal);
|
||||
@@ -28,6 +30,8 @@ public sealed class DailyTaskService : MonoBehaviour
|
||||
private bool initialized;
|
||||
private bool appFocused = true;
|
||||
private float pendingOnlineDurationSeconds;
|
||||
private bool isGameplayDurationTracking;
|
||||
private float gameplayDurationRealtimeStart;
|
||||
|
||||
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
|
||||
private static void Bootstrap()
|
||||
@@ -90,6 +94,7 @@ public sealed class DailyTaskService : MonoBehaviour
|
||||
if (!hasFocus)
|
||||
{
|
||||
FlushPendingOnlineDuration();
|
||||
FlushGameplayDuration();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,12 +103,14 @@ public sealed class DailyTaskService : MonoBehaviour
|
||||
if (pauseStatus)
|
||||
{
|
||||
FlushPendingOnlineDuration();
|
||||
FlushGameplayDuration();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnApplicationQuit()
|
||||
{
|
||||
FlushPendingOnlineDuration();
|
||||
FlushGameplayDuration();
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
@@ -111,6 +118,7 @@ public sealed class DailyTaskService : MonoBehaviour
|
||||
if (Instance == this)
|
||||
{
|
||||
FlushPendingOnlineDuration();
|
||||
FlushGameplayDuration();
|
||||
SceneManager.sceneLoaded -= OnSceneLoaded;
|
||||
}
|
||||
}
|
||||
@@ -327,9 +335,18 @@ public sealed class DailyTaskService : MonoBehaviour
|
||||
|
||||
private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
|
||||
{
|
||||
if (string.Equals(scene.name, "UI_UI", StringComparison.OrdinalIgnoreCase))
|
||||
if (string.Equals(scene.name, MainUiSceneName, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
DailyTaskEventHub.ReportLogin();
|
||||
TryReportDailyLogin();
|
||||
}
|
||||
|
||||
if (string.Equals(scene.name, GameplaySceneName, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
BeginGameplayDurationTracking();
|
||||
}
|
||||
else
|
||||
{
|
||||
FlushGameplayDuration();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -382,6 +399,7 @@ public sealed class DailyTaskService : MonoBehaviour
|
||||
saveData.dateKey = todayKey;
|
||||
saveData.dateStamp = effectiveTodayStamp;
|
||||
saveData.refreshUsedCount = 0;
|
||||
saveData.loginReportedToday = false;
|
||||
saveData.accumulatedProgress = new List<DailyTaskAccumulatedProgress>();
|
||||
saveData.uniqueIntProgress = new List<DailyTaskUniqueIntProgress>();
|
||||
GenerateDailyTasks();
|
||||
@@ -524,6 +542,57 @@ public sealed class DailyTaskService : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
private void TryReportDailyLogin()
|
||||
{
|
||||
EnsureTodayTasks();
|
||||
if (saveData == null || saveData.loginReportedToday)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
saveData.loginReportedToday = true;
|
||||
ReportEvent(new DailyTaskEventData
|
||||
{
|
||||
taskType = userTasksPool.TaskType.Login,
|
||||
amount = 1f
|
||||
});
|
||||
}
|
||||
|
||||
private void BeginGameplayDurationTracking()
|
||||
{
|
||||
if (isGameplayDurationTracking)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
isGameplayDurationTracking = true;
|
||||
gameplayDurationRealtimeStart = Time.realtimeSinceStartup;
|
||||
}
|
||||
|
||||
private void FlushGameplayDuration()
|
||||
{
|
||||
if (!isGameplayDurationTracking)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
float now = Time.realtimeSinceStartup;
|
||||
float elapsed = Mathf.Max(0f, now - gameplayDurationRealtimeStart);
|
||||
isGameplayDurationTracking = false;
|
||||
gameplayDurationRealtimeStart = 0f;
|
||||
|
||||
if (elapsed <= 0f)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ReportEvent(new DailyTaskEventData
|
||||
{
|
||||
taskType = userTasksPool.TaskType.GameDuration,
|
||||
amount = elapsed
|
||||
});
|
||||
}
|
||||
|
||||
private bool ApplyEventToTrackedProgress(DailyTaskEventData eventData)
|
||||
{
|
||||
switch (eventData.taskType)
|
||||
|
||||
Reference in New Issue
Block a user