From 766cdff5ffa72b65d7f106658d1603f47739b2ba Mon Sep 17 00:00:00 2001 From: chai <215380520@qq.com> Date: Fri, 27 Oct 2023 11:05:14 +0800 Subject: + init --- GameCode/ChatFilter.cs | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 GameCode/ChatFilter.cs (limited to 'GameCode/ChatFilter.cs') diff --git a/GameCode/ChatFilter.cs b/GameCode/ChatFilter.cs new file mode 100644 index 0000000..91b8c96 --- /dev/null +++ b/GameCode/ChatFilter.cs @@ -0,0 +1,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; + } +} -- cgit v1.1-26-g67d0