VisualElement MakeItem()
        {
            var element = new BuilderExplorerItem();

            element.name = "unity-treeview-item-content";
            element.RegisterCallback <MouseEnterEvent>((e) =>
            {
                ClearHighlightOverlay();

                var explorerItem    = e.target as VisualElement;
                var documentElement = explorerItem?.GetProperty(BuilderConstants.ElementLinkedDocumentVisualElementVEPropertyName) as VisualElement;
                HighlightAllRelatedDocumentElements(documentElement);
            });
            element.RegisterCallback <MouseLeaveEvent>((e) =>
            {
                ClearHighlightOverlay();
            });

            element.RegisterCustomBuilderStyleChangeEvent(elementStyle =>
            {
                var documentElement = element.GetProperty(BuilderConstants.ElementLinkedDocumentVisualElementVEPropertyName) as VisualElement;
                var isValidTarget   = documentElement != null;
                if (!isValidTarget)
                {
                    return;
                }

                var icon = element.Q(null, BuilderConstants.ExplorerItemIconClassName);
                if (icon == null)
                {
                    return;
                }

                var path        = documentElement.GetProperty(BuilderConstants.LibraryItemLinkedTemplateContainerPathVEPropertyName) as string;
                var libraryIcon = BuilderLibraryContent.GetTypeLibraryIcon(documentElement.GetType());
                if (documentElement is TemplateContainer && !string.IsNullOrEmpty(path))
                {
                    libraryIcon = BuilderLibraryContent.GetUXMLAssetIcon(path);
                }
                else if (elementStyle == BuilderElementStyle.Highlighted && !EditorGUIUtility.isProSkin)
                {
                    libraryIcon = BuilderLibraryContent.GetTypeDarkSkinLibraryIcon(documentElement.GetType());
                }

                var styleBackgroundImage   = icon.style.backgroundImage;
                styleBackgroundImage.value = new Background {
                    texture = libraryIcon
                };
                icon.style.backgroundImage = styleBackgroundImage;
            });

            return(element);
        }
Exemple #2
0
        VisualElement MakeItem()
        {
            var element = new BuilderExplorerItem();

            element.name = "unity-treeview-item-content";
            element.RegisterCallback <MouseEnterEvent>((e) =>
            {
                ClearHighlightOverlay();

                var explorerItem    = e.target as VisualElement;
                var documentElement = explorerItem?.GetProperty(BuilderConstants.ElementLinkedDocumentVisualElementVEPropertyName) as VisualElement;
                HighlightAllRelatedDocumentElements(documentElement);
            });
            element.RegisterCallback <MouseLeaveEvent>((e) =>
            {
                ResetHighlightOverlays();
            });

            return(element);
        }