Esempio n. 1
0
        void AddStyleSheetToRootAsset(VisualElementAsset rootAsset, string newUssPath = null)
        {
            if (rootAsset.fullTypeName == BuilderConstants.SelectedVisualTreeAssetSpecialElementTypeName)
            {
                return;
            }

            var localUssPath = ussPath;

            if (!string.IsNullOrEmpty(newUssPath))
            {
                localUssPath = newUssPath;
            }

            if (string.IsNullOrEmpty(localUssPath))
            {
#if UNITY_2019_3_OR_NEWER
                rootAsset.AddStyleSheet(mainStyleSheet);
#endif
                rootAsset.AddStyleSheetPath(
                    BuilderConstants.VisualTreeAssetStyleSheetPathAsInstanceIdSchemeName +
                    mainStyleSheet.GetInstanceID().ToString());
            }
            else
            {
#if UNITY_2019_3_OR_NEWER
                rootAsset.AddStyleSheet(mainStyleSheet);
#endif
                rootAsset.AddStyleSheetPath(localUssPath);
            }
        }
        void AddStyleSheetsToRootAsset(VisualElementAsset rootAsset, string newUssPath = null, int newUssIndex = 0)
        {
            if (rootAsset.fullTypeName == BuilderConstants.SelectedVisualTreeAssetSpecialElementTypeName)
            {
                return;
            }

            rootAsset.ClearStyleSheets();

            for (int i = 0; i < m_OpenUSSFiles.Count; ++i)
            {
                var localUssPath = m_OpenUSSFiles[i].assetPath;

                if (!string.IsNullOrEmpty(newUssPath) && i == newUssIndex)
                {
                    localUssPath = newUssPath;
                }

                if (string.IsNullOrEmpty(localUssPath))
                {
                    continue;
                }

                rootAsset.AddStyleSheet(m_OpenUSSFiles[i].styleSheet);
                rootAsset.AddStyleSheetPath(localUssPath);
            }
        }
        public static void AddStyleSheetsFromTreeAsset(VisualElementAsset visualElementAsset, VisualTreeAsset visualTreeAsset)
        {
            foreach (var styleSheet in visualTreeAsset.stylesheets)
            {
                var styleSheetPath = AssetDatabase.GetAssetPath(styleSheet);

                visualElementAsset.AddStyleSheet(styleSheet);
                visualElementAsset.AddStyleSheetPath(styleSheetPath);
            }
        }