-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTextCollectionBank.cs
66 lines (52 loc) · 1.9 KB
/
TextCollectionBank.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using Sirenix.OdinInspector;
using RotaryHeart.Lib.SerializableDictionary;
namespace AltSalt.Maestro
{
[CreateAssetMenu(menuName = "Maestro/Content Extension/Text Collection Bank")]
[Serializable]
public class TextCollectionBank : ScriptableObject
{
[SerializeField]
[Header("Text Collection Bank")]
public TextCollection textCollection;
[ShowInInspector]
[ReadOnly]
[InfoBox("Active text family should be set by TextTools in editor or a ModifyHandler at runtime")]
private TextFamily _activeTextFamily;
private TextFamily activeTextFamily
{
get => _activeTextFamily;
set => _activeTextFamily = value;
}
public bool GetText(string key, out string text)
{
activeTextFamily = TextFamily.GetActiveTextFamily(textCollection.Keys.ToList());
if (activeTextFamily != null) {
if (textCollection[activeTextFamily].ContainsKey(key)) {
text = textCollection[activeTextFamily][key];
return true;
}
text =
$"Key {key} not found under priority text family {activeTextFamily.name} in text collection {this.name}";
return false;
}
text = $"No active text families found in {this.name}";
return false;
}
#if UNITY_EDITOR
public string GetActiveTextFamilyName()
{
return activeTextFamily != null ? activeTextFamily.name : "No active text family.";
}
#endif
}
[Serializable]
public class TextCollection : SerializableDictionaryBase<TextFamily, TextNodes> { }
[Serializable]
public class TextNodes : SerializableDictionaryBase<string, string> { }
}