public void AddNotifier(IBuilderSelectionNotifier notifier)
 {
     if (!m_Notifiers.Contains(notifier))
     {
         m_Notifiers.Add(notifier);
     }
 }
        public void NotifyOfHierarchyChange(
            IBuilderSelectionNotifier source      = null,
            VisualElement element                 = null,
            BuilderHierarchyChangeType changeType = BuilderHierarchyChangeType.All)
        {
            if (m_Notifiers == null || m_Notifiers.Count == 0)
            {
                return;
            }

            VisualElementAsset vea = element?.GetVisualElementAsset();

            if (vea != null && vea.ruleIndex >= 0 && changeType.HasFlag(BuilderHierarchyChangeType.InlineStyle))
            {
                var vta  = m_PaneWindow.document.visualTreeAsset;
                var rule = vta.GetOrCreateInlineStyleRule(vea);

#if UNITY_2020_1_OR_NEWER
                element.SetInlineRule(vta.inlineSheet, rule);

                // Need to enforce this specific style is updated.
                element.IncrementVersion(VersionChangeType.Opacity | VersionChangeType.Overflow);
#elif UNITY_2019_3_OR_NEWER
                var stylesData = new UnityEngine.UIElements.StyleSheets.VisualElementStylesData(false);
                element.m_Style = stylesData;

                s_StylePropertyReader.SetInlineContext(vta.inlineSheet, rule, vea.ruleIndex);
                stylesData.ApplyProperties(s_StylePropertyReader, null);

                // Need to enforce this specific style is updated.
                element.IncrementVersion(VersionChangeType.Opacity | VersionChangeType.Overflow);
#else
                var stylesData = new UnityEngine.UIElements.StyleSheets.VisualElementStylesData(false);
                element.m_Style = stylesData;

                var propIds = UnityEngine.UIElements.StyleSheets.StyleSheetCache.GetPropertyIDs(vta.inlineSheet, vea.ruleIndex);
                element.specifiedStyle.ApplyRule(vta.inlineSheet, Int32.MaxValue, rule, propIds);

                // Need to enforce this specific style is updated.
                element.IncrementVersion(VersionChangeType.Overflow);
#endif
            }

            if (m_DocumentElement != null)
            {
                m_PaneWindow.document.RefreshStyle(m_DocumentElement);
            }

            // This is so anyone interested can refresh their use of this UXML with
            // the latest (unsaved to disk) changes.
            EditorUtility.SetDirty(m_PaneWindow.document.visualTreeAsset);

            foreach (var notifier in m_Notifiers)
            {
                if (notifier != source)
                {
                    notifier.HierarchyChanged(element, changeType);
                }
            }
        }
        public void RemoveFromSelection(IBuilderSelectionNotifier source, VisualElement ve)
        {
            m_Selection.Remove(ve);
            BuilderAssetUtilities.RemoveElementFromSelectionInAsset(m_PaneWindow.document, ve);

            NotifyOfSelectionChange(source);
        }
        public void NotifyOfStylingChange(IBuilderSelectionNotifier source = null, List <string> styles = null)
        {
            if (m_Notifiers == null || m_Notifiers.Count == 0)
            {
                return;
            }

            if (m_DocumentElement != null)
            {
                m_PaneWindow.document.RefreshStyle(m_DocumentElement);
            }

            m_CurrentNotifier  = source;
            m_CurrentStyleList = styles;
            QueueUpPostPanelUpdaterChangeAction(NotifyOfStylingChangePostStylingUpdate);
        }
        public void AddToSelection(IBuilderSelectionNotifier source, VisualElement ve, bool undo = true)
        {
            if (ve == null)
            {
                return;
            }

            m_Selection.Add(ve);

            if (undo)
            {
                BuilderAssetUtilities.AddElementToSelectionInAsset(m_PaneWindow.document, ve);
            }

            NotifyOfSelectionChange(source);
        }
        public void NotifyOfStylingChangePostStylingUpdate()
        {
            // This is so anyone interested can refresh their use of this USS with
            // the latest (unsaved to disk) changes.
            //RetainedMode.FlagStyleSheetChange(); // Works but TOO SLOW.
            EditorUtility.SetDirty(m_PaneWindow.document.mainStyleSheet);

            foreach (var notifier in m_Notifiers)
            {
                if (notifier != m_CurrentNotifier)
                {
                    notifier.StylingChanged(m_CurrentStyleList);
                }
            }

            m_CurrentNotifier  = null;
            m_CurrentStyleList = null;
        }
        public void ClearSelection(IBuilderSelectionNotifier source, bool undo = true)
        {
            if (isEmpty)
            {
                return;
            }

            if (undo)
            {
                foreach (var sel in m_Selection)
                {
                    BuilderAssetUtilities.RemoveElementFromSelectionInAsset(m_PaneWindow.document, sel);
                }
            }

            m_Selection.Clear();

            NotifyOfSelectionChange(source);
        }
Exemple #8
0
        public void NotifyOfStylingChangePostStylingUpdate()
        {
            // This is so anyone interested can refresh their use of this USS with
            // the latest (unsaved to disk) changes.
            //RetainedMode.FlagStyleSheetChange(); // Works but TOO SLOW.
            m_PaneWindow.document.MarkStyleSheetsDirty();
            m_LiveReloadTriggerMethod?.Invoke(null, null);

            foreach (var notifier in m_Notifiers)
            {
                if (notifier != m_CurrentNotifier)
                {
                    notifier.StylingChanged(m_CurrentStyleList, m_CurrentChangeType);
                }
            }

            m_CurrentNotifier  = null;
            m_CurrentStyleList = null;
        }
        void NotifyOfSelectionChange(IBuilderSelectionNotifier source)
        {
            if (m_Notifiers == null || m_Notifiers.Count == 0)
            {
                return;
            }

            if (m_DocumentElement != null)
            {
                m_PaneWindow.document.RefreshStyle(m_DocumentElement);
            }

            foreach (var notifier in m_Notifiers)
            {
                if (notifier != source)
                {
                    notifier.SelectionChanged();
                }
            }
        }
        public void NotifyOfHierarchyChange(
            IBuilderSelectionNotifier source      = null,
            VisualElement element                 = null,
            BuilderHierarchyChangeType changeType = BuilderHierarchyChangeType.All)
        {
            if (m_Notifiers == null || m_Notifiers.Count == 0)
            {
                return;
            }

            VisualElementAsset vea = element?.GetVisualElementAsset();

            if (vea != null && vea.ruleIndex >= 0 && changeType.HasFlag(BuilderHierarchyChangeType.InlineStyle))
            {
                var vta  = m_PaneWindow.document.visualTreeAsset;
                var rule = vta.GetOrCreateInlineStyleRule(vea);

                element.UpdateInlineRule(vta.inlineSheet, rule);

                // Need to enforce this specific style is updated.
                element.IncrementVersion(VersionChangeType.Opacity | VersionChangeType.Overflow);
            }

            if (m_DocumentRootElement != null)
            {
                m_PaneWindow.document.RefreshStyle(m_DocumentRootElement);
            }

            // This is so anyone interested can refresh their use of this UXML with
            // the latest (unsaved to disk) changes.
            EditorUtility.SetDirty(m_PaneWindow.document.visualTreeAsset);
            m_LiveReloadTriggerMethod?.Invoke(null, null);

            foreach (var notifier in m_Notifiers)
            {
                if (notifier != source)
                {
                    notifier.HierarchyChanged(element, changeType);
                }
            }
        }
        public void Select(IBuilderSelectionNotifier source, VisualElement ve)
        {
            if (ve == null)
            {
                return;
            }

            foreach (var sel in m_Selection)
            {
                if (sel == null)
                {
                    continue;
                }

                BuilderAssetUtilities.RemoveElementFromSelectionInAsset(m_PaneWindow.document, sel);
            }

            m_Selection.Clear();

            m_Selection.Add(ve);
            BuilderAssetUtilities.AddElementToSelectionInAsset(m_PaneWindow.document, ve);

            NotifyOfSelectionChange(source);
        }
        public void UpdateActiveStyleSheet(BuilderSelection selection, StyleSheet styleSheet, IBuilderSelectionNotifier source)
        {
            if (m_ActiveStyleSheet == styleSheet)
            {
                return;
            }

            m_ActiveStyleSheet = styleSheet;
            selection.ForceReselection(source);
        }
 public void RemoveNotifier(IBuilderSelectionNotifier notifier)
 {
     m_Notifiers.Remove(notifier);
 }
Exemple #14
0
 public void AddToSelection(IBuilderSelectionNotifier source, VisualElement ve)
 {
     AddToSelection(source, ve, true, true);
 }
Exemple #15
0
 public void ForceReselection(IBuilderSelectionNotifier source = null)
 {
     NotifyOfSelectionChange(source);
 }