Beispiel #1
0
        public override UGUINode DrawImage(Data.ImgNode image, UGUINode parent)
        {
            UGUINode node = CreateRootNode(image.Name, AdjustTextRect(image.rect, image.fontSize), parent);

            UnityEngine.UI.Text myText = node.InitComponent <Text>();
            PSDImporterUtility.SetPictureOrLoadColor(image, myText);
            return(node);
        }
Beispiel #2
0
 public void BeginReprocess(UGUINode node)
 {
     foreach (var item in node.childs)
     {
         BeginReprocess(item);
     }
     node.InversionReprocess();
 }
Beispiel #3
0
        /// <summary>
        /// 普通UGUI节点
        /// </summary>
        /// <param name="go"></param>
        /// <param name="rect"></param>
        /// <param name="parent"></param>
        /// <returns></returns>
        public UGUINode CreateNormalNode(GameObject go, Rect rect, UGUINode parent)
        {
            go.transform.SetParent(ctrl.uinode.transform, false);
            SetRectTransform(rect, go.transform as RectTransform);
            UGUINode node = new UGUINode(go.transform, parent);

            return(node);
        }
        private void DrawBackground(Data.ImgNode bg, UGUINode node)
        {
            var bgnode = ctrl.DrawImage(bg, node);
            var graph  = bgnode.InitComponent <UnityEngine.UI.Image>();

            node.InitComponent <Slider>().targetGraphic = graph;
            PSDImporterUtility.SetPictureOrLoadColor(bg, graph);
        }
Beispiel #5
0
        public override UGUINode DrawImage(ImgNode image, UGUINode parent)
        {
            UGUINode node = CreateRootNode(image.Name, image.rect, parent);

            UnityEngine.UI.RawImage pic = node.InitComponent <UnityEngine.UI.RawImage>();
            PSDImporterUtility.SetPictureOrLoadColor(image, pic);
            return(node);
        }
        public override UGUINode DrawLayer(Data.GroupNode layer, UGUINode parent)
        {
            UGUINode node = CreateRootNode(layer.displayName, layer.rect, parent);

            UnityEngine.UI.InputField inputfield = node.InitComponent <UnityEngine.UI.InputField>();
            DrawImages(inputfield, node, layer);
            return(node);
        }
Beispiel #7
0
        public override void AfterGenerate(UGUINode node)
        {
            base.AfterGenerate(node);
            ContentSizeFitter content = node.InitComponent <ContentSizeFitter>();

            content.horizontalFit = ContentSizeFitter.FitMode.PreferredSize;
            content.verticalFit   = ContentSizeFitter.FitMode.PreferredSize;
        }
        private void SetLayoutItem(UGUINode childNode, Rect rect)
        {
            var layout = childNode.transform.gameObject.AddComponent <LayoutElement>();

            layout.preferredWidth  = rect.width;
            layout.preferredHeight = rect.height;
            childNode.anchoType    = AnchoType.Left | AnchoType.Up;
        }
Beispiel #9
0
 public void BeginSetAnchers(UGUINode node)
 {
     foreach (var item in node.childs)
     {
         BeginSetAnchers(item);
         PSDImporterUtility.SetAnchorByNode(item);
     }
 }
Beispiel #10
0
 public void BeginSetUIParents(UGUINode node)
 {
     foreach (var item in node.childs)
     {
         item.transform.SetParent(node.transform);
         BeginSetUIParents(item);
     }
 }
Beispiel #11
0
        public override UGUINode DrawLayer(Data.GroupNode layer, UGUINode parent)
        {
            UGUINode  node      = CreateRootNode(layer.displayName, layer.rect, parent);
            Scrollbar scrollbar = node.InitComponent <Scrollbar>();

            SetScrollBarDirection(scrollbar, layer);
            DrawImages(layer.images, scrollbar, node);
            return(node);
        }
        public override void AfterGenerate(UGUINode node)
        {
            base.AfterGenerate(node);
            var           dropDown = node.InitComponent <Dropdown>();
            RectTransform rt       = dropDown.template;

            rt.pivot            = new Vector2(0.5f, 1);
            rt.anchoredPosition = Vector3.zero;
        }
Beispiel #13
0
 public event UnityAction <UGUINode> inversionReprocess;//从树的末端开始处理
 public UGUINode(Transform transform, UGUINode parent)
 {
     this.transform = transform;
     this.parent    = parent;
     if (parent != null)
     {
         parent.childs.Add(this);
     }
 }
Beispiel #14
0
        private void DrawFill(ImgNode fill, UGUINode node)
        {
            var fillAreaNode = CreateNormalNode(new GameObject("Fill Area", typeof(RectTransform)), fill.rect, node);
            var fileNode     = ctrl.DrawImage(fill, fillAreaNode);

            fileNode.InitComponent <Image>().type = Image.Type.Tiled;

            node.InitComponent <Slider>().fillRect = fileNode.InitComponent <RectTransform>();
        }
Beispiel #15
0
 /// <summary>
 /// 空器
 /// </summary>
 /// <param name="childNode"></param>
 /// <param name="scrollRect"></param>
 private void DrawConent(UGUINode childNode, ScrollRect scrollRect)
 {
     childNode.inversionReprocess += (x) =>
     {
         var content = childNode.InitComponent <RectTransform>();
         scrollRect.content = content;
         scrollRect.content.anchoredPosition = Vector2.zero;
     };
 }
Beispiel #16
0
 public PSDImportCtrl(Canvas canvas, RuleObject rule, Vector2 canvasSize)
 {
     this.canvas     = canvas;
     this.rule       = rule;
     this.canvas     = canvas;
     this.canvasSize = canvasSize;
     uinode          = new UGUINode(canvas.transform, null);
     InitDrawers();
 }
Beispiel #17
0
        private void DrawMask(Data.GroupNode layer, Toggle toggle, UGUINode bgNode)
        {
            var mask = layer.images.Find(x => MatchAddress(x.Name, maskAddress));

            if (mask != null)
            {
                PSDImporterUtility.SetPictureOrLoadColor(mask, toggle.graphic);
                CreateNormalNode(toggle.graphic.gameObject, mask.rect, bgNode);
            }
        }
Beispiel #18
0
 private void BeginScaleWithCanvas(UGUINode uinode, Vector2 uiSize)
 {
     foreach (var item in uinode.childs)
     {
         var child = item.InitComponent <RectTransform>();
         child.anchorMin        = Vector2.zero;
         child.anchorMax        = Vector2.one;
         child.anchoredPosition = Vector2.zero;
     }
 }
 private void DrawOtherLayers(GroupNode layer, UGUINode node)
 {
     for (int imageIndex = 0; imageIndex < layer.images.Count; imageIndex++)
     {
         ImgNode image = layer.images[imageIndex];
         if (!MatchAddress(image.Name, rule.backgroundAddress, rule.maskAddress))
         {
             ctrl.DrawImage(image, node);
         }
     }
 }
Beispiel #20
0
        /// <summary>
        /// 根UGUI节点
        /// </summary>
        /// <param name="transform"></param>
        /// <param name="parent"></param>
        protected UGUINode CreateRootNode(string name, Rect rect, UGUINode parent)
        {
            var go = CreateTemplate();

            go.name  = name;
            go.layer = LayerMask.NameToLayer("UI");
            var node = CreateNormalNode(go, rect, parent);

            node.inversionReprocess += AfterGenerate;
            return(node);
        }
Beispiel #21
0
        protected void StretchTitle(UGUINode node)
        {
            var texts = node.transform.GetComponentsInChildren <Text>();
            var title = Array.Find(texts, x => MatchAddress(x.name, rule.titleAddress));

            if (title)
            {
                PSDImporterUtility.SetNormalAnchor(AnchoType.XStretch | AnchoType.YStretch, node.transform as RectTransform, title.transform as RectTransform);
                title.rectTransform.anchoredPosition = Vector3.zero;
            }
        }
Beispiel #22
0
 public override UGUINode DrawImage(Data.ImgNode image, UGUINode parent)
 {
     if (image.type == ImgType.Texture)
     {
         return(DrawRawImage(image, parent));
     }
     else
     {
         return(DrawSpriteImage(image, parent));
     }
 }
        public override void AfterGenerate(UGUINode node)
        {
            base.AfterGenerate(node);
            var inputField = node.InitComponent <InputField>();
            var text       = inputField.textComponent.GetComponent <RectTransform>();
            var holder     = inputField.placeholder.GetComponent <RectTransform>();

            text.anchorMin        = holder.anchorMin = Vector2.zero;
            text.anchorMax        = holder.anchorMax = Vector2.one;
            text.anchoredPosition = holder.anchoredPosition = Vector2.zero;
            text.sizeDelta        = holder.sizeDelta = new Vector2(-10, -10);
        }
Beispiel #24
0
        public override UGUINode DrawLayer(Data.GroupNode layer, UGUINode parent)
        {
            UGUINode   node       = CreateRootNode(layer.displayName, layer.rect, parent);
            ScrollRect scrollRect = node.InitComponent <UnityEngine.UI.ScrollRect>();

            SetScrollViewDirection(layer, scrollRect, layer.directionAxis);
            var viewNode = DrawViewNode(layer, scrollRect, node);

            DrawImages(layer, node, scrollRect);
            DrawChildLayers(layer, viewNode, scrollRect);
            return(node);
        }
Beispiel #25
0
        public UGUINode DrawImage(Data.ImgNode image, UGUINode parent)
        {
            UGUINode node = imgImporterDic[image.type].DrawImage(image, parent);

            if (node == null)
            {
                Debug.Log(image.type);
                Debug.Log(image);
                Debug.Log(parent);
            }
            return(node);
        }
Beispiel #26
0
 public UGUINode[] DrawLayers(Data.GroupNode[] layers, UGUINode parent)
 {
     UGUINode[] nodes = new UGUINode[layers.Length];
     if (layers != null)
     {
         for (int layerIndex = 0; layerIndex < layers.Length; layerIndex++)
         {
             nodes[layerIndex] = DrawLayer(layers[layerIndex], parent);
         }
     }
     return(nodes);
 }
Beispiel #27
0
 public UGUINode[] DrawImages(Data.ImgNode[] images, UGUINode parent)
 {
     UGUINode[] nodes = new UGUINode[images.Length];
     if (images != null)
     {
         for (int layerIndex = 0; layerIndex < images.Length; layerIndex++)
         {
             nodes[layerIndex] = DrawImage(images[layerIndex], parent);
         }
     }
     return(nodes);
 }
Beispiel #28
0
        public override UGUINode DrawLayer(Data.GroupNode layer, UGUINode parent)
        {
            UGUINode node = CreateRootNode(layer.displayName, layer.rect, parent);

            UnityEngine.UI.Toggle toggle = node.InitComponent <UnityEngine.UI.Toggle>();
            if (layer.images != null)
            {
                var bgNode = DrawBackground(layer, toggle, node);
                DrawMask(layer, toggle, bgNode);
                DrawOtherLayers(layer, node);
            }
            return(node);
        }
Beispiel #29
0
 /// <summary>
 /// 试图为Panel类型的图片添加空背景
 /// </summary>
 /// <param name="background"></param>
 /// <param name="layer"></param>
 /// <param name="node"></param>
 private void TryDrawPanel(Graphic background, Data.GroupNode layer, UGUINode node)
 {
     if (background == null)
     {
         background = node.InitComponent <UnityEngine.UI.Image>();
         SetRectTransform(layer.rect, background.GetComponent <RectTransform>());
         Color color;
         if (ColorUtility.TryParseHtmlString("#FFFFFF01", out color))
         {
             background.color = color;
         }
         background.name = layer.displayName;
     }
 }
Beispiel #30
0
        protected void StretchTitle(UGUINode node)
        {
            var texts = node.transform.GetComponentsInChildren <Text>();

            var title = Array.Find(texts, x => MatchAddress(x.name, titleAddress));

            if (title)
            {
                PSDImporterUtility.SetNormalAnchor(AnchoType.XStretch | AnchoType.YStretch, node.transform as RectTransform, title.transform as RectTransform);
                title.rectTransform.anchoredPosition = Vector3.zero;
                title.alignment          = TextAnchor.MiddleCenter;
                title.horizontalOverflow = HorizontalWrapMode.Overflow;
                title.verticalOverflow   = VerticalWrapMode.Truncate;
            }
        }