Example #1
0
        /// <summary>
        /// 创建脚本枚举配置
        /// </summary>
        /// <param name="soundConfig"></param>
        /// <param name="path"></param>
        private void CreateCSConfig(SoundConfig soundConfig, string path)
        {
            string audioConfig = "";

            CreateEnum(soundConfig._voiceList, ref audioConfig, soundConfig._voiceEnumType);
            audioConfig += "\n";
            CreateEnum(soundConfig._soundList, ref audioConfig, soundConfig._soundEnumType);
            string config = "using System.ComponentModel;" + "\n"
                            + "namespace " + soundConfig._nameSpace + "\n"
                            + "{" + "\n"
                            + audioConfig
                            + "\n"
                            + "}";

            File.WriteAllText(path, config);
            AssetDatabase.Refresh();
        }
Example #2
0
        private bool _isOtherLanguage = false;          //是否其他语言
        public override void OnInspectorGUI()
        {
            serializedObject.Update();
            SoundConfig soundConfig = target as SoundConfig;

            soundConfig._savePath = EditorGUILayout.TextField("生成的枚举类存放的Assets下文件夹路径", soundConfig._savePath);
            if (GUILayout.Button("生成枚举配置"))
            {
                if (string.IsNullOrEmpty(soundConfig._fileName) || string.IsNullOrEmpty(soundConfig._nameSpace))
                {
                    EditorUtility.DisplayDialog("警告", "脚本名或命名空间未填写", "知道了");
                    return;
                }
                string path = AssetDatabase.GetAssetOrScenePath(Selection.activeObject);
                if (string.IsNullOrEmpty(soundConfig._savePath))
                {
                    path = Application.dataPath + path.Substring(path.IndexOf("/"));
                    path = Path.GetDirectoryName(path);
                }
                else
                {
                    path = Application.dataPath + "/" + soundConfig._savePath;
                }
                path += "/" + soundConfig._fileName + ".cs";
                if (File.Exists(path) && EditorUtility.DisplayDialog("警告", "已存在该配置,是否覆盖:" + path, "是的", "取消")) //显示对话框
                {
                    CreateCSConfig(soundConfig, path);
                }
                else
                {
                    CreateCSConfig(soundConfig, path);
                }
            }
            soundConfig._fileName  = EditorGUILayout.TextField("脚本名", soundConfig._fileName);
            soundConfig._nameSpace = EditorGUILayout.TextField("命名空间", soundConfig._nameSpace);
            _selectType            = GUILayout.Toolbar(_selectType, _typeButtons);
            List <SoundConfig.Config> scList;

            _isOtherLanguage = false;
            switch (_selectType)
            {
            case 0:
                EditorGUILayout.LabelField("枚举名", soundConfig._voiceEnumType);
                scList = soundConfig._voiceList;
                break;

            case 1:
                EditorGUILayout.LabelField("枚举名", soundConfig._soundEnumType);
                scList = soundConfig._soundList;
                break;

            default:
                scList = soundConfig._soundList;
                break;
            }
            ChineseLanguage(scList);
            GUILayout.Space(1000);
            serializedObject.ApplyModifiedProperties();
            EditorUtility.SetDirty(soundConfig);
            if (GUI.changed)
            {
                EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
            }
        }