From 3a71761d1845a9f3c0f9e7546ba199664635554d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillem=20Sunyer=20Cald=C3=BA?= Date: Sun, 12 Jun 2022 23:25:44 +0200 Subject: [PATCH] Added methods --- Runtime/Loading/Services/ILoadingService.cs | 3 +- Runtime/Loading/Services/LoadingService.cs | 39 +++++++++++++++------ 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/Runtime/Loading/Services/ILoadingService.cs b/Runtime/Loading/Services/ILoadingService.cs index d82d20d..ce988e1 100644 --- a/Runtime/Loading/Services/ILoadingService.cs +++ b/Runtime/Loading/Services/ILoadingService.cs @@ -11,6 +11,7 @@ public interface ILoadingService void AddBeforeLoading(Func func); void AddAfterLoading(Func func); - void EnqueueLoad(params Func[] func); + void Enqueue(params Func[] functions); + void Enqueue(params Action[] actions); } } diff --git a/Runtime/Loading/Services/LoadingService.cs b/Runtime/Loading/Services/LoadingService.cs index 8f0c4b2..a72e800 100644 --- a/Runtime/Loading/Services/LoadingService.cs +++ b/Runtime/Loading/Services/LoadingService.cs @@ -25,24 +25,41 @@ public void AddBeforeLoading(Func func) afterLoad.Add(func); } - public void EnqueueLoad(params Func[] func) + public void Enqueue(params Func[] functions) { - if(sequencer.Count == 0) + OnStartLoading(); + + foreach (Func 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 before in beforeLoad) - { - sequencer.Play(before.Invoke); - } + private void OnStartLoading() + { + if(sequencer.Count > 0) + { + return; } - foreach (Func toLoad in func) + IsLoading = true; + + sequencer.OnComplete -= OnComplete; + sequencer.OnComplete += OnComplete; + + foreach (Func before in beforeLoad) { - sequencer.Play(toLoad); + sequencer.Play(before.Invoke); } }