예제 #1
0
        public static bool CreateMonoLuaScript(string monoName, string desc)
        {
            string targetPath = Application.dataPath + "/" + CustomLuaMonoEditor.MonoScriptsPath;

            if (!string.IsNullOrEmpty(desc) && !desc.Equals("脚本描述"))
            {
                string monoPath = targetPath + monoName + "Mono.lua";
                Dictionary <string, ScriptElementInfo> dictElements = new Dictionary <string, ScriptElementInfo>();
                addFunToElement(dictElements, "Awake");
                addFunToElement(dictElements, "Start");
                addFunToElement(dictElements, "OnDestroy");
                addFunToElement(dictElements, "OnEnable");
                addFunToElement(dictElements, "OnDisable");
                //addFunToElement(dictElements, "Update");
                if (!Directory.Exists(targetPath))
                {
                    Directory.CreateDirectory(targetPath);
                }
                CustomLuaMenu.CreateMonoScriptFile(monoPath, desc, SystemInfo.deviceName, monoName, dictElements);

                string controllerPath = targetPath + monoName + "Controller.lua";
                CustomLuaMenu.CreateControllerScriptFile(controllerPath, desc, SystemInfo.deviceName, monoName);

                return(true);
            }
            else
            {
                EditorUtility.DisplayDialog("创建失败", "请填写正确的脚本描述", "确认");
                return(false);
            }
        }
예제 #2
0
        //绘制窗口内容
        void OnGUI()
        {
            EditorGUILayout.HelpBox(_strHelpMsg, _msgType, true);
            EditorGUILayout.Separator();

            EditorGUILayout.LabelField("目录:" + _strDirectory);

            /*
             * EditorGUILayout.BeginHorizontal();
             * EditorGUILayout.LabelField("*文件名");
             * _strFileName = EditorGUILayout.TextField(_strFileName, GUILayout.Width(300), GUILayout.ExpandWidth(true));
             * EditorGUILayout.EndHorizontal();
             */
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("*脚本描述");
            _strSummary = EditorGUILayout.TextField(_strSummary, GUILayout.Width(300), GUILayout.ExpandWidth(true));
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("*作者");
            _strAuthor = EditorGUILayout.TextField(_strAuthor, GUILayout.Width(300), GUILayout.ExpandWidth(true));
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("*模块名");
            _strModule = EditorGUILayout.TextField(_strModule, GUILayout.Width(300), GUILayout.ExpandWidth(true));
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.Separator();
            EditorGUILayout.Separator();

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("函数信息 ");
            _display = (ELuaMonoFunc)EditorGUILayout.EnumPopup(_display, GUILayout.Width(120), GUILayout.ExpandWidth(true));
            if (GUILayout.Button("添加", GUILayout.Width(100), GUILayout.ExpandWidth(true)))
            {
                string funcName = _display.ToString();
                AddFuncToScript(funcName);
            }
            EditorGUILayout.EndHorizontal();

            //菜单
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("名称", GUILayout.Width(30), GUILayout.ExpandWidth(true));
            EditorGUILayout.LabelField("属性", GUILayout.Width(30), GUILayout.ExpandWidth(true));
            EditorGUILayout.LabelField("类型", GUILayout.Width(30), GUILayout.ExpandWidth(true));
            EditorGUILayout.LabelField("模块", GUILayout.Width(30), GUILayout.ExpandWidth(true));
            EditorGUILayout.EndHorizontal();

            //函数列表信息
            _v2ScrollPos = EditorGUILayout.BeginScrollView(_v2ScrollPos);
            foreach (var kvp in _dictElements)
            {
                var    elementInfo = kvp.Value;
                string strAttr     = elementInfo._bGlobal ? "global" : "local";
                string strName     = elementInfo._name;
                string strTypeName = elementInfo._type.ToString();
                string strModule   = _strModule;

                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField(strName, GUILayout.Width(30), GUILayout.ExpandWidth(true));
                EditorGUILayout.LabelField(strAttr, GUILayout.Width(30), GUILayout.ExpandWidth(true));
                EditorGUILayout.LabelField(strTypeName, GUILayout.Width(30), GUILayout.ExpandWidth(true));
                EditorGUILayout.LabelField(strModule, GUILayout.Width(30), GUILayout.ExpandWidth(true));
                EditorGUILayout.EndHorizontal();
            }
            EditorGUILayout.EndScrollView();


            //操作按钮
            EditorGUILayout.BeginHorizontal();

            if (GUILayout.Button("生成", GUILayout.Width(100), GUILayout.ExpandWidth(true)))
            {
                if (string.IsNullOrEmpty(_strFileName) ||
                    string.IsNullOrEmpty(_strSummary) ||
                    string.IsNullOrEmpty(_strAuthor) ||
                    string.IsNullOrEmpty(_strModule))
                {
                    _strHelpMsg = "信息不完整";
                    _msgType    = MessageType.Error;
                    return;
                }

                //还原提示信息
                _strHelpMsg = "带有*标识的为必填项";
                _msgType    = MessageType.Info;

                //生成脚本
                string             file = _strDirectory + "/" + _strModule + "Mono.lua";
                System.IO.FileInfo fi   = new System.IO.FileInfo(file);
                if (fi.Exists)
                {
                    EditorUtility.DisplayDialog("创建失败", "存在相同命名的脚本,请删除或者重命名后再创建。", "确认");
                    return;
                }

                if (!Directory.Exists(_strDirectory))
                {
                    Directory.CreateDirectory(_strDirectory);
                }
                CustomLuaMenu.CreateMonoScriptFile(file, _strSummary, _strAuthor, _strModule, _dictElements);

                if (_parentBehaviour != null)
                {
                    _parentBehaviour.bindScript = CustomLuaMonoEditor.MonoScriptsPath + _strModule + "Mono.lua";
                }

                string controllerPath = _strDirectory + "/" + _strModule + "Controller.lua";
                CustomLuaMenu.CreateControllerScriptFile(controllerPath, _strSummary, _strAuthor, _strModule);
                this.Close();
            }

            if (GUILayout.Button("取消", GUILayout.Width(100), GUILayout.ExpandWidth(true)))
            {
                this.Close();
            }

            EditorGUILayout.EndHorizontal();
        }