private void RecordAllPsdInformation() { if (!string.IsNullOrEmpty(exporter.psdFile)) { var psd = PsdDocument.Create(exporter.psdFile); if (psd != null) { try { var rootSize = new Vector2(psd.Width, psd.Height); ExportUtility.InitPsdExportEnvrioment(exporter, rootSize); rootNode = new GroupNode(new Rect(Vector2.zero, rootSize), 0, -1); rootNode.displayName = exporter.name; var groupDatas = ExportUtility.CreatePictures(psd.Childs, rootSize, exporter.ruleObj.defultUISize, exporter.ruleObj.forceSprite); if (groupDatas != null) { foreach (var groupData in groupDatas) { rootNode.AddChild(groupData); ExportUtility.ChargeTextures(exporter, groupData); } } TreeViewUtility.TreeToList <GroupNode>(rootNode, exporter.groups, true); EditorUtility.SetDirty(exporter); } catch (Exception e) { psd.Dispose(); throw e; } psd.Dispose(); } } }
private void RecordSelectedInformation() { if (m_TreeView == null || m_TreeView.selected.Count == 0) { return; } var psdLayers = m_TreeView.selected.ConvertAll(x => x.layer as IPsdLayer).ToArray(); if (exporter == null) { exporter = ScriptableObject.CreateInstance <Exporter>(); } exporter.ruleObj = ruleObj; exporter.name = "exporter" + System.DateTime.UtcNow.ToFileTimeUtc(); ProjectWindowUtil.CreateAsset(exporter, exporter.name + ".asset"); EditorUtility.SetDirty(exporter); ExportUtility.InitPsdExportEnvrioment(exporter, new Vector2(psd.Width, psd.Height)); var rootNode = new GroupNode(new Rect(Vector2.zero, exporter.ruleObj.defultUISize), 0, -1); rootNode.displayName = exporter.name; var groupDatas = ExportUtility.CreatePictures(psdLayers, new Vector2(psd.Width, psd.Height), exporter.ruleObj.defultUISize, exporter.ruleObj.forceSprite); if (groupDatas != null) { foreach (var groupData in groupDatas) { rootNode.AddChild(groupData); ExportUtility.ChargeTextures(exporter, groupData); } } TreeViewUtility.TreeToList <GroupNode>(rootNode, exporter.groups, true); EditorUtility.SetDirty(exporter); }
public void GenerateTexture(bool all) { if (selected.Count == 0) { return; } selected.Sort((x, y) => { return(-string.Compare(x.depth.ToString(), y.depth.ToString())); }); List <KeyValuePair <PsdLayer, Texture2D> > textureList = new List <KeyValuePair <PsdLayer, Texture2D> >(); int maxWidth = 0, maxHeight = 0; List <PreviewItem> artItems = new List <PreviewItem>(); for (int i = 0; i < selected.Count; i++) { var root = selected[i]; if (all) { RetriveArtLayer(root, (x) => { if (!artItems.Contains(x)) { artItems.Add(x); } }); } else if (root.layerType != LayerType.Group && root.layerType != LayerType.Overflow) { artItems.Add(root); } } if (artItems.Count == 0) { return; } for (int i = 0; i < artItems.Count; i++) { var root = artItems[i]; var titem = ExportUtility.CreateTexture((PsdLayer)root.layer); textureList.Add(new KeyValuePair <PsdLayer, Texture2D>((PsdLayer)root.layer, titem)); maxHeight = titem.height > maxHeight ? titem.height : maxHeight; maxWidth = titem.width > maxWidth ? titem.width : maxWidth; } Texture2D texture = new Texture2D(psd.Width, psd.Height); foreach (var titem in textureList) { for (int x = 0; x < titem.Value.width; x++) { for (int y = 0; y < titem.Value.height; y++) { var color = titem.Value.GetPixel(x, y); if (color != Color.clear) { texture.SetPixel(x + titem.Key.Left, psd.Height - (titem.Value.height - y + titem.Key.Top), color); } } } } texture.Apply(); currentTexture = texture; }