Beispiel #1
0
    public void OnGUI()
    {
        GUILayout.Label("创建新的UILuaData,并同时创建脚本文件夹和脚本");
        GUILayout.Space(5);
        GUILayout.Label("作者");
        author = GUILayout.TextArea(author, 100);

        GUILayout.Space(5);
        GUILayout.Label("UI名字  命名格式:UIXXX");
        newUIStr = GUILayout.TextArea(newUIStr, 100);
        GUILayout.Label("文件夹名名字");
        newFileStr = GUILayout.TextArea(newFileStr, 100);
        GUILayout.Space(10);
        isCrtl = GUILayout.Toggle(isCrtl, "IsController 是否需要创建Controller");
        GUILayout.Space(10);
        isModel = GUILayout.Toggle(isModel, "isModel 是否需要创建Moel");
        GUILayout.Space(10);
        isView = GUILayout.Toggle(isView, "isView 是否需要创建View");
        GUILayout.Space(5);
        GUILayout.Label("选择UILayers");
        mLayerType = (UILayers_TYPE)EditorGUILayout.EnumPopup(mLayerType);
        GUILayout.Space(5);
        GUILayout.Label("只写入Config数据");
        if (GUILayout.Button("OnlyWriteData"))
        {
            CreatWriteConfig();
            CreaWriteWindowsName();
        }
        GUILayout.Space(50);
        if (GUILayout.Button("CreatUILuaData"))
        {
            if (newUIStr == "UIName")
            {
                Debug.LogError("UIName is deafult");
                return;
            }
            if (newFileStr == "FileName")
            {
                Debug.LogError("FileName is deafult");
                return;
            }
            CreatUIScript();
            if (isModel)
            {
                CreatModellLua();
            }
            if (isView)
            {
                CreatViewlLua();
            }
            if (isCrtl)
            {
                CreatCrtlLua();
            }
            CreatUIConfiglLua();
            CreatWriteConfig();
            CreaWriteWindowsName();
            AssetDatabase.SaveAssets();

            EditorUtility.DisplayDialog("MVC Tool", newUIStr + "页面生成成功!!!", "确定");
        }
        //GUILayout.Space(5);
        //GUILayout.Label("创建WarpItem");
        //GUILayout.Space(5);
        //GUILayout.Label("WarpItem名字  命名格式:UIXXXWarpItem");
        //newWarpItemStr = GUILayout.TextArea(newWarpItemStr, 100);
        //GUILayout.Label("请先填写fileName 作为生成目录");
        //if (GUILayout.Button("CreatWarpItem"))
        //{
        //    CreatWrapItem();
        //    AssetDatabase.SaveAssets();
        //}
    }
Beispiel #2
0
    private void OnGUI()
    {
        #region 生成MVVM
        //标题
        GUILayout.Space(10);
        GUILayout.BeginHorizontal();
        GUILayout.Label("此工具用于单独生成MVVM相关模板到指定的模块中");
        GUILayout.EndHorizontal();

        //选择层
        GUILayout.Space(10);
        GUILayout.BeginHorizontal();
        GUILayout.Label("Choose Layer: ", EditorStyles.boldLabel, GUILayout.Width(100));
        mLayerType = (UILayers_TYPE)EditorGUILayout.EnumPopup(mLayerType);
        GUILayout.EndHorizontal();

        //选择module
        GUILayout.Space(10);
        GUILayout.BeginHorizontal();
        GUILayout.Label("Module Path: ", EditorStyles.boldLabel, GUILayout.Width(100));
        modulePathObj = EditorGUILayout.ObjectField(modulePathObj, typeof(Object), true) as Object;
        GUILayout.EndHorizontal();

        //操作按钮
        GUILayout.Space(10);
        GUILayout.BeginHorizontal();
        if (GUILayout.Button("生成 ViewModel", GUILayout.ExpandWidth(true)))
        {
            Transform trans = Selection.activeTransform;
            if (trans == null)
            {
                EditorUtility.DisplayDialog("错误", "请选择需要生成模板的UI对象!", "确定");
                return;
            }
            if (modulePathObj == null)
            {
                EditorUtility.DisplayDialog("错误", "请选择目标目录!", "确定");
                return;
            }

            string pagePath = UIMVVMGen.output_dir + modulePathObj.name + "/Model";
            if (!Directory.Exists(pagePath))
            {
                Directory.CreateDirectory(pagePath);
            }

            string modelPath = pagePath + "/" + trans.name + "Model.lua";
            if (File.Exists(modelPath))
            {
                EditorUtility.DisplayDialog("错误", "文件已存在:" + pagePath, "确定");
                return;
            }
            UIMVVMGen.GenUITemplate(trans.name, mLayerType.ToString(), UIMVVMGen.tpl_viewmodel, modelPath);
        }
        if (GUILayout.Button("生成 View", GUILayout.ExpandWidth(true)))
        {
            Transform trans = Selection.activeTransform;
            if (trans == null)
            {
                EditorUtility.DisplayDialog("错误", "请选择需要生成模板的UI对象!", "确定");
                return;
            }
            if (modulePathObj == null)
            {
                EditorUtility.DisplayDialog("错误", "请选择目标目录!", "确定");
                return;
            }

            string pagePath = UIMVVMGen.output_dir + modulePathObj.name + "/View";
            if (!Directory.Exists(pagePath))
            {
                Directory.CreateDirectory(pagePath);
            }

            string modelPath = pagePath + "/" + trans.name + "View.lua";
            if (File.Exists(modelPath))
            {
                EditorUtility.DisplayDialog("错误", "文件已存在:" + pagePath, "确定");
                return;
            }
            UIMVVMGen.GenUITemplate(trans.name, mLayerType.ToString(), UIMVVMGen.tpl_view, modelPath);
        }


        if (GUILayout.Button("生成 Config", GUILayout.ExpandWidth(true)))
        {
            Transform trans = Selection.activeTransform;
            if (trans == null)
            {
                EditorUtility.DisplayDialog("错误", "请选择需要生成模板的UI对象!", "确定");
                return;
            }
            if (modulePathObj == null)
            {
                EditorUtility.DisplayDialog("错误", "请选择目标目录!", "确定");
                return;
            }

            string pagePath = UIMVVMGen.output_dir + modulePathObj.name;
            if (!Directory.Exists(pagePath))
            {
                Directory.CreateDirectory(pagePath);
            }


            string configPath = pagePath + "/" + trans.name + "Config.lua";
            if (File.Exists(configPath))
            {
                Logger.LogError("lua file in path:{0} is existed.", configPath);
                return;
            }

            UIMVVMGen.GenUITemplate(trans.name, mLayerType.ToString(), UIMVVMGen.tpl_config, configPath);
        }

        GUILayout.EndHorizontal();
        #endregion

        #region 生成 ScrollView
        GUILayout.Space(30);
        GUILayout.BeginHorizontal();
        GUILayout.Label("创建ScrollView GameObject");
        GUILayout.EndHorizontal();

        GUILayout.BeginVertical();

        scrollViewName = EditorGUILayout.TextField("ScrollView Name Prefix:", scrollViewName);
        widthHeight    = EditorGUILayout.Vector2IntField("Scroll Size: ", widthHeight);
        cellWH         = EditorGUILayout.Vector2IntField("Cell Size:", cellWH);

        GUILayout.BeginHorizontal();
        horizontal = EditorGUILayout.Toggle("Horizontal: ", horizontal);
        vertical   = EditorGUILayout.Toggle("Vertical: ", vertical);
        GUILayout.EndHorizontal();

        GUILayout.EndVertical();

        GUILayout.Space(10);
        GUILayout.BeginVertical();
        if (GUILayout.Button("Hierarchy中创建ScrollView GameObject", GUILayout.ExpandWidth(true)))
        {
            Transform trans = Selection.activeTransform;
            if (trans == null)
            {
                EditorUtility.DisplayDialog("错误", "请选择ScrollView所在的父结点!", "确定");
                return;
            }

            if (scrollViewName.Equals(""))
            {
                EditorUtility.DisplayDialog("错误", "请输入Name Prefix !", "确定");
                return;
            }
            UIGOGen.GenScrollView(trans, scrollViewName, widthHeight.x, widthHeight.y, cellWH.x, cellWH.y, horizontal, vertical);
        }
        GUILayout.Space(10);
        if (GUILayout.Button("生成 ScrollView Item", GUILayout.ExpandWidth(true)))
        {
            Transform trans = Selection.activeTransform;
            if (trans == null)
            {
                EditorUtility.DisplayDialog("错误", "请选择需要生成模板的UI对象!", "确定");
                return;
            }
            if (modulePathObj == null)
            {
                EditorUtility.DisplayDialog("错误", "请选择目标目录!", "确定");
                return;
            }

            string pagePath = UIMVVMGen.output_dir + modulePathObj.name + "/Component";
            if (!Directory.Exists(pagePath))
            {
                Directory.CreateDirectory(pagePath);
            }

            string modelPath = pagePath + "/" + trans.name + "WrapItem.lua";
            if (File.Exists(modelPath))
            {
                EditorUtility.DisplayDialog("错误", "文件已存在:" + pagePath, "确定");
                return;
            }
            UIMVVMGen.GenUITemplate(trans.name, mLayerType.ToString(), UIMVVMGen.tpl_component, modelPath);
        }
        GUILayout.EndVertical();
        #endregion
    }