public void BeginSetUIParents(UGUINode node) { foreach (var item in node.childs) { item.transform.SetParent(node.transform); BeginSetUIParents(item); } }
public void BeginSetAnchers(UGUINode node) { foreach (var item in node.childs) { BeginSetAnchers(item); PSDImportUtility.SetAnchorByNode(item); } }
public UGUINode(Transform transform, UGUINode parent) { this.transform = transform; this.parent = parent; if (parent != null) { parent.childs.Add(this); } }
private UGUINode DrawRawImage(ImgNode image, UGUINode parent) { UGUINode node = PSDImportUtility.InstantiateItem(GroupType.RawIMAGE, image.sprite.name, parent); UnityEngine.UI.RawImage pic = node.InitComponent <UnityEngine.UI.RawImage>(); PSDImportUtility.SetPictureOrLoadColor(image, pic); PSDImportUtility.SetRectTransform(image, pic.GetComponent <RectTransform>()); return(node); }
public static UGUINode InstantiateItem(GroupType groupType, string name, UGUINode parent) { GameObject prefab = rouleObject.prefabs.Find(x => x.groupType == groupType).prefab; GameObject item = GameObject.Instantiate(prefab) as GameObject; item.name = name; item.transform.SetParent(canvas.transform, false); UGUINode node = new UGUINode(item.transform, parent); return(node); }
public UGUINode DrawLayer(GroupNode layer, UGUINode parent) { UGUINode node = PSDImportUtility.InstantiateItem(GroupType.SCROLLBAR, layer.Name, parent); Scrollbar scrollBar = node.InitComponent <Scrollbar>(); switch (layer.direction) { case Direction.LeftToRight: scrollBar.direction = Scrollbar.Direction.LeftToRight; break; case Direction.BottomToTop: scrollBar.direction = Scrollbar.Direction.BottomToTop; break; case Direction.TopToBottom: scrollBar.direction = Scrollbar.Direction.TopToBottom; break; case Direction.RightToLeft: scrollBar.direction = Scrollbar.Direction.RightToLeft; break; default: break; } for (int i = 0; i < layer.images.Count; i++) { ImgNode image = layer.images[i]; string lowerName = image.Name.ToLower(); UnityEngine.UI.Image graph = null; if (lowerName.StartsWith("b_")) { graph = scrollBar.GetComponent <UnityEngine.UI.Image>(); PSDImportUtility.SetRectTransform(image, scrollBar.GetComponent <RectTransform>()); scrollBar.name = layer.Name; } else if (lowerName.StartsWith("h_")) { graph = scrollBar.handleRect.GetComponent <UnityEngine.UI.Image>(); } if (graph == null) { //忽略Scorllbar其他的artLayer continue; } PSDImportUtility.SetPictureOrLoadColor(image, graph); } return(node); }
public void BeginReprocess(UGUINode node) { foreach (var item in node.childs) { BeginReprocess(item); } if (node.ReprocessEvent != null) { node.ReprocessEvent(); } }
public UGUINode[] DrawImages(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); }
public UGUINode[] DrawLayers(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); }
public void BeginDrawUILayers(GroupNode1[] groups, Vector2 uiSize) { UGUINode empty = PSDImportUtility.InstantiateItem(GroupType.EMPTY, "PSDUnity", PSDImportUtility.uinode); RectTransform rt = empty.InitComponent <RectTransform>(); rt.sizeDelta = new Vector2(uiSize.x, uiSize.y); for (int layerIndex = 0; layerIndex < groups.Length; layerIndex++) { DrawLayer(groups[layerIndex] as GroupNode, empty); } AssetDatabase.Refresh(); }
public UGUINode DrawLayer(GroupNode layer, UGUINode parent) { UGUINode node = null; switch (layer.groupType) { case GroupType.EMPTY: case GroupType.IMAGE: node = panelImport.DrawLayer(layer, parent); break; case GroupType.BUTTON: node = buttonImport.DrawLayer(layer, parent); break; case GroupType.TOGGLE: node = toggleImport.DrawLayer(layer, parent); break; case GroupType.GRID: node = gridImport.DrawLayer(layer, parent); break; case GroupType.SCROLLVIEW: node = scrollViewImport.DrawLayer(layer, parent); break; case GroupType.SLIDER: node = sliderImport.DrawLayer(layer, parent); break; case GroupType.GROUP: node = groupImport.DrawLayer(layer, parent); break; case GroupType.INPUTFIELD: node = inputFiledImport.DrawLayer(layer, parent); break; case GroupType.SCROLLBAR: node = scrollBarImport.DrawLayer(layer, parent); break; case GroupType.DROPDOWN: node = dropdownImport.DrawLayer(layer, parent); break; default: break; } return(node); }
public UGUINode DrawImage(ImgNode image, UGUINode parent) { UGUINode node = PSDImportUtility.InstantiateItem(GroupType.TEXT, image.Name, parent); UnityEngine.UI.Text myText = node.InitComponent <Text>(); PSDImportUtility.SetPictureOrLoadColor(image, myText); RectTransform rectTransform = myText.GetComponent <RectTransform>(); AdjustImage(image, myText.fontSize); rectTransform.sizeDelta = new Vector2(image.rect.width, image.rect.height); rectTransform.anchoredPosition = new Vector2(image.rect.x, image.rect.y); return(node); }
public static Canvas InitEnviroment(RouleObject arg, Vector2 uiSize) { rouleObject = arg; var canvasPfb = rouleObject.prefabs.Find(x => x.groupType == GroupType.CANVAS).prefab; canvas = GameObject.Instantiate(canvasPfb).GetComponent <Canvas>(); canvas.renderMode = RenderMode.ScreenSpaceOverlay; UnityEngine.UI.CanvasScaler scaler = PSDImportUtility.canvas.GetComponent <UnityEngine.UI.CanvasScaler>(); scaler.referenceResolution = new Vector2(uiSize.x, uiSize.y); uinode = new UGUINode(PSDImportUtility.canvas.transform, null); return(canvas); }
public static void SetAnchorByNode(UGUINode node) { RectTransform p_rt = node.parent.InitComponent <RectTransform>(); RectTransform c_rt = node.InitComponent <RectTransform>(); switch (node.anchoType) { case AnchoType.Custom: SetCustomAnchor(p_rt, c_rt); break; default: SetNormalAnchor(node.anchoType, p_rt, c_rt); break; } }
public UGUINode DrawImage(ImgNode image, UGUINode parent) { UGUINode node = null; switch (image.type) { case ImgType.Image: case ImgType.AtlasImage: node = DrawNormalImage(image, parent); break; case ImgType.Texture: node = DrawRawImage(image, parent); break; default: break; } return(node); }
public UGUINode DrawImage(ImgNode image, UGUINode parent) { UGUINode node = null; switch (image.type) { case ImgType.Image: case ImgType.Texture: case ImgType.AtlasImage: node = spriteImport.DrawImage(image, parent); break; case ImgType.Label: node = textImport.DrawImage(image, parent); break; default: break; } return(node); }
public UGUINode DrawLayer(GroupNode layer, UGUINode parent) { UGUINode node = PSDImportUtility.InstantiateItem(GroupType.INPUTFIELD, layer.Name, parent); UnityEngine.UI.InputField inputfield = node.InitComponent <UnityEngine.UI.InputField>(); if (layer.images != null) { for (int imageIndex = 0; imageIndex < layer.images.Count; imageIndex++) { ImgNode image = layer.images[imageIndex]; string lowerName = image.Name.ToLower(); if (image.type == ImgType.Label) { if (lowerName.StartsWith("t_")) { UnityEngine.UI.Text text = (UnityEngine.UI.Text)inputfield.textComponent;//inputfield.transform.Find("Text").GetComponent<UnityEngine.UI.Text>(); PSDImportUtility.SetPictureOrLoadColor(image, text); } else if (lowerName.StartsWith("p_")) { UnityEngine.UI.Text text = (UnityEngine.UI.Text)inputfield.placeholder;//.transform.Find("Placeholder").GetComponent<UnityEngine.UI.Text>(); PSDImportUtility.SetPictureOrLoadColor(image, text); } } else { if (lowerName.StartsWith("b_")) { PSDImportUtility.SetPictureOrLoadColor(image, inputfield.image); PSDImportUtility.SetRectTransform(image, inputfield.GetComponent <RectTransform>()); } } } } return(node); }
public UGUINode DrawLayer(GroupNode layer, UGUINode parent) { UGUINode node = PSDImportUtility.InstantiateItem(GroupType.IMAGE, layer.Name, parent);//GameObject.Instantiate(temp) as UnityEngine.UI.Image; UnityEngine.UI.Image panel = node.InitComponent <UnityEngine.UI.Image>(); ctrl.DrawLayers(layer.groups.ToArray(), node);//子节点 bool havebg = false; for (int i = 0; i < layer.images.Count; i++) { ImgNode image = layer.images[i]; if (image.Name.ToLower().StartsWith("b_")) { havebg = true; PSDImportUtility.SetPictureOrLoadColor(image, panel); PSDImportUtility.SetRectTransform(image, panel.GetComponent <RectTransform>()); panel.name = layer.Name; } else { ctrl.DrawImage(image, node); } } if (!havebg) { PSDImportUtility.SetRectTransform(layer, panel.GetComponent <RectTransform>()); Color color; if (ColorUtility.TryParseHtmlString("#FFFFFF01", out color)) { panel.GetComponent <UnityEngine.UI.Image>().color = color; } panel.name = layer.Name; } return(node); }
public UGUINode DrawLayer(GroupNode layer, UGUINode parent) { UGUINode node = PSDImportUtility.InstantiateItem(GroupType.BUTTON, layer.Name, parent); UnityEngine.UI.Button button = node.InitComponent <UnityEngine.UI.Button>(); PSDImportUtility.SetRectTransform(layer, button.GetComponent <RectTransform>()); if (layer.images != null) { for (int imageIndex = 0; imageIndex < layer.images.Count; imageIndex++) { ImgNode image = layer.images[imageIndex]; string lowerName = image.Name.ToLower(); if (lowerName.StartsWith("n_") || lowerName.StartsWith("p_") || lowerName.StartsWith("d_") || lowerName.StartsWith("h_")) { if (lowerName.StartsWith("n_")) { PSDImportUtility.SetRectTransform(image, button.GetComponent <RectTransform>()); } if (image.color == UnityEngine.Color.white) { SetSpriteSwipe(image, button); } else { SetColorSwipe(image, button); } } else { ctrl.DrawImage(image, node); } } } return(node); }
public UGUINode DrawLayer(GroupNode layer, UGUINode parent) { UGUINode node = PSDImportUtility.InstantiateItem(GroupType.GROUP, layer.Name, parent); UnityEngine.UI.LayoutGroup group = null; switch (layer.direction) { case Direction.Horizontal: group = node.InitComponent <UnityEngine.UI.HorizontalLayoutGroup>(); group.childAlignment = TextAnchor.UpperLeft; break; case Direction.Vertical: group = node.InitComponent <UnityEngine.UI.VerticalLayoutGroup>(); group.childAlignment = TextAnchor.UpperLeft; break; default: break; } ((UnityEngine.UI.VerticalLayoutGroup)group).spacing = layer.spacing; PSDImportUtility.SetRectTransform(layer, group.GetComponent <RectTransform>()); UGUINode[] nodes = pSDImportCtrl.DrawImages(layer.images.ToArray(), node); foreach (var item in nodes) { item.anchoType = AnchoType.Left | AnchoType.Up; } nodes = pSDImportCtrl.DrawLayers(layer.groups.ToArray(), node); foreach (var item in nodes) { item.anchoType = AnchoType.Left | AnchoType.Up; } return(node); }
public UGUINode DrawLayer(GroupNode layer, UGUINode parent) { UGUINode node = PSDImportUtility.InstantiateItem(GroupType.SCROLLVIEW, layer.Name, parent); UnityEngine.UI.ScrollRect scrollRect = node.InitComponent <UnityEngine.UI.ScrollRect>(); UGUINode childNode = PSDImportUtility.InstantiateItem(GroupType.IMAGE, "Viewport", node); scrollRect.viewport = childNode.InitComponent <RectTransform>(); Color color; if (ColorUtility.TryParseHtmlString("#FFFFFF01", out color)) { childNode.InitComponent <UnityEngine.UI.Image>().color = color; } childNode.InitComponent <Mask>(); childNode.anchoType = AnchoType.XStretch | AnchoType.YStretch; bool havebg = false; for (int i = 0; i < layer.images.Count; i++) { ImgNode image = layer.images[i]; if (image.Name.ToLower().StartsWith("b_")) { havebg = true; UnityEngine.UI.Image graph = node.InitComponent <UnityEngine.UI.Image>(); PSDImportUtility.SetPictureOrLoadColor(image, graph); PSDImportUtility.SetRectTransform(image, scrollRect.GetComponent <RectTransform>()); } else { ctrl.DrawImage(image, node); } } if (!havebg) { PSDImportUtility.SetRectTransform(layer, scrollRect.GetComponent <RectTransform>()); } PSDImportUtility.SetRectTransform(layer, childNode.InitComponent <RectTransform>()); switch (layer.direction) { case Direction.Horizontal: scrollRect.vertical = true; scrollRect.horizontal = false; break; case Direction.Vertical: scrollRect.vertical = false; scrollRect.horizontal = true; break; case Direction.Horizontal | Direction.Vertical: scrollRect.vertical = true; scrollRect.horizontal = true; break; default: break; } if (layer.groups != null) { for (int i = 0; i < layer.groups.Count; i++) { GroupNode child = layer.groups[i]; string childLowerName = child.Name; UGUINode c_Node = ctrl.DrawLayer(child, childNode); if (childLowerName.StartsWith("c_")) { scrollRect.content = c_Node.InitComponent <RectTransform>(); } else if (childLowerName.StartsWith("vb_")) { scrollRect.verticalScrollbar = c_Node.InitComponent <Scrollbar>(); scrollRect.verticalScrollbarVisibility = ScrollRect.ScrollbarVisibility.AutoHide; } else if (childLowerName.StartsWith("hb_")) { scrollRect.horizontalScrollbar = c_Node.InitComponent <Scrollbar>(); scrollRect.horizontalScrollbarVisibility = ScrollRect.ScrollbarVisibility.AutoHide; } } } return(node); }
public UGUINode DrawLayer(GroupNode layer, UGUINode parent) { UGUINode node = PSDImportUtility.InstantiateItem(GroupType.DROPDOWN, layer.Name, parent); Dropdown dropdown = node.InitComponent <Dropdown>(); ScrollRect scrllRect = dropdown.template.GetComponent <ScrollRect>(); RectTransform content = scrllRect.content; Toggle toggle = content.GetComponentInChildren <Toggle>(); UGUINode childNode = new UGUINode(dropdown.template, node); childNode.transform.SetParent(PSDImportUtility.canvas.transform); childNode.anchoType = AnchoType.Down | AnchoType.XStretch; //由于设置相对坐标需要,所以修改了部分预制体的状态 childNode.ReprocessEvent = () => { RectTransform rt = childNode.InitComponent <RectTransform>(); rt.pivot = new Vector2(0.5f, 1); rt.anchoredPosition = Vector3.zero; }; for (int i = 0; i < layer.images.Count; i++) { ImgNode image = layer.images[i]; string lowerName = image.Name.ToLower(); if (lowerName.StartsWith("b1_")) { PSDImportUtility.SetPictureOrLoadColor(image, dropdown.image); PSDImportUtility.SetRectTransform(image, dropdown.GetComponent <RectTransform>()); dropdown.name = layer.Name; } else if (lowerName.StartsWith("b2_")) { PSDImportUtility.SetPictureOrLoadColor(image, dropdown.template.GetComponent <Graphic>()); PSDImportUtility.SetRectTransform(image, dropdown.template); } else if (lowerName.StartsWith("b3_")) { UnityEngine.UI.Image itemimage = (UnityEngine.UI.Image)toggle.targetGraphic; PSDImportUtility.SetPictureOrLoadColor(image, itemimage); content.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, image.rect.height); } else if (lowerName.StartsWith("t1_")) { PSDImportUtility.SetPictureOrLoadColor(image, dropdown.captionText); } else if (lowerName.StartsWith("t2_")) { PSDImportUtility.SetPictureOrLoadColor(image, dropdown.itemText); } else if (lowerName.StartsWith("m_")) { UnityEngine.UI.Image mask = (UnityEngine.UI.Image)toggle.graphic; PSDImportUtility.SetPictureOrLoadColor(image, mask); } else { ctrl.DrawImage(image, node); } } for (int i = 0; i < layer.groups.Count; i++) { GroupNode child = layer.groups[i] as GroupNode; string lowerName = child.Name; if (lowerName.StartsWith("vb_")) { UGUINode barNode = ctrl.DrawLayer(child, childNode); scrllRect.verticalScrollbar = barNode.InitComponent <Scrollbar>(); scrllRect.verticalScrollbarVisibility = ScrollRect.ScrollbarVisibility.AutoHide; } else { ctrl.DrawLayer(child, node); } } return(node); }
public UGUINode DrawLayer(GroupNode layer, UGUINode parent) { UGUINode node = PSDImportUtility.InstantiateItem(GroupType.SLIDER, layer.Name, parent); //GameObject.Instantiate(temp) as UnityEngine.UI.Slider; UnityEngine.UI.Slider slider = node.InitComponent <UnityEngine.UI.Slider>(); PSDImportUtility.SetRectTransform(layer, slider.GetComponent <RectTransform>()); slider.value = 1; ImgNode bg = layer.images.Find(x => x.Name.ToLower().StartsWith("b_")); ImgNode fill = layer.images.Find(x => x.Name.ToLower().StartsWith("f_")); ImgNode handle = layer.images.Find(x => x.Name.ToLower().StartsWith("h_")); if (bg != null) { var graph = node.InitComponent <UnityEngine.UI.Image>(); PSDImportUtility.SetPictureOrLoadColor(bg, graph); } if (fill != null) { var fillAreaNode = PSDImportUtility.InstantiateItem(GroupType.EMPTY, "Fill Area", node); var fileNode = ctrl.DrawImage(fill, fillAreaNode); fileNode.InitComponent <Image>().type = Image.Type.Tiled; PSDImportUtility.SetRectTransform(fill, fillAreaNode.InitComponent <RectTransform>()); fillAreaNode.ReprocessEvent = () => { slider.fillRect = fileNode.InitComponent <RectTransform>(); }; } if (handle != null && bg != null) { var tempRect = fill != null ? fill : bg; SetSlider(slider, handle, layer); var handAreaNode = PSDImportUtility.InstantiateItem(GroupType.EMPTY, "Handle Slide Area", node); var handNode = ctrl.DrawImage(handle, handAreaNode); PSDImportUtility.SetRectTransform(tempRect, handAreaNode.InitComponent <RectTransform>()); switch (layer.direction) { case Direction.LeftToRight: handNode.anchoType = AnchoType.Right | AnchoType.YStretch; break; case Direction.BottomToTop: handNode.anchoType = AnchoType.Up | AnchoType.XStretch; break; case Direction.TopToBottom: handNode.anchoType = AnchoType.Down | AnchoType.XStretch; break; case Direction.RightToLeft: handNode.anchoType = AnchoType.Left | AnchoType.YStretch; break; default: break; } handNode.ReprocessEvent = () => { slider.handleRect = handNode.InitComponent <RectTransform>(); slider.handleRect.anchoredPosition = Vector3.zero; }; } else { SetSlider(slider, layer.direction); } return(node); }