示例#1
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);
            }