private void DrawUICreateOption() { using (var hor = new EditorGUILayout.HorizontalScope()) { var style = "miniButton"; var layout = GUILayout.Width(60); if (GUILayout.Button("Build-All", style, layout)) { var canvasObj = Array.Find(Selection.objects, x => x is GameObject && (x as GameObject).GetComponent <Canvas>() != null); var ctrl = PSDImporterUtility.CreatePsdImportCtrlSafty(exporter.ruleObj, exporter.ruleObj.defultUISize, canvasObj == null ? FindObjectOfType <Canvas>() : (canvasObj as GameObject).GetComponent <Canvas>()); ctrl.Import(rootNode.data); AssetDatabase.Refresh(); } if (GUILayout.Button("Build-Sel", style, layout)) { var canvasObj = Array.Find(Selection.objects, x => x is GameObject && (x as GameObject).GetComponent <Canvas>() != null); var ctrl = PSDImporterUtility.CreatePsdImportCtrlSafty(exporter.ruleObj, exporter.ruleObj.defultUISize, canvasObj == null ? FindObjectOfType <Canvas>() : (canvasObj as GameObject).GetComponent <Canvas>()); var root = new GroupNodeItem(new Rect(Vector2.zero, rootNode.rect.size), 0, -1); root.displayName = "partial build"; foreach (var node in m_TreeView.selected) { root.AddChild(node); } ctrl.Import(root.data); AssetDatabase.Refresh(); } if (GUILayout.Button("Expland", style, layout)) { m_TreeView.ExpandAll(); } if (GUILayout.Button("Clear", style, layout)) { exporter.groups.Clear(); m_TreeView.root = null; m_TreeView.Reload(); } } }
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 GroupNodeItem(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); } } var list = new List <GroupNodeItem>(); TreeViewUtility.TreeToList <GroupNodeItem>(rootNode, list, true); exporter.groups = list.ConvertAll(x => x.data); EditorUtility.SetDirty(exporter); } catch (Exception e) { throw e; } finally { psd.Dispose(); } } } }
/// <summary> /// 转换为组 /// </summary> /// <param name="layer"></param> /// <param name="group"></param> /// <param name="OnRetrive"></param> public static void RetriveLayerToSwitchModle(Vector2 rootSize, PsdLayer layer, GroupNodeItem group, bool forceSprite = false) { if (!layer.IsGroup) { return; } else { float index = 0; foreach (var child in layer.Childs) { var progress = ++index / layer.Childs.Length; EditorUtility.DisplayProgressBar(layer.Name, "转换进度:" + progress, progress); if (child.IsGroup) { GroupNodeItem childNode = new GroupNodeItem(GetRectFromLayer(child), idSpan++, group.depth + 1); childNode.Analyzing(RuleObj, child.Name); group.AddChild(childNode); if (childNode != null) { RetriveLayerToSwitchModle(rootSize, child, childNode, forceSprite); } } else { Data.ImgNode imgnode = AnalysisLayer(group.displayName, rootSize, child, forceSprite); if (imgnode != null) { group.images.Add(imgnode); } } } EditorUtility.ClearProgressBar(); } }
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 <Data.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 GroupNodeItem(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); } } var list = new List <GroupNodeItem>(); TreeViewUtility.TreeToList <GroupNodeItem>(rootNode, list, true); exporter.groups = list.ConvertAll(x => x.data); EditorUtility.SetDirty(exporter); }