Exemplo n.º 1
0
        public override void execute(UIElementNode node)
        {
            base.execute(node);

            //模块名字
            //var moduleName = UICodeExport.UIName;

            //模块名字 dele_xxx
            var fullName = node.gameObject.name;
            var arr      = fullName.Split('_');

            var renderName = UICodeExport.UpperFirstChar(arr[1]);

            string savePath = UICodeExport.modulePath + "itemRender/" + renderName + "ItemRender" + UICodeExport.CodeExtendsion;

            if (File.Exists(savePath) == true)
            {
                //不重复生成,以免覆盖已有逻辑
                return;
            }

            String content = FileHelper.GetUTF8Text(UICodeExport.templatePath + uri);

            content = content.Replace("[name]", renderName);
            content = content.Replace("[varname]", outputVar(node));
            content = content.Replace("[varaddress]", outputAddress(node));
            content = content.Replace("[varhandler]", outputHandler(node));


            content = content.Replace("[varadvname]", outputAdvName(node));
            content = content.Replace("[varadvaddress]", outputAdvAddress(node));


            FileHelper.SaveUTF8(content, savePath);
        }
Exemplo n.º 2
0
        public override void execute(UIElementNode node)
        {
            base.execute(node);

            //模块名字
            var moduleName = UICodeExport.UIName;

            var proxyName = UICodeExport.UIName.Substring(2);

            string savePath = UICodeExport.modulePath + moduleName + "Mediator" + UICodeExport.CodeExtendsion;

            if (File.Exists(savePath) == true)
            {
                //不重复生成,以免覆盖已有逻辑
                return;
            }

            String content = FileHelper.GetUTF8Text(UICodeExport.templatePath + uri);


            content = content.Replace("[name]", UICodeExport.UIName);
            content = content.Replace("[proxyName]", proxyName);
            content = content.Replace("[varimport]", outputImport(node));
            content = content.Replace("[varname]", outputVar(node));
            content = content.Replace("[varaddress]", outputAddress(node));

            FileHelper.SaveUTF8(content, savePath);
        }
Exemplo n.º 3
0
        private void createOther(UIElementNode root)
        {
            foreach (var node in root.children)
            {
                if (node.gameObject.name.IndexOf("dele_") == 0)
                {
                    //生成PanelDelegate
                    var dele = new DelegateTemplate();
                    dele.execute(node);

                    var deleCode = new DelegateCodeTemplate();
                    deleCode.execute(node);
                }

                if (node.gameObject.name.IndexOf("itemRender_") == 0)
                {
                    //生成ItemRender
                    var itemRender = new ItemRenderTemplate();
                    itemRender.execute(node);

                    var itemRenderCode = new ItemRenderCodeTemplate();
                    itemRenderCode.execute(node);
                }

                if (node.children.Count > 0)
                {
                    createOther(node);
                }
            }
        }
Exemplo n.º 4
0
        protected virtual string outputAddress(UIElementNode node)
        {
            string output = "";
            string v      = "";

            foreach (UIElementPropertyBase prop in node.propterties)
            {
                v = prop.outputProperty();
                if (string.IsNullOrEmpty(v) == false)
                {
                    output += addressSpace + v + breakLine;
                }
            }

            HashSet <string> defHashSet = new HashSet <string>();

            foreach (UIElementPropertyBase prop in node.localPropterties)
            {
                v = prop.outputDefine();
                if (string.IsNullOrEmpty(v) == false && defHashSet.Contains(v) == false)
                {
                    defHashSet.Add(v);
                    output += addressSpace + v + breakLine;
                }

                v = prop.outputProperty();
                if (string.IsNullOrEmpty(v) == false)
                {
                    output += addressSpace + v + breakLine;
                }
            }

            return(output);
        }
Exemplo n.º 5
0
        protected override string outputAddress(UIElementNode node)
        {
            var go = node.getChildByName("btn_close");

            if (go != null)
            {
                return(addressSpace + "btn_close.addEventListener(EventX.CLICK, hide);" + breakLine);
            }
            return("");
        }
Exemplo n.º 6
0
 protected string outputImport(UIElementNode node)
 {
     foreach (var prop in node.propterties)
     {
         if (prop is UITabPropertyElement)
         {
             return("using clayui;");
         }
     }
     return("");
 }
Exemplo n.º 7
0
        protected override string outputVar(UIElementNode node)
        {
            //只要tab
            foreach (var prop in node.propterties)
            {
                if (prop is UITabPropertyElement)
                {
                    return(varSpace + "private TabNav tabNav = new TabNav();");
                }
            }

            return("");
        }
Exemplo n.º 8
0
        protected string outputHandler(UIElementNode node)
        {
            string output = "";

            foreach (var prop in node.propterties)
            {
                if (prop is UIBtnPropertyElement)
                {
                    output += prop.outputHandler(addressSpace + "//TODO" + breakLine, varSpace, addressSpace, breakLine);
                }
            }

            return(output);
        }
Exemplo n.º 9
0
        private string outputAdvName(UIElementNode node)
        {
            string output = "";

            foreach (var prop in node.propterties)
            {
                if (prop is UIPageListPropertyElement)
                {
                    output += varSpace + prop.outputAdvDefine() + breakLine;
                }
            }

            return(output);
        }
Exemplo n.º 10
0
        private string outputAdvAddress(UIElementNode node)
        {
            string output = "";

            foreach (var prop in node.propterties)
            {
                if (prop is UIPageListPropertyElement)
                {
                    output += addressSpace + prop.outputAdvProperty() + breakLine;
                }
            }

            return(output);
        }
Exemplo n.º 11
0
        public void initilize(GameObject go, UIElementNode parent = null)
        {
            this.gameObject = go;
            this.parent     = parent;
            //Debug.Log("UICodeExport :initilize" + go.name);
            dic.Clear();
            propterties.Clear();
            localPropterties.Clear();

            children = AS3_getChildren(go);


            //解析属性
            parseProperties();
        }
Exemplo n.º 12
0
        public void dispose()
        {
            parent     = null;
            gameObject = null;

            foreach (var child in children)
            {
                child.dispose();
            }

            dic.Clear();
            dic = null;
            propterties.Clear();
            propterties = null;
        }
Exemplo n.º 13
0
        private void parseProperties()
        {
            foreach (UIElementNode tsf in children)
            {
                var child = tsf.gameObject;
                if (child == null)
                {
                    continue;
                }
                UIElementPropertyBase prop;
                //btn_close,tab_arena,item_ArenaRank
                string[] keyValuePair = child.name.Split('_');
                if (keyValuePair.Length > 1)
                {
                    var key   = keyValuePair[0];
                    var value = keyValuePair[1];
                    prop            = UIElementPropertyManager.getProperty(key, value);
                    prop.gameObject = child;

                    propterties.Add(prop);

                    //处理特殊的属性
                    handleSpecialProperty(prop, child, value);
                }
                else
                {
                    //没有前缀就不申明变量
                    Text[] texts = tsf.gameObject.GetComponentsInChildren <Text>(true);
                    foreach (Text text in texts)
                    {
                        string path = text.name;

                        Transform parent = text.transform.parent;
                        while (parent != gameObject.transform)
                        {
                            path = parent.name + "/" + path;

                            parent = parent.parent;
                        }

                        UITxtPropertyLocalElement uiTxtPropertyElement = new UITxtPropertyLocalElement(text.name);
                        uiTxtPropertyElement.path       = path;
                        uiTxtPropertyElement.gameObject = text.gameObject;
                        localPropterties.Add(uiTxtPropertyElement);
                    }
                }
            }
        }
Exemplo n.º 14
0
        protected virtual string outputVar(UIElementNode node)
        {
            string output = "";
            string v      = "";

            foreach (var prop in node.propterties)
            {
                v = prop.outputDefine();
                if (string.IsNullOrEmpty(v) == false)
                {
                    output += varSpace + v + breakLine;
                }
            }

            return(output);
        }
Exemplo n.º 15
0
        protected override string outputAddress(UIElementNode node)
        {
            string output = "";

            foreach (var prop in node.propterties)
            {
                if (prop is UIBtnPropertyElement)
                {
                    output += addressSpace +
                              UICodeExport.LowerFirstChar(prop.fullName) + ".addEventListener(EventX.CLICK, on" +
                              UICodeExport.UpperFirstChar(prop.name) +
                              "Click);" +
                              breakLine;
                }
            }
            return(output);
        }
Exemplo n.º 16
0
        public override void execute(UIElementNode node)
        {
            base.execute(node);

            //模块名字
            var moduleName = UICodeExport.UIName;

            string savePath = UICodeExport.modulePath + "code/Code" + moduleName + UICodeExport.CodeExtendsion;


            String content = FileHelper.GetUTF8Text(UICodeExport.templatePath + uri);

            content = content.Replace("[name]", UICodeExport.UIName);
            content = content.Replace("[varname]", outputVar(node));
            content = content.Replace("[varaddress]", outputAddress(node));


            FileHelper.SaveUTF8(content, savePath);
        }
Exemplo n.º 17
0
        protected override string outputAddress(UIElementNode node)
        {
            string str = "";

            foreach (var prop in node.propterties)
            {
                if (prop is UITabPropertyElement)
                {
                    str += addressSpace + "tabNav.addMediator(view.tab_" + prop.name + ", view.dele_" + prop.name + ");\r\n";
                }
            }

            if (!string.IsNullOrEmpty(str))
            {
                str += addressSpace + "tabNav.selectedIndex = 0;\r\n";
            }

            return(str);
        }
Exemplo n.º 18
0
        private List <UIElementNode> AS3_getChildren(GameObject go)
        {
            Transform[] transforms = go.GetComponentsInChildren <Transform>(true);

            List <UIElementNode> nodes = new List <UIElementNode>();

            foreach (Transform item in transforms)
            {
                if (item.parent == go.transform)
                {
                    var node = new UIElementNode();
                    node.initilize(item.gameObject, this);

                    dic[item.gameObject.name] = item.gameObject;
                    nodes.Add(node);
                }
            }
            return(nodes);
        }
Exemplo n.º 19
0
        public override void execute(UIElementNode node)
        {
            base.execute(node);

            //模块名字
            //var moduleName = UICodeExport.UIName;

            //模块名字 dele_xxx
            var fullName = node.gameObject.name;
            var arr      = fullName.Split('_');

            var renderName = UICodeExport.UpperFirstChar(arr[1]);


            String content = FileHelper.GetUTF8Text(UICodeExport.templatePath + uri);

            content = content.Replace("[name]", renderName);
            content = content.Replace("[varname]", outputVar(node));
            content = content.Replace("[varaddress]", outputAddress(node));

            string savePath = UICodeExport.modulePath + "code/Code" + renderName + "ItemRender" + UICodeExport.CodeExtendsion;

            FileHelper.SaveUTF8(content, savePath);
        }
Exemplo n.º 20
0
        public void decode(GameObject go)
        {
            if (go.name.IndexOf("UI") == 0)
            {
                UIName = go.name;

                var folderName = UIName.Substring(2) + "UI";
                folderName = LowerFirstChar(folderName);
                modulePath = modulePathPrefix + folderName + "/";

                CodeExportSetting setting = go.GetComponent <CodeExportSetting>();
                if (setting != null)
                {
                    if (string.IsNullOrEmpty(setting.parentModuleName) == false)
                    {
                        modulePath = modulePathPrefix + setting.parentModuleName + "/";
                    }
                    onlyGenerateMediator = setting.onlyGenerateMediator;
                }
                else
                {
                    onlyGenerateMediator = false;
                }
            }
            else
            {
                EditorUtility.DisplayDialog("提示", "请以 UI{0} 命名", "ok");
                return;
            }

            root = new UIElementNode();
            root.initilize(go);

            //生成ViewCode
            var viewCode = new ViewCodeTemplate();

            viewCode.execute(root);

            //生成View
            var viewTemplate = new ViewTemplate();

            viewTemplate.execute(root);

            //生成Mediator
            var meditorTemplate = new MediatorTemplate();

            meditorTemplate.execute(root);

            if (onlyGenerateMediator == false)
            {
                //生成Proxy
                var proxyTemplate = new ProxyTemplate();
                proxyTemplate.execute(root);

                //生成Operater
                var operateTemplate = new OperaterTemplate();
                operateTemplate.execute(root);

                //生成Decoder
                var decoderTemplate = new DecoderTemplate();
                decoderTemplate.execute(root);
            }

            createOther(root);

            EditorUtility.DisplayDialog("提示", UIName + " 代码生成成功", "确定");
        }
Exemplo n.º 21
0
 public virtual void execute(UIElementNode node)
 {
 }