From f6c25e118027a6493c10b7b8eddfefc6bcc5a293 Mon Sep 17 00:00:00 2001 From: geondo55 <102933884+geondo55@users.noreply.github.com> Date: Mon, 30 Jun 2025 10:41:26 +0900 Subject: [PATCH 1/2] =?UTF-8?q?InputFieldValidator=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Scripts/Studio/UI/InputField.meta | 8 ++++++++ .../InputField/EnglishInputFieldValidator.cs | 15 ++++++++++++++ .../EnglishInputFieldValidator.cs.meta | 2 ++ .../UI/InputField/InputFieldValidator.cs | 20 +++++++++++++++++++ .../UI/InputField/InputFieldValidator.cs.meta | 2 ++ .../NumericDotInputFieldValidator.cs | 15 ++++++++++++++ .../NumericDotInputFieldValidator.cs.meta | 2 ++ .../InputField/NumericInputFieldValidator.cs | 15 ++++++++++++++ .../NumericInputFieldValidator.cs.meta | 2 ++ 9 files changed, 81 insertions(+) create mode 100644 Assets/Scripts/Studio/UI/InputField.meta create mode 100644 Assets/Scripts/Studio/UI/InputField/EnglishInputFieldValidator.cs create mode 100644 Assets/Scripts/Studio/UI/InputField/EnglishInputFieldValidator.cs.meta create mode 100644 Assets/Scripts/Studio/UI/InputField/InputFieldValidator.cs create mode 100644 Assets/Scripts/Studio/UI/InputField/InputFieldValidator.cs.meta create mode 100644 Assets/Scripts/Studio/UI/InputField/NumericDotInputFieldValidator.cs create mode 100644 Assets/Scripts/Studio/UI/InputField/NumericDotInputFieldValidator.cs.meta create mode 100644 Assets/Scripts/Studio/UI/InputField/NumericInputFieldValidator.cs create mode 100644 Assets/Scripts/Studio/UI/InputField/NumericInputFieldValidator.cs.meta diff --git a/Assets/Scripts/Studio/UI/InputField.meta b/Assets/Scripts/Studio/UI/InputField.meta new file mode 100644 index 00000000..e0272e9f --- /dev/null +++ b/Assets/Scripts/Studio/UI/InputField.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 01921bb75417df441acf53da6992d294 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Studio/UI/InputField/EnglishInputFieldValidator.cs b/Assets/Scripts/Studio/UI/InputField/EnglishInputFieldValidator.cs new file mode 100644 index 00000000..262b38dc --- /dev/null +++ b/Assets/Scripts/Studio/UI/InputField/EnglishInputFieldValidator.cs @@ -0,0 +1,15 @@ +namespace Studio.UI +{ + public class EnglishInputFieldValidator : InputFieldValidator + { + protected override char ValidateInput(string text, int charIndex, char addedChar) + { + if ((addedChar >= 'A' && addedChar <= 'Z') || (addedChar >= 'a' && addedChar <= 'z')) + { + return addedChar; + } + + return '\0'; + } + } +} diff --git a/Assets/Scripts/Studio/UI/InputField/EnglishInputFieldValidator.cs.meta b/Assets/Scripts/Studio/UI/InputField/EnglishInputFieldValidator.cs.meta new file mode 100644 index 00000000..eacd99c4 --- /dev/null +++ b/Assets/Scripts/Studio/UI/InputField/EnglishInputFieldValidator.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 5cfbc3180aa0867408d6521529e5cac4 \ No newline at end of file diff --git a/Assets/Scripts/Studio/UI/InputField/InputFieldValidator.cs b/Assets/Scripts/Studio/UI/InputField/InputFieldValidator.cs new file mode 100644 index 00000000..be493a07 --- /dev/null +++ b/Assets/Scripts/Studio/UI/InputField/InputFieldValidator.cs @@ -0,0 +1,20 @@ +using TMPro; +using UnityEngine; +using XRLib.UI; + +namespace Studio.UI +{ + [RequireComponent(typeof(TMP_InputField))] + public abstract class InputFieldValidator : UIBase + { + public TMP_InputField inputField; + + void Awake() + { + inputField = GetComponent(); + inputField.onValidateInput += ValidateInput; + } + + protected abstract char ValidateInput(string text, int charIndex, char addedChar); + } +} diff --git a/Assets/Scripts/Studio/UI/InputField/InputFieldValidator.cs.meta b/Assets/Scripts/Studio/UI/InputField/InputFieldValidator.cs.meta new file mode 100644 index 00000000..4adf497b --- /dev/null +++ b/Assets/Scripts/Studio/UI/InputField/InputFieldValidator.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 03b149247b27102428968cb5df010774 \ No newline at end of file diff --git a/Assets/Scripts/Studio/UI/InputField/NumericDotInputFieldValidator.cs b/Assets/Scripts/Studio/UI/InputField/NumericDotInputFieldValidator.cs new file mode 100644 index 00000000..bd325dff --- /dev/null +++ b/Assets/Scripts/Studio/UI/InputField/NumericDotInputFieldValidator.cs @@ -0,0 +1,15 @@ +namespace Studio.UI +{ + public class NumericDotInputFieldValidator : InputFieldValidator + { + protected override char ValidateInput(string text, int charIndex, char addedChar) + { + if (char.IsDigit(addedChar) || addedChar == '.') + { + return addedChar; + } + + return '\0'; + } + } +} diff --git a/Assets/Scripts/Studio/UI/InputField/NumericDotInputFieldValidator.cs.meta b/Assets/Scripts/Studio/UI/InputField/NumericDotInputFieldValidator.cs.meta new file mode 100644 index 00000000..2339ace3 --- /dev/null +++ b/Assets/Scripts/Studio/UI/InputField/NumericDotInputFieldValidator.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 318ad98d4b818194da00221ee69745cd \ No newline at end of file diff --git a/Assets/Scripts/Studio/UI/InputField/NumericInputFieldValidator.cs b/Assets/Scripts/Studio/UI/InputField/NumericInputFieldValidator.cs new file mode 100644 index 00000000..1fb91d1c --- /dev/null +++ b/Assets/Scripts/Studio/UI/InputField/NumericInputFieldValidator.cs @@ -0,0 +1,15 @@ +namespace Studio.UI +{ + public class NumericInputFieldValidator : InputFieldValidator + { + protected override char ValidateInput(string text, int charIndex, char addedChar) + { + if (char.IsDigit(addedChar)) + { + return addedChar; + } + + return '\0'; + } + } +} diff --git a/Assets/Scripts/Studio/UI/InputField/NumericInputFieldValidator.cs.meta b/Assets/Scripts/Studio/UI/InputField/NumericInputFieldValidator.cs.meta new file mode 100644 index 00000000..a28da226 --- /dev/null +++ b/Assets/Scripts/Studio/UI/InputField/NumericInputFieldValidator.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 6f95cd07bc2246945965157693796194 \ No newline at end of file -- 2.48.1.windows.1 From 6c4aa2fb76cdd4770891e1468a5298ff932bf1af Mon Sep 17 00:00:00 2001 From: geondo55 <102933884+geondo55@users.noreply.github.com> Date: Mon, 30 Jun 2025 14:52:22 +0900 Subject: [PATCH 2/2] =?UTF-8?q?=EC=9E=85=EB=A0=A5=20=EA=B0=92=20=EC=9C=A0?= =?UTF-8?q?=ED=9A=A8=EC=84=B1=20=EA=B2=80=EC=82=AC=20=EA=B8=B0=EB=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Prefabs/UI/PRF_InputTopicItem.prefab | 14 ++++++++++ .../Prefabs/UI/PRF_MQTTConnectionItem.prefab | 28 +++++++++++++++++++ .../Studio/UI/Elements/UI_MQTTConnection.cs | 14 ++++++++-- 3 files changed, 54 insertions(+), 2 deletions(-) diff --git a/Assets/Resources/Prefabs/UI/PRF_InputTopicItem.prefab b/Assets/Resources/Prefabs/UI/PRF_InputTopicItem.prefab index c93805cb..d739036b 100644 --- a/Assets/Resources/Prefabs/UI/PRF_InputTopicItem.prefab +++ b/Assets/Resources/Prefabs/UI/PRF_InputTopicItem.prefab @@ -251,6 +251,7 @@ GameObject: - component: {fileID: 6549079342170574329} - component: {fileID: 8772786093202997941} - component: {fileID: 8501740602063653259} + - component: {fileID: 1292074844791121958} m_Layer: 0 m_Name: InputField_Topic m_TagString: Untagged @@ -417,6 +418,19 @@ MonoBehaviour: isAlert: 0 m_InputValidator: {fileID: 0} m_ShouldActivateOnSelect: 1 +--- !u!114 &1292074844791121958 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 5041442594409627906} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 5cfbc3180aa0867408d6521529e5cac4, type: 3} + m_Name: + m_EditorClassIdentifier: + inputField: {fileID: 0} --- !u!1 &5562854965458769467 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Resources/Prefabs/UI/PRF_MQTTConnectionItem.prefab b/Assets/Resources/Prefabs/UI/PRF_MQTTConnectionItem.prefab index eec069f9..ad888827 100644 --- a/Assets/Resources/Prefabs/UI/PRF_MQTTConnectionItem.prefab +++ b/Assets/Resources/Prefabs/UI/PRF_MQTTConnectionItem.prefab @@ -942,6 +942,7 @@ GameObject: - component: {fileID: 1294127454145776225} - component: {fileID: 451971561218025839} - component: {fileID: 4531525069399822389} + - component: {fileID: 3782032704331303633} m_Layer: 0 m_Name: InputField_Port m_TagString: Untagged @@ -1108,6 +1109,19 @@ MonoBehaviour: isAlert: 0 m_InputValidator: {fileID: 0} m_ShouldActivateOnSelect: 1 +--- !u!114 &3782032704331303633 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2436487502178914535} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 6f95cd07bc2246945965157693796194, type: 3} + m_Name: + m_EditorClassIdentifier: + inputField: {fileID: 0} --- !u!1 &3156314644122750241 GameObject: m_ObjectHideFlags: 0 @@ -2566,6 +2580,7 @@ GameObject: - component: {fileID: 6749344978886352018} - component: {fileID: 2032036743421240120} - component: {fileID: 7558723559091652677} + - component: {fileID: 8720815484175462745} m_Layer: 0 m_Name: InputField_Domain m_TagString: Untagged @@ -2732,3 +2747,16 @@ MonoBehaviour: isAlert: 0 m_InputValidator: {fileID: 0} m_ShouldActivateOnSelect: 1 +--- !u!114 &8720815484175462745 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 8829135613240903342} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 318ad98d4b818194da00221ee69745cd, type: 3} + m_Name: + m_EditorClassIdentifier: + inputField: {fileID: 0} diff --git a/Assets/Scripts/Studio/UI/Elements/UI_MQTTConnection.cs b/Assets/Scripts/Studio/UI/Elements/UI_MQTTConnection.cs index d1d00857..45eee9e5 100644 --- a/Assets/Scripts/Studio/UI/Elements/UI_MQTTConnection.cs +++ b/Assets/Scripts/Studio/UI/Elements/UI_MQTTConnection.cs @@ -60,13 +60,23 @@ namespace Studio.UI onMQTTTest?.Invoke(); var domain = InputField_Domain.text; - var port = int.Parse(InputField_Port.text); + if (string.IsNullOrWhiteSpace(domain)) + { + return; + } + if (!int.TryParse(InputField_Port.text, out var port)) + { + return; + } List topics = new(); foreach (UI_InputTopicItem item in inputTopicItems) { var topic = item.InputField_Topic.text; - topics.Add(topic); + if (!string.IsNullOrWhiteSpace(topic)) + { + topics.Add(topic); + } } var tmpClient = new TemporaryMQTTClient(domain, port, topics, OnTopicTest, OnConnectedClient, OnErrorClient); panel_MQTTTestResult.Open(domain, port.ToString()); -- 2.48.1.windows.1