Exemple #1
0
        public void OnGUI()
        {
            GUILayout.Label($"Create {typeof(T).Name}:");

            GUILayout.Space(25);
            GUILayout.Label("Name:");

            GUI.SetNextControlName("namefield");
            _AssetName = EditorGUILayout.TextField(_AssetName, GUILayout.ExpandWidth(true));

            if (GUILayout.Button("Create Asset") || KeyPressed(KeyCode.Return))
            {
                _ShowFileExistsMessage = AssetUtil.Exists(_FolderPath, _AssetName);
                if (!_ShowFileExistsMessage)
                {
                    CreateAndClose();
                }
            }

            if (KeyPressed(KeyCode.Escape))
            {
                Close();
            }

            if (_ShowFileExistsMessage && IsLayoutOrRepaint())
            {
                EditorGUILayout.LabelField(ERR_FILE_EXISTS, _RichTextStyle);
            }

            if (_SelectField)
            {
                EditorGUI.FocusTextInControl("namefield");
                _SelectField = false;
            }
        }
        public void OnGUI()
        {
            GUILayout.Label($"Create {typeof(T).Name}:", _CenteredLabelStyle);

            GUILayout.FlexibleSpace();

            if (AssetUtil.Exists(_FolderPath, _AssetName))
            {
                GUILayout.Label(ERR_FILE_EXISTS, _RedLabelStyle);
            }

            GUILayout.BeginHorizontal();
            GUILayout.Label("Name:");

            GUI.SetNextControlName("namefield");
            var newAssetName = EditorGUILayout.TextField(_AssetName, GUILayout.ExpandWidth(true));

            if (!newAssetName.Equals(_AssetName))
            {
                Repaint();
                _AssetName = newAssetName;
            }

            GUILayout.EndHorizontal();


            if (GUILayout.Button("Create Asset") || KeyPressed(KeyCode.Return))
            {
                if (!AssetUtil.Exists(_FolderPath, _AssetName))
                {
                    CreateAndClose();
                }
            }

            if (KeyPressed(KeyCode.Escape))
            {
                Close();
            }

            if (_SelectField)
            {
                EditorGUI.FocusTextInControl("namefield");
                _SelectField = false;
            }
        }