예제 #1
0
        public UINode DrawLayer(LayerInfo layer)
        {
            var    newRect = LayerImportUtil.AddSubRectFromResourceDic(layer.rect, layer.resourceDic);
            UINode node    = mechine.CreateRootNode(layer, newRect);

            node.AddComponent <UnityEngine.UI.Text>();
            return(node);
        }
예제 #2
0
        public UINode DrawLayer(LayerInfo layer)
        {
            var node       = mechine.CreateRootNode(layer);
            var image      = node.AddComponent <Image>();
            var inputField = node.AddComponent <InputField>();

            inputField.targetGraphic = image;
            CompleteInputField(inputField);
            return(node);
        }
 public UINode DrawLayer(LayerInfo layer)
 {
     if (string.IsNullOrEmpty(layer.name) || string.IsNullOrEmpty(layer.type))
     {
         return(emptyImporter.DrawLayer(layer));
     }
     else if (layerImportDic.ContainsKey(layer.type))
     {
         return(layerImportDic[layer.type].DrawLayer(layer));
     }
     else
     {
         Debug.LogWarningFormat("未解析层{0},因为找不到类型为{1}的Importer", layer.name, layer.type);
         return(null);
     }
 }
예제 #4
0
        public static UINode CreateRootNode(this AssemblerStateMechine mechine, LayerInfo layerInfo, Rect customRect)
        {
            var path         = layerInfo.path;
            var instenceName = NameFromPath(path);
            var go           = new GameObject(instenceName, typeof(RectTransform));

            go.layer = LayerMask.NameToLayer("UI");
            go.transform.SetParent(mechine.canvas.transform, false);
            var uiRect = ParamAnalysisTool.PsRectToUnityRect(mechine.uiSize, customRect);

            SetRectTransform(uiRect, go.transform as RectTransform);
            UINode node = new UINode(go.transform, layerInfo);

            node.layerInfo = layerInfo;
            return(node);
        }
예제 #5
0
        public static UIInfo LoadUIInfo(this CsvTable table)
        {
            if (table.IsUIInfoTable(false))
            {
                var uiInfo = new UIInfo(table.name);

                if (table.Rows != null && table.Columns != null)
                {
                    for (int i = 0; i < table.Rows.Count; i++)
                    {
                        var layerInfo = new LayerInfo();
                        layerInfo.name = table[0, i];
                        layerInfo.path = table[1, i];
                        layerInfo.type = table[2, i];
                        layerInfo.rect = ParamAnalysisTool.StringToRect(table[3, i]);
                        var resourceDic = ParamAnalysisTool.ToDictionary(table[4, i]);
                        if (resourceDic != null)
                        {
                            ChargeDic(layerInfo.resourceDic, resourceDic);
                        }


                        if (table.Columns.Count > 5)
                        {
                            List <ResourceDic> sub_images;
                            List <ResourceDic> sub_texts;
                            List <ResourceDic> sub_rawImages;
                            var subResourceDic = ParamAnalysisTool.ToDictionary_Sub(table[5, i], out sub_images, out sub_texts, out sub_rawImages);
                            if (subResourceDic != null)
                            {
                                ChargeDic(layerInfo.subResourceDic, subResourceDic);
                            }
                            ChargeList(layerInfo.sub_images, sub_images);
                            ChargeList(layerInfo.sub_texts, sub_texts);
                            ChargeList(layerInfo.sub_rawImages, sub_rawImages);
                        }

                        uiInfo.layers.Add(layerInfo);
                    }
                }

                return(uiInfo);
            }
            return(null);
        }
예제 #6
0
        /// <summary>
        /// 加载Image/Text/Label
        /// </summary>
        /// <param name="parent"></param>
        /// <param name="layerInfo"></param>
        public static void LoadCommonResources(AssemblerStateMechine mechine, UINode node, Rect baseRect)
        {
            Transform parent    = node.transform;
            LayerInfo layerInfo = node.layerInfo;

            if (layerInfo.sub_images != null)
            {
                for (int i = 0; i < layerInfo.sub_images.Count; i++)
                {
                    var current = layerInfo.sub_images[i];
                    var image   = new GameObject("Image", typeof(RectTransform), typeof(Image)).GetComponent <Image>();
                    image.transform.SetParent(parent, false);
                    mechine.ChargeInfo(image, current);
                    image.rectTransform.SetRectFromResource(layerInfo.rect, baseRect, current);
                }
            }

            if (layerInfo.sub_texts != null)
            {
                for (int i = 0; i < layerInfo.sub_texts.Count; i++)
                {
                    var current = layerInfo.sub_texts[i];
                    var title   = LayerImportUtil.MakeTitleComponenet("Title", parent);
                    title.resizeTextForBestFit = true;//缩放时会看不到?
                    mechine.ChargeInfo(title, current);
                    title.rectTransform.SetRectFromResource(layerInfo.rect, baseRect, current);
                }
            }

            if (layerInfo.sub_rawImages != null)
            {
                for (int i = 0; i < layerInfo.sub_rawImages.Count; i++)
                {
                    var current  = layerInfo.sub_rawImages[i];
                    var rawImage = new GameObject("RawImage", typeof(RectTransform), typeof(RawImage)).GetComponent <RawImage>();
                    rawImage.transform.SetParent(parent, false);
                    mechine.ChargeInfo(rawImage, current);
                    rawImage.rectTransform.SetRectFromResource(layerInfo.rect, baseRect, current);
                }
            }
        }
        public UINode DrawLayer(LayerInfo layer)
        {
            var node   = mechine.CreateRootNode(layer);
            var slider = node.AddComponent <Slider>();

            slider.value = 1;

            var background = new GameObject("Background", typeof(Image));

            background.transform.SetParent(slider.transform, false);
            slider.targetGraphic = background.GetComponent <Image>();
            node.RecordSubTransfrom(runtime_key_background, background.GetComponent <RectTransform>());

            var fillRect = new GameObject("Fill Area", typeof(RectTransform));
            var fill     = new GameObject("Fill", typeof(Image));

            fillRect.transform.SetParent(slider.transform, false);
            fill.transform.SetParent(fillRect.transform, false);
            slider.fillRect = fill.GetComponent <RectTransform>();
            node.RecordSubTransfrom(runtime_key_fill, fillRect.GetComponent <RectTransform>());
            return(node);
        }
        public UINode DrawLayer(LayerInfo layer)
        {
            var node = mechine.CreateRootNode(layer);

            return(node);
        }
        private UINode[] CompleteEmptyNodes(UINode[] uiNodes)
        {
            var pathCatchDic    = new Dictionary <string, string[]>();
            var nodeTemplateDic = new Dictionary <string, UINode>();
            var neededNodes     = new Dictionary <string, List <UINode> >();
            var emptyNodes      = new List <UINode>();
            var maxdeepth       = 0;

            ///确定深度,记录索引
            for (int i = 0; i < uiNodes.Length; i++)
            {
                var node = uiNodes[i];

                if (string.IsNullOrEmpty(node.path))
                {
                    continue;
                }

                nodeTemplateDic.Add(node.path, node);
                var pathArray = LayerImportUtil.PathToArray(node.path);
                pathCatchDic.Add(node.path, pathArray);

                var deepth = pathArray.Length;
                maxdeepth = maxdeepth > deepth ? maxdeepth : deepth;
            }

            ///查找所有空节点的实体子节点
            for (int i = 0; i < uiNodes.Length; i++)
            {
                var node = uiNodes[i];

                if (string.IsNullOrEmpty(node.path))
                {
                    continue;
                }

                var path = pathCatchDic[node.path];

                for (int j = path.Length; j > 0; j--)
                {
                    var parentPath = LayerImportUtil.ArrayToPath(path, j - 1);
                    if (!string.IsNullOrEmpty(parentPath))
                    {
                        if (!nodeTemplateDic.ContainsKey(parentPath))
                        {
                            if (neededNodes.ContainsKey(parentPath))
                            {
                                if (!neededNodes[parentPath].Contains(node))
                                {
                                    neededNodes[parentPath].Add(node);
                                }
                            }
                            else
                            {
                                neededNodes.Add(parentPath, new List <UINode>()
                                {
                                    node
                                });
                            }
                        }
                    }
                }
            }

            ///创建节点
            using (var enumerator = neededNodes.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    var current = enumerator.Current;
                    var rects   = new Rect[current.Value.Count];
                    for (int i = 0; i < rects.Length; i++)
                    {
                        rects[i] = current.Value[i].layerInfo.rect;
                    }
                    var info = new LayerInfo();
                    info.path = current.Key;
                    info.rect = LayerImportUtil.GetRectContent(rects);
                    var emptyNode = DrawLayer(info);
                    emptyNodes.Add(emptyNode);
                }
            }

            return(emptyNodes.ToArray());
        }
예제 #10
0
        /// <summary>
        /// 普通UGUI节点
        /// </summary>
        /// <param name="go"></param>
        /// <param name="rect"></param>
        /// <param name="parent"></param>
        /// <returns></returns>
        public static UINode CreateNormalNode(GameObject go, Transform root, Vector2 rootSize, LayerInfo layerInfo)
        {
            go.transform.SetParent(root, false);
            var uiRect = ParamAnalysisTool.PsRectToUnityRect(rootSize, layerInfo.rect);

            SetRectTransform(uiRect, go.transform as RectTransform);
            UINode node = new UINode(go.transform, layerInfo);

            return(node);
        }
예제 #11
0
 public UINode(Transform transform, LayerInfo layerInfo = null)
 {
     this.layerInfo = layerInfo;
     this.transform = transform;
     anchoType      = AnchoType.Custom;
 }
예제 #12
0
 public UINode DrawLayer(LayerInfo layer)
 {
     return(mechine.CreateRootNode(layer));
 }