4 using System.Collections.Generic;
16 [CreateAssetMenu(menuName =
"Managers/Tickertape"), Serializable]
18 [SerializeField]
private bool autoStart =
true;
19 [SerializeField]
private float secondsBetweenFeeds = 0.2f;
20 [SerializeField]
private Quotes quotes =
default;
21 [SerializeField]
private String showing =
default;
22 [SerializeField]
private Trigger showingComplete =
default;
24 private readonly Fifo<string> texts = Fifo<string>.Instance;
25 private List<Quotes> allQuotes;
26 private readonly Map loadedQuotes =
new Map();
29 public int[]
Counts => allQuotes.ConvertAll(q => q.Count).ToArray();
31 protected override void Initialise() {
33 allQuotes =
new List<Quotes>();
38 Selection.activeObject = (quotes as
Object) ??
this;
40 return "Add to the Quotes custom asset in the resource often called 'Content'";
43 string pick() => texts.Pop() ?? ((allQuotes.Count > 0)
44 ? allQuotes[
Random.Range(0, allQuotes.Count)].Pick()
47 showFiber = Fiber.Instance.Begin.Do(_ => showing.Value = pick())
48 .WaitFor(showingComplete.Emitter).WaitFor(secondsBetweenFeeds).Again;
49 if (autoStart)
Show();
53 public void Show() => showFiber.Exit().Go();
54 private Fiber showFiber;
57 public void ShowNext(
string text) => texts.Push(text);
60 public void ShowImmediate(
string text) => showing.Value = text;
63 public void Stop() => showFiber.Exit();
68 if ((moreQuotes ==
default) || (moreQuotes.Count == 0) || loadedQuotes[moreQuotes.name].Found)
return this;
70 loadedQuotes.
Add(moreQuotes.name);
71 allQuotes.
Add(moreQuotes);
int [] Counts
Combined total of all messages that can be served
Manager Custom Asset to serve messages to the marquee
void Show()
Start showing messages from the currently loaded Quote custom assets
Tickertape Clear()
Remove all messages from the list to display
Tickertape Add(Quotes moreQuotes)
Add more messages contained in a Quote custom asset
void Stop()
Stop displaying messages after the current one is done
void ShowNext(string text)
Inject a message to be displayed after the current one has finished
void ShowImmediate(string text)
Inject a message to show right now - removing any half-finished message first