blob: 91b8c96f0657a4e49d6b8b5747c3ce16927b5cd4 (
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
using Sirenix.OdinInspector;
using UnityEngine;
public class ChatFilter : MonoBehaviour
{
[TextArea]
public string enterData;
public string category;
public static ChatFilter instance;
public ChatFilterInstance[] filters;
private void Awake()
{
instance = this;
}
[Button]
private void EnterData()
{
string[] array = enterData.Replace('"', ' ').Trim().Split(',');
ChatFilterInstance chatFilterInstance = null;
for (int i = 0; i < filters.Length; i++)
{
if (filters[i].category == category)
{
chatFilterInstance = filters[i];
break;
}
}
if (chatFilterInstance == null)
{
UnityEngine.Debug.LogError("No valid category target!");
return;
}
for (int j = 0; j < array.Length; j++)
{
array[j] = array[j].Trim();
array[j] = array[j].ToUpper();
if (array[j] == "")
{
continue;
}
bool flag = false;
for (int k = 0; k < chatFilterInstance.words.Count; k++)
{
if (chatFilterInstance.words[k] == array[j])
{
flag = true;
}
}
if (!flag)
{
chatFilterInstance.words.Add(array[j]);
}
}
}
public string FilterMessage(string message)
{
for (int i = 0; i < filters.Length; i++)
{
for (int j = 0; j < filters[i].words.Count; j++)
{
if (message.ToUpper().Contains(filters[i].words[j]))
{
return filters[i].replacement;
}
}
}
return message;
}
}
|