using System; using System.Threading.Tasks; using UnityEngine; namespace Mogafa.Unity.Common.Contexts { public class TimesTask : TimesTaskAbstract { private readonly Func func; internal TimesTask(int delay, int interval, int maxTimes, Func func) : base(delay, interval, maxTimes) { if (func == null) { Debug.LogError("The parameter func cannot be null."); throw new InvalidOperationException("The parameter func cannot be null."); } this.func = func; } protected override Task ExecuteInternal() { return func.Invoke(); } } public class TimesTask : TimesTaskAbstract { private readonly Func func; private readonly T arg; internal TimesTask(int delay, int interval, int maxTimes, Func func, T arg) : base(delay, interval, maxTimes) { if (func == null) { Debug.LogError("The parameter func cannot be null."); throw new InvalidOperationException("The parameter func cannot be null."); } this.arg = arg; this.func = func; } protected override Task ExecuteInternal() { return func(arg); } } public class TimesTask : TimesTaskAbstract { private readonly Func func; private readonly T1 arg1; private readonly T2 arg2; internal TimesTask(int delay, int interval, int maxTimes, Func func, T1 arg1, T2 arg2) : base(delay, interval, maxTimes) { if (func == null) { Debug.LogError("The parameter func cannot be null."); throw new InvalidOperationException("The parameter func cannot be null."); } this.arg1 = arg1; this.arg2 = arg2; this.func = func; } protected override Task ExecuteInternal() { return func(arg1, arg2); } } public class TimesTask : TimesTaskAbstract { private readonly Func func; private readonly T1 arg1; private readonly T2 arg2; private readonly T3 arg3; internal TimesTask(int delay, int interval, int maxTimes, Func func, T1 arg1, T2 arg2, T3 arg3) : base(delay, interval, maxTimes) { if (func == null) { Debug.LogError("The parameter func cannot be null."); throw new InvalidOperationException("The parameter func cannot be null."); } this.arg1 = arg1; this.arg2 = arg2; this.arg3 = arg3; this.func = func; } protected override Task ExecuteInternal() { return func(arg1, arg2, arg3); } } public class TimesTask : TimesTaskAbstract { private readonly Func func; private readonly T1 arg1; private readonly T2 arg2; private readonly T3 arg3; private readonly T4 arg4; internal TimesTask(int delay, int interval, int maxTimes, Func func, T1 arg1, T2 arg2, T3 arg3, T4 arg4) : base(delay, interval, maxTimes) { if (func == null) { Debug.LogError("The parameter func cannot be null."); throw new InvalidOperationException("The parameter func cannot be null."); } this.arg1 = arg1; this.arg2 = arg2; this.arg3 = arg3; this.arg4 = arg4; this.func = func; } protected override Task ExecuteInternal() { return func(arg1, arg2, arg3, arg4); } } }