using System; using UnityEngine; using UnityEngine.Events; public class NameTextBehaviour : MonoBehaviour { public static NameTextBehaviour Instance; public TextBox nameSource; public void Start() { NameTextBehaviour.Instance = this; this.nameSource.SetText(SaveManager.PlayerName, ""); this.nameSource.OnFocusLost.AddListener(new UnityAction(this.UpdateName)); } public void UpdateName() { if (this.ShakeIfInvalid()) { return; } SaveManager.PlayerName = this.nameSource.text; } public static bool IsValidName(string text) { if (text == null || text.Length == 0) { return false; } if (text.Equals("Enter Name", StringComparison.OrdinalIgnoreCase)) { return false; } if (BlockedWords.ContainsWord(text)) { return false; } bool result = false; for (int i = 0; i < text.Length; i++) { if (text[i] != ' ') { result = true; } } return result; } public bool ShakeIfInvalid() { if (!NameTextBehaviour.IsValidName(this.nameSource.text)) { base.StartCoroutine(Effects.Shake(this.nameSource.transform, 0.75f, 0.25f)); return true; } return false; } }