You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
1.5 KiB
C#
65 lines
1.5 KiB
C#
3 weeks ago
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using UnityEngine;
|
||
|
using UnityEngine.UI;
|
||
|
|
||
|
public class TWS_GameDataLoadingStateMachine : MonoBehaviour
|
||
|
{
|
||
|
public TWS_IGameDataLoadingTask currentTask;
|
||
|
|
||
|
public List<MonoBehaviour> tasks;
|
||
|
|
||
|
int currentTaskIndex = 0;
|
||
|
|
||
|
// Initialize with the first state
|
||
|
private void Start()
|
||
|
{
|
||
|
ChangeState(tasks[currentTaskIndex] as TWS_IGameDataLoadingTask);
|
||
|
}
|
||
|
|
||
|
// Change to a new state
|
||
|
public void ChangeState(TWS_IGameDataLoadingTask newState)
|
||
|
{
|
||
|
if (currentTask != null)
|
||
|
{
|
||
|
currentTask.OnTaskFinished();
|
||
|
}
|
||
|
|
||
|
currentTask = newState;
|
||
|
|
||
|
if (currentTask != null)
|
||
|
{
|
||
|
TWS_Delegates.TriggerTaskStatusChanged(currentTask.TaskName);
|
||
|
|
||
|
currentTask.OnTaskStarted();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
float value = 0;
|
||
|
// Update is called once per frame
|
||
|
void Update()
|
||
|
{
|
||
|
if (currentTask != null)
|
||
|
{
|
||
|
value = currentTask.TaskProgress;
|
||
|
|
||
|
TWS_Delegates.TriggerTaskProgressUpdated((currentTaskIndex + value) / tasks.Count);
|
||
|
|
||
|
if (value >= 1)
|
||
|
{
|
||
|
currentTaskIndex++;
|
||
|
|
||
|
if(currentTaskIndex < tasks.Count)
|
||
|
{
|
||
|
ChangeState(tasks[currentTaskIndex] as TWS_IGameDataLoadingTask);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
ChangeState(null);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|
||
|
}
|
||
|
}
|