public void Unregister(LeanLocalizedBehaviour behaviour) { if (behaviours != null) { behaviours.Remove(behaviour); } }
public void Register(LeanLocalizedBehaviour behaviour) { if (behaviour != null) { if (behaviours == null) { behaviours = new HashSet <LeanLocalizedBehaviour>(); } behaviours.Add(behaviour); } }
/// <summary>This returns Text with all tokens substituted using the LeanLocalization.Tokens list.</summary> public static string FormatText(string rawText, string currentText, LeanLocalizedBehaviour behaviour) { if (string.IsNullOrEmpty(currentText) == true) { currentText = rawText; } if (rawText != null) { current.Length = 0; buffer.Length = 0; tokens.Clear(); for (var i = 0; i < rawText.Length; i++) { var rawChar = rawText[i]; if (rawChar == '{') { if (buffering == true) { buffering = false; buffer.Length = 0; } else { buffering = true; } } else if (rawChar == '}') { if (buffering == true) { if (buffer.Length > 0) { var token = default(LeanToken); if (buffer.Length > 0 && LeanLocalization.CurrentTokens.TryGetValue(buffer.ToString(), out token) == true) // TODO: Avoid ToString here? { current.Append(token.Value); tokens.Add(token); } else { current.Append('{').Append(buffer).Append('}'); } buffer.Length = 0; } buffering = false; } } else { if (buffering == true) { buffer.Append(rawChar); } else { current.Append(rawChar); } } } if (Match(currentText, current) == false) { if (behaviour != null) { behaviour.UnregisterAll(); } for (var i = tokens.Count - 1; i >= 0; i--) { var token = tokens[i]; token.Register(behaviour); behaviour.Register(token); } return(current.ToString()); } } return(currentText); }