private static (int Imported, int Skipped) ImportedArtboards(XdImportSettings xdSettings, AkyuiLogger logger, string xdFilePath, IAkyuiProgress progress, List <IAkyuiLoader> loaders) { logger.Log($"Xd Import Start"); var file = new XdFile(xdFilePath); var imported = 0; var skipped = 0; var targets = new List <XdArtboard>(); foreach (var artwork in file.Artworks) { if (artwork.Artboard.Children.Length == 0) { continue; } var markForExport = artwork.Artboard.Children[0].Meta?.Ux?.MarkedForExport ?? false; if (!markForExport) { continue; } targets.Add(artwork); } progress.SetTotal(targets.Count); foreach (var artwork in targets) { using (progress.TaskStart(artwork.Name)) { var akyuiXdObjectParsers = xdSettings.ObjectParsers ?? new AkyuiXdObjectParser[] { }; var akyuiXdGroupParsers = xdSettings.GroupParsers ?? new AkyuiXdGroupParser[] { }; var triggers = xdSettings.XdTriggers ?? new AkyuiXdImportTrigger[] { }; var name = artwork.Name; var xdHash = FastHash.CalculateHash(JsonConvert.SerializeObject(artwork.Artboard) + JsonConvert.SerializeObject(artwork.Resources)); var userData = new Dictionary <string, string> { { "xd_hash", xdHash.ToString() } }; var pathGetter = new PathGetter(xdSettings, name); var prevMetaGameObject = AssetDatabase.LoadAssetAtPath <GameObject>(pathGetter.MetaSavePath); var prevMeta = prevMetaGameObject != null?prevMetaGameObject.GetComponent <AkyuiMeta>() : null; var prevMetaUserData = prevMeta != null?prevMeta.FindUserData("xd_hash") : null; if (!xdSettings.ReimportLayout && !xdSettings.ReimportAsset && prevMetaUserData != null && prevMetaUserData.value == xdHash.ToString()) { logger.Log("Skip", ("hash", xdHash)); skipped++; continue; } loaders.Add(new XdAkyuiLoader(file, artwork, name, userData, akyuiXdObjectParsers, akyuiXdGroupParsers, triggers)); imported++; } } logger.Log($"Xd Import Finish", ("imported", imported), ("skipped", skipped)); return(imported, skipped); }
public XdAssetHolder(XdFile xdFile) { _xdFile = xdFile; _fileNameToMeta = new Dictionary <string, XdStyleFillPatternMetaJson>(); _fileNameToBytes = new Dictionary <string, byte[]>(); _fileNameToGenerators = new Dictionary <string, Func <byte[]> >(); _svgHash = new Dictionary <uint, CachedSvg>(); }
public XdAkyuiLoader(XdFile xdFile, XdArtboard xdArtboard, string name, Dictionary <string, string> userData, AkyuiXdObjectParser[] objectParsers, AkyuiXdGroupParser[] groupParsers, AkyuiXdImportTrigger[] triggers) { _xdFile = xdFile; _objectParsers = objectParsers.Concat(DefaultObjectParsers).ToArray(); _groupParsers = groupParsers.Concat(DefaultGroupParsers).ToArray(); _triggers = triggers; _assetHolder = new XdAssetHolder(_xdFile); (LayoutInfo, AssetsInfo) = Create(xdArtboard, _assetHolder, name, userData); }
public void Dispose() { _xdFile?.Dispose(); _xdFile = null; }
private static (int Imported, int Skipped) ImportedArtboards(XdImportSettings xdSettings, AkyuiLogger logger, string xdFilePath, IAkyuiProgress progress, List <IAkyuiLoader> loaders) { var stopWatch = Stopwatch.StartNew(); var file = new XdFile(xdFilePath); XdFile = file; using (Disposable.Create(() => XdFile = null)) { var imported = 0; var skipped = 0; var targets = new List <XdArtboard>(); foreach (var artwork in file.Artworks) { if (artwork.Artboard.Children.Length == 0) { continue; } var markForExport = artwork.Artboard.Children[0].Meta?.Ux?.MarkedForExport ?? false; if (!markForExport) { continue; } targets.Add(artwork); } progress.SetTotal(targets.Count); var akyuiXdObjectParsers = xdSettings.ObjectParsers ?? new AkyuiXdObjectParser[] { }; var akyuiXdGroupParsers = xdSettings.GroupParsers ?? new AkyuiXdGroupParser[] { }; var triggers = xdSettings.XdTriggers ?? new AkyuiXdImportTrigger[] { }; var expandTargets = new List <XdArtboard>(); foreach (var artwork in targets) { if (!artwork.HasParameter("expand")) { expandTargets.Add(artwork); continue; } foreach (var child in artwork.Artboard.Children.SelectMany(x => x.Artboard.Children)) { var childArtboardJson = new XdArtboardJson { Version = artwork.Artboard.Version, Artboards = artwork.Artboard.Artboards, Resources = artwork.Artboard.Resources, Children = new[] { new XdArtboardChildJson { Artboard = new XdArtboardChildArtboardJson { Children = new[] { child } } } } }; var childArtboard = new XdArtboard($"{artwork.GetSimpleName()}{child.GetSimpleName()}", artwork.Manifest, childArtboardJson, artwork.Resources, artwork.Hash); expandTargets.Add(childArtboard); } } foreach (var artwork in expandTargets) { using (progress.TaskStart(artwork.Name)) using (var _ = logger.SetCategory(artwork.Name)) { var name = artwork.Name.ToSafeString(); var xdHash = artwork.Hash; var userData = new Dictionary <string, string> { { "xd_hash", xdHash.ToString() } }; var pathGetter = new PathGetter(xdSettings, name); var prevMetaGameObject = AssetDatabase.LoadAssetAtPath <GameObject>(pathGetter.MetaSavePath); var prevMeta = prevMetaGameObject != null?prevMetaGameObject.GetComponent <AkyuiMeta>() : null; var prevMetaUserData = prevMeta != null?prevMeta.FindUserData("xd_hash") : null; if (!xdSettings.ReimportLayout && !xdSettings.ReimportAsset && prevMetaUserData != null && prevMetaUserData.value == xdHash.ToString()) { logger.Log("Skip", ("Name", artwork.Name), ("Hash", xdHash)); skipped++; continue; } loaders.Add(new XdAkyuiLoader(file, artwork, name, userData, akyuiXdObjectParsers, akyuiXdGroupParsers, triggers)); imported++; } } stopWatch.Stop(); logger.Log($"Xd Parse Finish", ("ImportArtboard", imported), ("SkipArtboard", skipped), ("Time", $"{stopWatch.Elapsed.TotalSeconds:0.00}s")); return(imported, skipped); } }