diff --git a/Assets/AkyuiUnity.Xd/Editor/XdAkyuiLoader.cs b/Assets/AkyuiUnity.Xd/Editor/XdAkyuiLoader.cs index 242613a..2645528 100644 --- a/Assets/AkyuiUnity.Xd/Editor/XdAkyuiLoader.cs +++ b/Assets/AkyuiUnity.Xd/Editor/XdAkyuiLoader.cs @@ -137,7 +137,7 @@ public XdRenderer(XdArtboard xdArtboard, XdAssetHolder xdAssetHolder, IXdObjectP if (rootArtboard.Style?.Fill != null && rootArtboard.Style.Fill.Type == "solid") { var color = rootArtboard.GetFillUnityColor(); - rootComponents.Add(new ImageComponent(null, color, Vector2Int.one)); + rootComponents.Add(new ImageComponent(null, color, Vector2Int.one, null)); } var root = new ObjectElement( diff --git a/Assets/AkyuiUnity.Xd/Editor/XdGroupParser/SvgGroupParser.cs b/Assets/AkyuiUnity.Xd/Editor/XdGroupParser/SvgGroupParser.cs index bb160be..eb4ff48 100644 --- a/Assets/AkyuiUnity.Xd/Editor/XdGroupParser/SvgGroupParser.cs +++ b/Assets/AkyuiUnity.Xd/Editor/XdGroupParser/SvgGroupParser.cs @@ -62,7 +62,8 @@ public Rect CalcSize(XdObjectJson xdObject, Rect rect) components.Add(new ImageComponent( spriteUid, new Color(1f, 1f, 1f, xdObject.Style?.Opacity ?? 1f), - Vector2Int.one + Vector2Int.one, + svgHash )); return (components.ToArray(), assets.ToArray()); diff --git a/Assets/AkyuiUnity.Xd/Editor/XdObjectParser/ShapeObjectParser.cs b/Assets/AkyuiUnity.Xd/Editor/XdObjectParser/ShapeObjectParser.cs index ef0a083..0d304a0 100644 --- a/Assets/AkyuiUnity.Xd/Editor/XdObjectParser/ShapeObjectParser.cs +++ b/Assets/AkyuiUnity.Xd/Editor/XdObjectParser/ShapeObjectParser.cs @@ -109,26 +109,31 @@ public static (ImageComponent, IAsset[]) RenderImage(XdObjectJson xdObject, Obb if (!string.IsNullOrWhiteSpace(ux?.Uid)) { string spriteUid = null; + uint? hash = null; if (!isPlaceholder) { spriteUid = $"{xdObject.GetSimpleName()}_{ux?.Uid.Substring(0, 8)}.png"; asset = new SpriteAsset(spriteUid, xdObject.Style.Fill.Pattern.Meta.Ux.HrefLastModifiedDate, obb.Size, null, border); assetHolder.Save(spriteUid, xdObject.Style.Fill.Pattern.Meta); + hash = xdObject.Style.Fill.Pattern.Meta.Ux.HrefLastModifiedDate; } imageComponent = new ImageComponent( spriteUid, color, - direction + direction, + hash ); } else if (SvgUtil.Types.Contains(shapeType)) { string spriteUid = null; + uint? hash = null; if (!isPlaceholder) { spriteUid = $"{xdObject.GetSimpleName()}_{xdObject.Id.Substring(0, 8)}.png"; var svg = SvgUtil.CreateSvg(xdObject, null, false); var svgHash = FastHash.CalculateHash(svg); + hash = svgHash; var cachedSvg = assetHolder.GetCachedSvg(svgHash); if (cachedSvg != null) @@ -146,7 +151,8 @@ public static (ImageComponent, IAsset[]) RenderImage(XdObjectJson xdObject, Obb imageComponent = new ImageComponent( spriteUid, new Color(1f, 1f, 1f, xdObject.Style?.Opacity ?? 1f), - direction + direction, + hash ); } else diff --git a/Assets/AkyuiUnity/Loader/AkyuiCompressor.cs b/Assets/AkyuiUnity/Loader/AkyuiCompressor.cs index c9e2ff1..96d8d21 100644 --- a/Assets/AkyuiUnity/Loader/AkyuiCompressor.cs +++ b/Assets/AkyuiUnity/Loader/AkyuiCompressor.cs @@ -137,6 +137,7 @@ private static Dictionary ToSerializable(IComponent source) if (imageComponent.Sprite != null) dict["sprite"] = ToSerializable(imageComponent.Sprite); if (imageComponent.Color != null) dict["color"] = ToSerializable(imageComponent.Color.Value); if (imageComponent.Direction != null) dict["direction"] = ToSerializable(imageComponent.Direction.Value); + if (imageComponent.SpriteHash != null) dict["hash"] = ToSerializable(imageComponent.SpriteHash.Value); } else if (source is MaskComponent maskComponent) { diff --git a/Assets/AkyuiUnity/Loader/AkyuiLoader.cs b/Assets/AkyuiUnity/Loader/AkyuiLoader.cs index 03530f5..a8226ca 100644 --- a/Assets/AkyuiUnity/Loader/AkyuiLoader.cs +++ b/Assets/AkyuiUnity/Loader/AkyuiLoader.cs @@ -307,7 +307,8 @@ private static ImageComponent ParseImage(Dictionary componentJso return new ImageComponent( componentJson.ContainsKey("sprite") ? JsonExtensions.ToString(componentJson["sprite"]) : null, componentJson.ContainsKey("color") ? JsonExtensions.ToColor(componentJson["color"]) : (Color?) null, - componentJson.ContainsKey("direction") ? JsonExtensions.ToVector2Int(componentJson["direction"]) : (Vector2Int?) null + componentJson.ContainsKey("direction") ? JsonExtensions.ToVector2Int(componentJson["direction"]) : (Vector2Int?) null, + componentJson.ContainsKey("hash") ? JsonExtensions.ToUint(componentJson["hash"]) : (uint?) null ); } diff --git a/Assets/AkyuiUnity/Runtime/Interface.cs b/Assets/AkyuiUnity/Runtime/Interface.cs index d7a6aeb..c9d801c 100644 --- a/Assets/AkyuiUnity/Runtime/Interface.cs +++ b/Assets/AkyuiUnity/Runtime/Interface.cs @@ -143,12 +143,14 @@ public class ImageComponent : IComponent [CanBeNull] public readonly string Sprite; [CanBeNull] public readonly Color? Color; [CanBeNull] public readonly Vector2Int? Direction; + [CanBeNull] public readonly uint? SpriteHash; - public ImageComponent([CanBeNull] string sprite, [CanBeNull] Color? color, [CanBeNull] Vector2Int? direction) + public ImageComponent([CanBeNull] string sprite, [CanBeNull] Color? color, [CanBeNull] Vector2Int? direction, [CanBeNull] uint? spriteHash) { Sprite = sprite; Color = color; Direction = direction; + SpriteHash = spriteHash; } }