示例#1
0
        private (LayoutInfo, AssetsInfo) Create(XdArtboard xdArtboard, XdAssetHolder assetHolder, string name, Dictionary <string, string> userData)
        {
            var renderer = new XdRenderer(xdArtboard, assetHolder, _objectParsers, _groupParsers, _triggers);

            var layoutInfoForCalcHash = new LayoutInfo(
                name,
                0,
                renderer.Meta,
                new Dictionary <string, string>(),
                renderer.Root,
                renderer.Elements.ToArray()
                );
            var hash = FastHash.CalculateHash(JsonConvert.SerializeObject(AkyuiCompressor.ToSerializable(layoutInfoForCalcHash)));

            var layoutInfo = new LayoutInfo(
                name,
                hash,
                renderer.Meta,
                userData,
                renderer.Root,
                renderer.Elements.ToArray()
                );

            var assetsInfo = new AssetsInfo(
                renderer.Assets.ToArray()
                );

            return(layoutInfo, assetsInfo);
        }
示例#2
0
 public (IComponent[], IAsset[]) Render(XdObjectJson xdObject, XdAssetHolder assetHolder, IObbGetter obbGetter)
 {
     return(new IComponent[]
     {
         new InputFieldComponent()
     }, new IAsset[] { });
 }
示例#3
0
        public (IComponent[], IAsset[]) Render(XdObjectJson xdObject, XdAssetHolder assetHolder, IObbGetter obbGetter)
        {
            var repeatGrid = xdObject.Meta?.Ux?.RepeatGrid ?? new XdRepeatGridJson();

            var item = xdObject.Group.Children[0].Group.Children[0];

            xdObject.Group.Children = new[] { item };

            // Visible設定によりSpacingが変わってくるので計算しなおす
            var childSize = obbGetter.Get(item).Size;

            if (repeatGrid.Columns > 1 && repeatGrid.Rows > 1)
            {
                return(new IComponent[]
                {
                    new GridLayoutComponent(repeatGrid.PaddingX, repeatGrid.PaddingY)
                }, new IAsset[] { });
            }
            else if (repeatGrid.Columns > 1)
            {
                var spacing = repeatGrid.PaddingX + repeatGrid.CellWidth - childSize.x;
                return(new IComponent[]
                {
                    new HorizontalLayoutComponent(spacing)
                }, new IAsset[] { });
            }
            else
            {
                var spacing = repeatGrid.PaddingY + repeatGrid.CellHeight - childSize.y;
                return(new IComponent[]
                {
                    new VerticalLayoutComponent(spacing)
                }, new IAsset[] { });
            }
        }
示例#4
0
        public (IComponent[], IAsset[]) Render(XdObjectJson xdObject, XdAssetHolder assetHolder, IObbGetter obbGetter)
        {
            var components = new List <IComponent>();
            var assets     = new List <IAsset>();

            var color = xdObject.GetFillUnityColor();
            var svg   = SvgUtil.CreateSvg(xdObject);

            xdObject.Group.Children = new XdObjectJson[] { };

            var size      = obbGetter.Get(xdObject).Size;
            var spriteUid = $"{xdObject.GetSimpleName()}_{xdObject.Id.Substring(0, 8)}.png";
            var svgHash   = FastHash.CalculateHash(svg);

            var cachedSvg = assetHolder.GetCachedSvg(svgHash);

            if (cachedSvg != null)
            {
                spriteUid = cachedSvg.SpriteUid;
            }
            else
            {
                assets.Add(new SpriteAsset(spriteUid, svgHash, size, null, null));
                var xdImportSettings = XdImporter.Settings;
                assetHolder.Save(spriteUid, () => SvgToPng.Convert(svg, size, xdImportSettings));
                assetHolder.SaveCacheSvg(spriteUid, svgHash);
            }
            components.Add(new ImageComponent(
                               spriteUid,
                               new Color(1f, 1f, 1f, color.a),
                               Vector2Int.one
                               ));

            return(components.ToArray(), assets.ToArray());
        }
示例#5
0
        public (IComponent[], IAsset[]) Render(XdObjectJson xdObject, XdAssetHolder assetHolder, IObbGetter obbGetter)
        {
            var repeatGrid = xdObject.Meta?.Ux?.RepeatGrid ?? new XdRepeatGridJson();

            var item = xdObject.Group.Children[0].Group.Children[0];

            xdObject.Group.Children = new[] { item };

            if (repeatGrid.Columns > 1 && repeatGrid.Rows > 1)
            {
                return(new IComponent[]
                {
                    new GridLayoutComponent(repeatGrid.PaddingX, repeatGrid.PaddingY)
                }, new IAsset[] { });
            }
            else if (repeatGrid.Columns > 1)
            {
                return(new IComponent[]
                {
                    new HorizontalLayoutComponent(repeatGrid.PaddingX)
                }, new IAsset[] { });
            }
            else
            {
                return(new IComponent[]
                {
                    new VerticalLayoutComponent(repeatGrid.PaddingY)
                }, new IAsset[] { });
            }

            throw new Exception();
        }
示例#6
0
        public (IComponent[], IAsset[]) Render(XdObjectJson xdObject, XdAssetHolder assetHolder, IObbGetter obbGetter)
        {
            var spacing         = 0f;
            var scrollingType   = xdObject.Meta?.Ux?.ScrollingType;
            var specialSpacings = new List <SpecialSpacing>();
            var repeatGrid      = xdObject.Group?.Children?.FirstOrDefault(x => RepeatGridGroupParser.Is(x));

            if (scrollingType == "vertical")
            {
                var paddingTop    = 0f;
                var paddingBottom = GetSpacerSize(xdObject, obbGetter);

                if (repeatGrid != null)
                {
                    XdObjectJson[] newChildren;
                    (newChildren, spacing) = ExpandRepeatGridGroup(xdObject, repeatGrid, scrollingType, obbGetter, ref specialSpacings);

                    xdObject.Group.Children = xdObject.Group.Children.Where(x => x != repeatGrid).Concat(newChildren).ToArray();

                    var rootObb = obbGetter.Get(xdObject);
                    paddingTop = newChildren.Select(x => obbGetter.Get(x).CalcObbInWorld(rootObb).CalcLocalRect().yMin).Min();
                    if (paddingTop < 0f)
                    {
                        paddingTop = 0f;
                    }
                }

                return(new IComponent[]
                {
                    new VerticalListComponent(spacing, paddingTop, paddingBottom, specialSpacings.ToArray()),
                }, new IAsset[] { });
            }
            else
            {
                var paddingLeft  = 0f;
                var paddingRight = GetSpacerSize(xdObject, obbGetter);

                if (repeatGrid != null)
                {
                    XdObjectJson[] newChildren;
                    (newChildren, spacing) = ExpandRepeatGridGroup(xdObject, repeatGrid, scrollingType, obbGetter, ref specialSpacings);

                    xdObject.Group.Children = xdObject.Group.Children.Where(x => x != repeatGrid).Concat(newChildren).ToArray();

                    var rootObb = obbGetter.Get(xdObject);
                    paddingLeft = newChildren.Select(x => obbGetter.Get(x).CalcObbInWorld(rootObb).CalcLocalRect().xMin).Min();
                    if (paddingLeft < 0f)
                    {
                        paddingLeft = 0f;
                    }
                }

                return(new IComponent[]
                {
                    new HorizontalListComponent(spacing, paddingLeft, paddingRight, specialSpacings.ToArray()),
                }, new IAsset[] { });
            }
        }
示例#7
0
        public (IComponent[], IAsset[]) Render(XdObjectJson xdObject, XdAssetHolder assetHolder, IObbGetter obbGetter)
        {
            var opacity = xdObject.Style?.Opacity ?? 1.0f;

            return(new IComponent[]
            {
                new AlphaComponent(opacity)
            }, new IAsset[] { });
        }
示例#8
0
 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);
 }
示例#9
0
        public (IComponent[], IAsset[]) Render(XdObjectJson xdObject, Obb obb, XdAssetHolder assetHolder)
        {
            var(imageComponent, assets) = ShapeObjectParser.RenderImage(xdObject, obb, assetHolder);

            IComponent scrollbar = new VerticalScrollbarComponent(imageComponent);

            if (xdObject.HasParameter("horizontal"))
            {
                scrollbar = new HorizontalScrollbarComponent(imageComponent);
            }
            return(new[] { scrollbar }, assets);
        }
示例#10
0
        public (IComponent[], IAsset[]) Render(XdObjectJson xdObject, Obb obb, XdAssetHolder assetHolder)
        {
            var components = new List <IComponent>();

            var font     = xdObject.Style.Font;
            var fontSize = font.Size;
            var color    = xdObject.GetFillUnityColor();
            var rawText  = xdObject.Text.RawText;

            var textAlign      = TextComponent.TextAlign.MiddleLeft;
            var wrap           = false;
            var paragraphAlign = xdObject.Style?.TextAttributes?.ParagraphAlign ?? "left";

            if (xdObject.Text?.Frame?.Type == "positioned")
            {
                wrap = false;
                if (paragraphAlign == "left")
                {
                    textAlign = TextComponent.TextAlign.MiddleLeft;
                }
                if (paragraphAlign == "center")
                {
                    textAlign = TextComponent.TextAlign.MiddleCenter;
                }
                if (paragraphAlign == "right")
                {
                    textAlign = TextComponent.TextAlign.MiddleRight;
                }
            }

            if (xdObject.Text?.Frame?.Type == "area" || xdObject.Text?.Frame?.Type == "autoHeight")
            {
                wrap = true;
                if (paragraphAlign == "left")
                {
                    textAlign = TextComponent.TextAlign.UpperLeft;
                }
                if (paragraphAlign == "center")
                {
                    textAlign = TextComponent.TextAlign.UpperCenter;
                }
                if (paragraphAlign == "right")
                {
                    textAlign = TextComponent.TextAlign.UpperRight;
                }
            }

            var lineHeight = xdObject.Style?.TextAttributes?.LineHeight;

            components.Add(new TextComponent(rawText, fontSize, color, textAlign, font.PostscriptName, wrap, lineHeight));

            return(components.ToArray(), new IAsset[] { });
        }
示例#11
0
            public XdRenderer(XdArtboard xdArtboard, XdAssetHolder xdAssetHolder, IXdObjectParser[] objectParsers, IXdGroupParser[] groupParsers, AkyuiXdImportTrigger[] triggers)
            {
                var resources = xdArtboard.Resources;

                _xdAssetHolder = xdAssetHolder;
                _objectParsers = objectParsers;
                _groupParsers  = groupParsers;
                Elements       = new List <IElement>();
                Assets         = new List <IAsset>();
                _obbHolder     = new ObbHolder();

                CreateRefObjectMap(resources.Resources);

                var xdResourcesArtboardsJson = resources.Artboards[xdArtboard.Manifest.Path.Replace("artboard-", "")];
                var rootObb = new Obb {
                    Size = new Vector2(xdResourcesArtboardsJson.Width, xdResourcesArtboardsJson.Height)
                };

                var rootArtboard           = xdArtboard.Artboard.Children[0];
                var xdObjectJsons          = rootArtboard.Artboard.Children;
                var convertedXdObjectJsons = ConvertRefObject(xdObjectJsons, triggers);
                var childrenObbs           = CalcPosition(convertedXdObjectJsons, rootObb);

                foreach (var childObb in childrenObbs)
                {
                    childObb.LocalLeftTopPosition -= new Vector2(xdResourcesArtboardsJson.X, xdResourcesArtboardsJson.Y);
                }
                var children = Render(convertedXdObjectJsons, rootObb);

                var rootComponents = new List <IComponent>();

                if (rootArtboard.Style?.Fill != null && rootArtboard.Style.Fill.Type == "solid")
                {
                    var color = rootArtboard.GetFillUnityColor();
                    rootComponents.Add(new ImageComponent(null, color, Vector2Int.one));
                }

                var root = new ObjectElement(
                    0,
                    xdArtboard.Name,
                    Vector2.zero,
                    rootObb.Size,
                    AnchorXType.Center,
                    AnchorYType.Middle,
                    0f,
                    true,
                    rootComponents.ToArray(),
                    children.Select(x => x.Eid).ToArray()
                    );

                Elements.Add(root);
            }
示例#12
0
        public (IComponent[], IAsset[]) Render(XdObjectJson xdObject, XdAssetHolder assetHolder, IObbGetter obbGetter)
        {
            var obb      = obbGetter.Get(xdObject);
            var clipPath = xdObject.Meta.Ux.ClipPathResources.Children[0];

            if (SvgUtil.IsAlphaOnly(clipPath))
            {
                return(new IComponent[] { }, new IAsset[] { });
            }

            var(imageComponent, assets) = ShapeObjectParser.RenderImage(clipPath, obb, assetHolder);
            return(new IComponent[] { new MaskComponent(imageComponent.Sprite) }, assets);
        }
示例#13
0
        public static (ImageComponent, IAsset[]) RenderImage(XdObjectJson xdObject, Obb obb, XdAssetHolder assetHolder)
        {
            ImageComponent imageComponent = null;
            SpriteAsset    asset          = null;

            var color     = xdObject.GetFillUnityColor();
            var ux        = xdObject.Style?.Fill?.Pattern?.Meta?.Ux;
            var flipX     = ux?.FlipX ?? false;
            var flipY     = ux?.FlipY ?? false;
            var direction = new Vector2Int(flipX ? -1 : 1, flipY ? -1 : 1);
            var shapeType = xdObject.Shape?.Type;

            if (!string.IsNullOrWhiteSpace(ux?.Uid))
            {
                var spriteUid = $"{xdObject.GetSimpleName()}_{ux?.Uid.Substring(0, 8)}.png";
                asset          = new SpriteAsset(spriteUid, xdObject.Style.Fill.Pattern.Meta.Ux.HrefLastModifiedDate, obb.Size, null, null);
                imageComponent = new ImageComponent(
                    spriteUid,
                    color,
                    direction
                    );
                assetHolder.Save(spriteUid, xdObject.Style.Fill.Pattern.Meta);
            }
            else if (SvgUtil.Types.Contains(shapeType))
            {
                var spriteUid = $"{xdObject.GetSimpleName()}_{xdObject.Id.Substring(0, 8)}.png";
                var svg       = SvgUtil.CreateSvg(xdObject);
                var svgHash   = FastHash.CalculateHash(svg);

                var cachedSvg = assetHolder.GetCachedSvg(svgHash);
                if (cachedSvg != null)
                {
                    spriteUid = cachedSvg.SpriteUid;
                }
                else
                {
                    asset = new SpriteAsset(spriteUid, svgHash, obb.Size, null, null);
                    var xdImportSettings = XdImporter.Settings;
                    assetHolder.Save(spriteUid, () => SvgToPng.Convert(svg, obb.Size, xdImportSettings));
                    assetHolder.SaveCacheSvg(spriteUid, svgHash);
                }

                imageComponent = new ImageComponent(
                    spriteUid,
                    new Color(1f, 1f, 1f, color.a),
                    direction
                    );
            }
            else
            {
                Debug.LogError($"Unknown shape type {shapeType} in {xdObject.Name}({xdObject.Id}, {xdObject.Guid})");
            }

            var assets = new List <IAsset>();

            if (!xdObject.HasParameter("placeholder") && asset != null)
            {
                assets.Add(asset);
            }
            return(imageComponent, assets.ToArray());
        }
示例#14
0
 public (IComponent[], IAsset[]) Render(XdObjectJson xdObject, Obb obb, XdAssetHolder assetHolder)
 {
     var(imageComponent, assets) = RenderImage(xdObject, obb, assetHolder);
     return(new IComponent[] { imageComponent }, assets);
 }
示例#15
0
 public abstract (IComponent[], IAsset[]) Render(XdObjectJson xdObject, XdAssetHolder assetHolder, IObbGetter obbGetter);
示例#16
0
 public abstract (IComponent[], IAsset[]) Render(XdObjectJson xdObject, Obb obb, XdAssetHolder assetHolder);