【Unityエディタ拡張】未入力でエラーダイアログを表示する
2019-09-22
Unityエディタ拡張でインプットフィールドを作成し,未入力の場合インプットフィールドを赤くし,そのまま決定ボタンを押された場合は更にエラーダイアログを表示する方法のメモ
Environment
- Unity2019.1.12f1
- Windows10 64bit
Methods
たれ
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 |
//Sample.cs using UnityEditor; using UnityEngine; public class Sample : EditorWindow { private static string NAME; static Sample SampleWindow; private int _selectedTabNumber; [MenuItem("MyTool/Sample")] static void Open() { if (SampleWindow == null) { SampleWindow = CreateInstance<Sample>(); } SampleWindow.Show(); } void OnGUI() { //Description EditorGUILayout.LabelField("Name (require)"); //InputField if (NAME == string.Empty || NAME == null) { GUI.backgroundColor = Color.red; } else { GUI.backgroundColor = Color.white; } NAME = EditorGUILayout.TextField(NAME); //EnterButton if (GUILayout.Button("Enter")) { Debug.Log("Button Clicked"); if (NAME == string.Empty || NAME == null) { EditorUtility.DisplayDialog("Error", "Require name", "Close"); } else { Debug.Log("Done"); //完了時の処理をここに入れる } } } } |