//绘制窗口内容 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(200), 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 + "/" + _strFileName + ".lua"; if (!Directory.Exists(_strDirectory)) { Directory.CreateDirectory(_strDirectory); } CustomLuaMenu.generateScriptFile(file, _strSummary, _strAuthor, _strModule, _dictElements); } if (GUILayout.Button("取消", GUILayout.Width(100), GUILayout.ExpandWidth(true))) { this.Close(); } EditorGUILayout.EndHorizontal(); }
//绘制窗口内容 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(); }
/// <summary> /// 调用脚本函数 /// </summary> /// <param name="eFunc"></param> protected object callLuaFunction(ELuaMonoFunc eFunc) { if (bindScript == null) { return(null); } LuaFunction func = null; if (_luaFuncs.TryGetValue(eFunc, out func)) { return(func.call(gameObject)); } #if UNITY_EDITOR string s = string.Format("Function [{0}] in the lua script ** {1}.{2} ** is missing", eFunc.ToString(), gameObject.name, bindScript); Debug.LogWarning(s); #endif return(null); }