public UINode DrawLayer(Layer layer, UINode parent) { UINode node = PSDImportUtility.InstantiateItem(PSDImporterConst.PREFAB_PATH_GROUP, layer.name, parent); UnityEngine.UI.LayoutGroup group = null; string type = layer.arguments[0].ToLower(); float span = 0; float.TryParse(layer.arguments[1], out span); switch (type) { case "v": group = node.AddComponent <UnityEngine.UI.VerticalLayoutGroup>(); group.childAlignment = TextAnchor.UpperLeft; ((UnityEngine.UI.VerticalLayoutGroup)group).spacing = span; break; case "h": group = node.AddComponent <UnityEngine.UI.HorizontalLayoutGroup>(); group.childAlignment = TextAnchor.UpperLeft; ((UnityEngine.UI.HorizontalLayoutGroup)group).spacing = span; break; } PSDImportUtility.SetRectTransform(layer, group.GetComponent <RectTransform>(), parent.GetComponent <RectTransform>()); UINode[] nodes = pSDImportCtrl.DrawImages(layer.images, node); foreach (var item in nodes) { item.anchoType = UINode.AnchoType.Left | UINode.AnchoType.Up; } nodes = pSDImportCtrl.DrawLayers(layer.layers, node); foreach (var item in nodes) { item.anchoType = UINode.AnchoType.Left | UINode.AnchoType.Up; } return(node); }
public UINode DrawLayer(Layer layer, UINode parent) { UINode node = PSDImportUtility.InstantiateItem(PSDImporterConst.PREFAB_PATH_GRID, layer.name, parent); node.anchoType = UINode.AnchoType.Up | UINode.AnchoType.Left; GridLayoutGroup gridLayoutGroup = node.GetComponent <GridLayoutGroup>(); PSDImportUtility.SetRectTransform(layer, gridLayoutGroup.GetComponent <RectTransform>(), node.GetComponent <RectTransform>()); gridLayoutGroup.padding = new RectOffset(1, 1, 1, 1); gridLayoutGroup.cellSize = new Vector2(layer.size.width, layer.size.height); if (layer.arguments != null && layer.arguments.Length > 1) { string rc = layer.arguments[0]; gridLayoutGroup.constraint = rc.ToLower() == "c" ? GridLayoutGroup.Constraint.FixedColumnCount : (rc.ToLower() == "r"? GridLayoutGroup.Constraint.FixedRowCount: GridLayoutGroup.Constraint.Flexible); int count = int.Parse(layer.arguments[1]); gridLayoutGroup.constraintCount = count; } ctrl.DrawImages(layer.images, node); ctrl.DrawLayers(layer.layers, node); return(node); }