4 using System.Text.RegularExpressions;
11 [Serializable]
public sealed
class QuoteSet : Set<string> {
12 [SerializeField, Tooltip(
"Asset with one quote per line (with attribution in brackets at end)")]
13 private TextAsset[] quoteFiles =
default;
17 Fifo<string> choices =
new Fifo<string>();
19 Rtf(choices, Selector.Choices);
21 for (var i = 0; i < quoteFiles.Length; i++) {
22 if (quoteFiles[0] != null) Rtf(choices, quoteFiles[i].text.Split(
'\n'));
25 if (choices.Count > 0) Selector.Choices = choices.ToArray();
29 public int Count => Selector.Choices.Length;
32 public static void Rtf(Fifo<string> to,
string[] from) {
33 for (
int i = 0; i < from.Length; i++) {
34 if (!
string.IsNullOrEmpty(from[i])) to.Push(Rtf(from[i]));
39 public static string Rtf(
string quote) =>
41 input: quote, pattern:
@"^(.*?)\s*\((.*)\)$", evaluator: m =>
42 $
"<b>\"</b><i>{m.Groups[1].Value}</i><b>\"</b> <color=grey>{(m.Groups.Count > 1 ? m.Groups[2].Value : "")}</color>");
46 [CreateAssetMenu(menuName =
"Custom Assets/Constant/Quotes")]
52 if (!EditorApplication.isPlayingOrWillChangePlaymode)
return;
58 public string Pick() => Value.Pick();
61 public static string Rtf(
string quote) =>
QuoteSet.
Rtf(quote);
64 public int Count => Value.Count;
Custom Asset for picking one or a list of quotes - either kept in the asset or as a separate text fil...
static void Rtf(Fifo< string > to, string[] from)
Turn a list of strings into a list of formatted quotes
Base class for a custom asset. Provides getters and setters for the contained value and templates for...
override void BuildSelector()
Class for picking one or a list of quotes - either set in the inspector or in a separate text file...