diff options
| author | Andrew Lee <alee14498@gmail.com> | 2019-08-24 15:24:57 -0400 |
|---|---|---|
| committer | Andrew Lee <alee14498@gmail.com> | 2019-08-24 15:24:57 -0400 |
| commit | 85553832ead1a96f88726cd2b35cb6ff1d8b8cc8 (patch) | |
| tree | 7a2615034462d4296ed09d24038bb4c68107979d /Assets/Packages/Lean/Localization/Scripts/LeanToken.cs | |
| parent | e06acf066171670248b0b644c0eb8f6d895e051e (diff) | |
| download | Unicity-85553832ead1a96f88726cd2b35cb6ff1d8b8cc8.tar.gz Unicity-85553832ead1a96f88726cd2b35cb6ff1d8b8cc8.tar.bz2 Unicity-85553832ead1a96f88726cd2b35cb6ff1d8b8cc8.zip | |
Attempt number 2 on localization
Diffstat (limited to 'Assets/Packages/Lean/Localization/Scripts/LeanToken.cs')
| -rw-r--r-- | Assets/Packages/Lean/Localization/Scripts/LeanToken.cs | 130 |
1 files changed, 130 insertions, 0 deletions
diff --git a/Assets/Packages/Lean/Localization/Scripts/LeanToken.cs b/Assets/Packages/Lean/Localization/Scripts/LeanToken.cs new file mode 100644 index 0000000..c6ca7f8 --- /dev/null +++ b/Assets/Packages/Lean/Localization/Scripts/LeanToken.cs @@ -0,0 +1,130 @@ +using UnityEngine; +using System.Collections.Generic; +using Lean.Common; +#if UNITY_EDITOR +using UnityEditor; + +namespace Lean.Localization +{ + [CustomEditor(typeof(LeanToken))] + public class LeanToken_Inspector : LeanInspector<LeanToken> + { + protected override void DrawInspector() + { + Draw("value"); + } + } +} +#endif + +namespace Lean.Localization +{ + /// <summary>The class stores a token name (e.g. "AGE"), allowing it to be replaced with the token value (e.g. "20"). + /// To use the token in your text, simply include the token name surrounded by braces (e.g. "I am {AGE} years old!")</summary> + [ExecuteInEditMode] + [HelpURL(LeanLocalization.HelpUrlPrefix + "LeanToken")] + [AddComponentMenu(LeanLocalization.ComponentPathPrefix + "Token")] + public class LeanToken : LeanSource + { + [SerializeField] + private string value; + + [System.NonSerialized] + private HashSet<LeanLocalizedBehaviour> behaviours; + + [System.NonSerialized] + private static HashSet<LeanLocalizedBehaviour> tempBehaviours = new HashSet<LeanLocalizedBehaviour>(); + + public string Value + { + set + { + if (this.value != value) + { + this.value = value; + + if (behaviours != null) + { + tempBehaviours.Clear(); + + tempBehaviours.UnionWith(behaviours); + + foreach (var behaviour in tempBehaviours) + { + behaviour.UpdateLocalization(); + } + } + } + } + + get + { + return value; + } + } + + public void SetValue(float value) + { + Value = value.ToString(); + } + + public void SetValue(string value) + { + Value = value; + } + + public void SetValue(int value) + { + Value = value.ToString(); + } + + public void Register(LeanLocalizedBehaviour behaviour) + { + if (behaviour != null) + { + if (behaviours == null) + { + behaviours = new HashSet<LeanLocalizedBehaviour>(); + } + + behaviours.Add(behaviour); + } + } + + public void Unregister(LeanLocalizedBehaviour behaviour) + { + if (behaviours != null) + { + behaviours.Remove(behaviour); + } + } + + public void UnregisterAll() + { + if (behaviours != null) + { + foreach (var behaviour in behaviours) + { + behaviour.Unregister(this); + } + + behaviours.Clear(); + } + } + + public override void Compile(string primaryLanguage, string secondaryLanguage) + { + if (string.IsNullOrEmpty(name) == false) + { + LeanLocalization.CurrentTokens.Add(name, this); + } + } + + protected override void OnDisable() + { + base.OnDisable(); + + UnregisterAll(); + } + } +}
\ No newline at end of file |
