Fiber
Fibers Lighweight Cooperative Multitasking
FramesWorker.cs
1 // Copyright 2018 (C) paul@marrington.net http://www.askowl.net/unity-packages
2 
3 // ReSharper disable ClassNeverInstantiated.Local, ClassNeverInstantiated.Global
4 
5 using System;
6 using UnityEngine;
7 
8 namespace Askowl {
9  public partial class Fiber {
10  /// <a href="http://bit.ly/2DDvloH">Wait a specific count of Update, FixedUpdate or LateUpdate frames</a>
11  public Fiber SkipFrames(int framesToSkip) =>
12  AddAction(_ => FrameWorker.Instance.Load(fiber: this, data: Time.frameCount + framesToSkip));
13 
14  /// <a href="http://bit.ly/2DDvloH">Wait a specific count of Update, FixedUpdate or LateUpdate frames - value passed by function return to</a>
15  public Fiber SkipFrames(Func<Fiber, int> getter) =>
16  AddAction(_ => FrameWorker.Instance.Load(fiber: this, data: Time.frameCount + getter(this)));
17 
18  private class FrameWorker : Worker<int> {
19  // ReSharper disable once MemberHidesStaticFromOuterClass
20  public static FrameWorker Instance => Cache<FrameWorker>.Instance;
21  protected override void Recycle() => Cache<FrameWorker>.Dispose(this);
22 
23  protected override int CompareTo(Worker other) => Seed.CompareTo((other as FrameWorker)?.Seed);
24 
25  public override bool NoMore => (Seed - 3) >= Time.frameCount;
26 
27  public override void Step() => Dispose();
28 
29  protected override bool Prepare() => true;
30  }
31  }
32 }
Definition: Emitter.cs:6
void Dispose()
Cleans up Fiber before it goes into the recycling
Definition: Fiber.cs:34
static Fiber Instance
Precompile an instance of a fiber command
Definition: Fiber.cs:22
Fiber SkipFrames(int framesToSkip)
Wait a specific count of Update, FixedUpdate or LateUpdate frames