Example #1
0
        public static void FlagStyleSheetChange()
        {
            // clear caches that depend on loaded style sheets
            StyleSheetCache.ClearCaches();

            // for now we don't bother tracking which panel depends on which style sheet
            var iterator = UIElementsUtility.GetPanelsIterator();

            while (iterator.MoveNext())
            {
                var panel = iterator.Current.Value;

                // In-game doesn't support styling
                if (panel.contextType != ContextType.Editor)
                {
                    continue;
                }

                panel.styleContext.DirtyStyleSheets();
                panel.visualTree.Dirty(ChangeType.Styles); // dirty all styles

                var guiView = panel.ownerObject as GUIView;
                if (guiView != null)
                {
                    guiView.Repaint();
                }
            }
        }
        public static StyleProperty AddProperty(
            this StyleSheet styleSheet, StyleRule rule, string name,
            string undoMessage = null)
        {
            // Undo/Redo
            if (string.IsNullOrEmpty(undoMessage))
            {
                undoMessage = "Change UI Style Value";
            }
            Undo.RegisterCompleteObjectUndo(styleSheet, undoMessage);

            var newProperty = new StyleProperty
            {
                name = name
            };

            // Create empty values array.
            newProperty.values = new StyleValueHandle[0];

            // Add property to selector's rule's properties.
            var properties = rule.properties.ToList();

            properties.Add(newProperty);
            rule.properties = properties.ToArray();

            StyleSheetCache.ClearCaches();

            return(newProperty);
        }
            private const string k_UssExtensionGenerated = ".uss.asset"; // for editor_resources project

            static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets,
                                               string[] movedFromAssetPaths)
            {
                // Early exit: no imported or deleted assets.
                var uxmlImportedAssets = new HashSet <string>(importedAssets.Where(x => MatchesFileExtension(x, k_UxmlExtension)));
                var uxmlDeletedAssets  = new HashSet <string>(deletedAssets.Where(x => MatchesFileExtension(x, k_UxmlExtension)));
                var ussImportedAssets  = new HashSet <string>(importedAssets.Where(x => MatchesFileExtension(x, k_UssExtension) || MatchesFileExtension(x, k_UssExtensionGenerated)));
                var ussDeletedAssets   = new HashSet <string>(deletedAssets.Where(x => MatchesFileExtension(x, k_UssExtension)));

                if (uxmlImportedAssets.Count == 0 && uxmlDeletedAssets.Count == 0 &&
                    ussImportedAssets.Count == 0 && ussDeletedAssets.Count == 0)
                {
                    return;
                }

                HashSet <VisualTreeAsset> uxmlModifiedAssets = null;

                if (uxmlImportedAssets.Count > 0)
                {
                    UXMLImporterImpl.logger.FinishImport();

                    // the inline stylesheet cache might get out of date.
                    // Usually called by the USS importer, which might not get called here
                    StyleSheetCache.ClearCaches();

                    uxmlModifiedAssets = new HashSet <VisualTreeAsset>();
                    foreach (var assetPath in uxmlImportedAssets)
                    {
                        VisualTreeAsset asset = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>(assetPath);
                        if (asset != null) // Shouldn't be!
                        {
                            uxmlModifiedAssets.Add(asset);
                        }
                    }
                }

                HashSet <StyleSheet> ussModifiedAssets = null;

                var iterator = UIElementsUtility.GetPanelsIterator();

                while (iterator.MoveNext())
                {
                    var panel = iterator.Current.Value;
                    panel.liveReloadSystem.OnVisualTreeAssetsImported(uxmlModifiedAssets, uxmlDeletedAssets);

                    // ussModifiedAssets is null but we don't care for those, only deleted ones (that we'll stop tracking).
                    panel.liveReloadSystem.OnStyleSheetAssetsImported(ussModifiedAssets, ussDeletedAssets);
                }

                if (ussImportedAssets.Count > 0 || ussDeletedAssets.Count > 0)
                {
                    FlagStyleSheetChange();
                }
            }
Example #4
0
        static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
        {
            bool anyUxmlImported = false;
            bool anyUssImported  = false;

            foreach (string assetPath in importedAssets)
            {
                if (assetPath.EndsWith("uss"))
                {
                    if (!anyUssImported)
                    {
                        anyUssImported = true;
                        FlagStyleSheetChange();
                    }
                }
                else if (assetPath.EndsWith("uxml"))
                {
                    if (!anyUxmlImported)
                    {
                        anyUxmlImported = true;
                        UIElementsViewImporter.logger.FinishImport();

                        // the inline stylesheet cache might get out of date.
                        // Usually called by the USS importer, which might not get called here
                        StyleSheetCache.ClearCaches();

                        if (UxmlLiveReloadIsEnabled && Unsupported.IsDeveloperMode())
                        {
                            // Delay the view reloading so we do not try to reload the view that
                            // is currently active in the current callstack (i.e. ProjectView).
                            EditorApplication.update += OneShotUxmlLiveReload;
                        }
                    }
                }

                // no need to continue, as we found both extensions we were looking for
                if (anyUxmlImported && anyUssImported)
                {
                    break;
                }
            }
        }
Example #5
0
 public static void FlagStyleSheetChange()
 {
     StyleSheetCache.ClearCaches();
     Dictionary <int, Panel> .Enumerator panelsIterator = UIElementsUtility.GetPanelsIterator();
     while (panelsIterator.MoveNext())
     {
         KeyValuePair <int, Panel> current = panelsIterator.Current;
         Panel value = current.Value;
         if (value.contextType == ContextType.Editor)
         {
             value.styleContext.DirtyStyleSheets();
             value.visualTree.Dirty(ChangeType.Styles);
             GUIView gUIView = EditorUtility.InstanceIDToObject(value.instanceID) as GUIView;
             if (gUIView != null)
             {
                 gUIView.Repaint();
             }
         }
     }
 }
        public static void FlagStyleSheetChange()
        {
            // clear caches that depend on loaded style sheets
            StyleSheetCache.ClearCaches();

            // for now we don't bother tracking which panel depends on which style sheet
            var iterator = UIElementsUtility.GetPanelsIterator();

            while (iterator.MoveNext())
            {
                var panel = iterator.Current.Value;

                panel.DirtyStyleSheets();

                var guiView = panel.ownerObject as GUIView;
                if (guiView != null)
                {
                    guiView.Repaint();
                }
            }
        }
Example #7
0
        private static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
        {
            bool flag  = false;
            bool flag2 = false;

            for (int i = 0; i < importedAssets.Length; i++)
            {
                string text = importedAssets[i];
                if (text.EndsWith("uss"))
                {
                    if (!flag2)
                    {
                        flag2 = true;
                        RetainedMode.FlagStyleSheetChange();
                    }
                }
                else if (text.EndsWith("uxml"))
                {
                    if (!flag)
                    {
                        flag = true;
                        UIElementsViewImporter.logger.FinishImport();
                        StyleSheetCache.ClearCaches();
                        if (RetainedMode.UxmlLiveReloadIsEnabled)
                        {
                            Delegate arg_92_0 = EditorApplication.update;
                            if (RetainedMode.< > f__mg$cache2 == null)
                            {
                                RetainedMode.< > f__mg$cache2 = new EditorApplication.CallbackFunction(RetainedMode.OneShotUxmlLiveReload);
                            }
                            EditorApplication.update = (EditorApplication.CallbackFunction)Delegate.Combine(arg_92_0, RetainedMode.< > f__mg$cache2);
                        }
                    }
                }
                if (flag && flag2)
                {
                    break;
                }
            }
        }