private static float GetSpacerSize(XdObjectJson xdObject, IObbGetter obbGetter) { var spacerSize = 0f; var spacer = xdObject.Group?.Children?.FirstOrDefault(x => x.NameEndsWith("spacer")); if (spacer != null) { spacerSize = Mathf.Max(obbGetter.Get(spacer).Size.y, 0f); xdObject.Group.Children = xdObject.Group.Children.Where(x => x != spacer).ToArray(); } return(spacerSize); }
private static XdObjectJson[] ExpandMultiItemsList(XdObjectJson listItemRoot, string scrollingType, IObbGetter obbGetter, ref List <SpecialSpacing> specialSpacings) { var listItems = new List <XdObjectJson>(); // 孫を解析して、それもRepeatGridなら更に子供 var tmp = listItemRoot.Group.Children.ToList(); var size = new List <(string Name, Obb Obb)>(); foreach (var listItem in tmp) { if (RepeatGridGroupParser.Is(listItem, scrollingType)) { var listListItem = listItem.Group.Children[0].Group.Children[0]; // 登録 specialSpacings.Add(new SpecialSpacing(listListItem.Name, listListItem.Name, listItem.GetRepeatGridSpacing(scrollingType))); listItems.Add(listListItem); // 名前は参照されるので子供の名前を使うが、サイズは親のものとして計算する。 // XDのデザイン上は親のサイズなので。 size.Add((listListItem.Name, obbGetter.Get(listItem))); } else { listItems.Add(listItem); size.Add((listItem.Name, obbGetter.Get(listItem))); } } var rootObb = obbGetter.Get(listItemRoot); var cache = size.ToDictionary(x => x.Obb, x => x.Obb.CalcObbInWorld(rootObb).CalcLocalRect()); var orderedSize = size.OrderBy(x => cache[x.Obb].yMin).ToArray(); foreach (var((name1, obb1), (name2, obb2)) in orderedSize.Zip(orderedSize.Skip(1), (x, y) => (x, y))) { specialSpacings.Add(new SpecialSpacing(name1, name2, cache[obb1].yMax - cache[obb2].yMin)); } return(listItems.ToArray()); }
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[] { }); } }
public (IComponent[], IAsset[]) Render(XdObjectJson xdObject, XdAssetHolder assetHolder, IObbGetter obbGetter) { return(new IComponent[] { new InputFieldComponent() }, new IAsset[] { }); }
private static (XdObjectJson[], float Spacing) ExpandRepeatGridGroup(XdObjectJson xdObject, XdObjectJson repeatGrid, string scrollingType, IObbGetter obbGetter, ref List <SpecialSpacing> specialSpacings) { var spacing = repeatGrid.GetRepeatGridSpacing(scrollingType); var listElement = repeatGrid.Group.Children[0].Group.Children[0]; var listItems = new[] { listElement }; if (xdObject.HasParameter("multiitems")) { listItems = ExpandMultiItemsList(listElement, scrollingType, obbGetter, ref specialSpacings); } foreach (var listItem in listItems) { listItem.RemoveConstraint(); } return(listItems.ToArray(), spacing); }
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); }
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[] { }); }
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[] { }); } }
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()); }
private static (XdObjectJson[], float Spacing) ExpandRepeatGridGroup(XdObjectJson xdObject, XdObjectJson repeatGrid, string scrollingType, IObbGetter obbGetter, ref List <SpecialSpacing> specialSpacings) { var listElement = repeatGrid.Group.Children[0].Group.Children[0]; var listItems = new[] { listElement }; var childSize = obbGetter.Get(listElement).Size; float spacing; if (scrollingType == "vertical") { spacing = (repeatGrid.Meta?.Ux?.RepeatGrid?.PaddingY ?? 0f) + (repeatGrid.Meta?.Ux?.RepeatGrid?.CellHeight ?? 0f) - childSize.y; } else { spacing = (repeatGrid.Meta?.Ux?.RepeatGrid?.PaddingX ?? 0f) + (repeatGrid.Meta?.Ux?.RepeatGrid?.CellWidth ?? 0f) - childSize.x; } if (xdObject.HasParameter("multiitems")) { listItems = ExpandMultiItemsList(listElement, scrollingType, obbGetter, ref specialSpacings); } foreach (var listItem in listItems) { listItem.RemoveConstraint(); } return(listItems.ToArray(), spacing); }
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(); }
public abstract (IComponent[], IAsset[]) Render(XdObjectJson xdObject, XdAssetHolder assetHolder, IObbGetter obbGetter);