Ejemplo n.º 1
0
        internal static List<StyleSheet> GetAllReferencedStyleSheets(this VisualTreeAsset vta)
        {
            var sheets = new HashSet<StyleSheet>();

            foreach (var vea in vta.visualElementAssets)
                if (vta.IsRootElement(vea) || vta.IsRootUXMLElement(vea))
                    GetAllReferencedStyleSheets(vea, sheets);

            foreach (var vea in vta.templateAssets)
                if (vta.IsRootElement(vea))
                    GetAllReferencedStyleSheets(vea, sheets);

            return sheets.ToList();
        }
Ejemplo n.º 2
0
        static void ReinitElementWithNewParentAsset(
            VisualTreeAsset vta, VisualElementAsset parent, VisualTreeAsset other,
            Dictionary <int, List <VisualElementAsset> > otherIdToChildren,
            VisualElementAsset vea, ref int nextOrderInDocument)
        {
            SwallowStyleRule(vta, other, vea);

            // Set new parent id on root elements.
            if (other.IsRootElement(vea) && parent != null)
            {
                vea.parentId = parent.id;
            }

            // Set order in document.
            vea.orderInDocument  = nextOrderInDocument;
            nextOrderInDocument += BuilderConstants.VisualTreeAssetOrderIncrement;

            // Create new id and update parentId in children.
            var oldId = vea.id;

            vea.id = VisualTreeAssetUtilities.GenerateNewId(vta, vea);
            List <VisualElementAsset> children;

            if (otherIdToChildren.TryGetValue(oldId, out children) && children != null)
            {
                foreach (var child in children)
                {
                    child.parentId = vea.id;
                }
            }
        }
        public static VisualElementAsset ReparentElementInDocument(
            VisualTreeAsset vta, VisualElementAsset vea,
            VisualElementAsset newParent, int index = -1)
        {
            var idToChildren = GenerateIdToChildren(vta);

            // HACK: We clear ALL stylesheets here if element is no longer at root.
            // this is fine as long as we only support one uss but when we support more
            // we need to make sure we only remove the stylesheets that make sense to remove.
            // See: https://unity3d.atlassian.net/browse/UIT-469
            if (vta.IsRootElement(vea) && newParent != null)
            {
#if UNITY_2019_3_OR_NEWER
                vea.stylesheetPaths.Clear();
                vea.stylesheets.Clear();
#else
                vea.stylesheets.Clear();
#endif
            }

            SetInitElementWithParent(vta, vea, newParent, idToChildren, index);

            // Fix document ordering.
            ReOrderDocument(vta);

            return(vea);
        }