blob: 83a3ad7fd2dec8db43a8cf0c0a75f634c1d1ea34 (
plain)
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
|
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;
}
}
|