Skip to content

Commit

Permalink
Added methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillemsc committed Jun 12, 2022
1 parent 9c9d847 commit 3a71761
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
3 changes: 2 additions & 1 deletion Runtime/Loading/Services/ILoadingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public interface ILoadingService
void AddBeforeLoading(Func<CancellationToken, Task> func);
void AddAfterLoading(Func<CancellationToken, Task> func);

void EnqueueLoad(params Func<CancellationToken, Task>[] func);
void Enqueue(params Func<CancellationToken, Task>[] functions);
void Enqueue(params Action[] actions);
}
}
39 changes: 28 additions & 11 deletions Runtime/Loading/Services/LoadingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,41 @@ public void AddBeforeLoading(Func<CancellationToken, Task> func)
afterLoad.Add(func);
}

public void EnqueueLoad(params Func<CancellationToken, Task>[] func)
public void Enqueue(params Func<CancellationToken, Task>[] functions)
{
if(sequencer.Count == 0)
OnStartLoading();

foreach (Func<CancellationToken, Task> function in functions)
{
IsLoading = true;
sequencer.Play(function);
}
}

sequencer.OnComplete -= OnComplete;
sequencer.OnComplete += OnComplete;
public void Enqueue(params Action[] actions)
{
OnStartLoading();

foreach (Action action in actions)
{
sequencer.Play(action);
}
}

foreach (Func<CancellationToken, Task> before in beforeLoad)
{
sequencer.Play(before.Invoke);
}
private void OnStartLoading()
{
if(sequencer.Count > 0)
{
return;
}

foreach (Func<CancellationToken, Task> toLoad in func)
IsLoading = true;

sequencer.OnComplete -= OnComplete;
sequencer.OnComplete += OnComplete;

foreach (Func<CancellationToken, Task> before in beforeLoad)
{
sequencer.Play(toLoad);
sequencer.Play(before.Invoke);
}
}

Expand Down

0 comments on commit 3a71761

Please sign in to comment.