using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using UnityEngine; using UnityEngine.UIElements; using UnityEditor.Graphing; using UnityEditor.Experimental.GraphView; using UnityEditor.ShaderGraph.Drawing.Controls; using UnityEditor.ShaderGraph.Drawing.Inspector.PropertyDrawers; using UnityEditor.ShaderGraph.Internal; using UnityEngine.Assertions; using ContextualMenuManipulator = UnityEngine.UIElements.ContextualMenuManipulator; using GraphDataStore = UnityEditor.ShaderGraph.DataStore; namespace UnityEditor.ShaderGraph.Drawing { class SGBlackboardField : GraphElement, IInspectable, ISGControlledElement { static readonly Texture2D k_ExposedIcon = Resources.Load("GraphView/Nodes/BlackboardFieldExposed"); static readonly string k_UxmlTemplatePath = "UXML/Blackboard/SGBlackboardField"; static readonly string k_StyleSheetPath = "Styles/SGBlackboard"; ShaderInputViewModel m_ViewModel; ShaderInputViewModel ViewModel { get => m_ViewModel; set => m_ViewModel = value; } VisualElement m_ContentItem; Pill m_Pill; Label m_TypeLabel; TextField m_TextField; internal TextField textField => m_TextField; Action m_ResetReferenceNameTrigger; List m_SelectedNodes = new List(); public string text { get { return m_Pill.text; } set { m_Pill.text = value; } } public string typeText { get { return m_TypeLabel.text; } set { m_TypeLabel.text = value; } } public Texture icon { get { return m_Pill.icon; } set { m_Pill.icon = value; } } public bool highlighted { get { return m_Pill.highlighted; } set { m_Pill.highlighted = value; } } internal SGBlackboardField(ShaderInputViewModel viewModel) { ViewModel = viewModel; // Store ShaderInput in userData object userData = ViewModel.model; if (userData == null) { AssertHelpers.Fail("Could not initialize blackboard field as shader input was null."); return; } // Store the Model guid as viewDataKey as that is persistent viewDataKey = ViewModel.model.guid.ToString(); var visualTreeAsset = Resources.Load(k_UxmlTemplatePath); Assert.IsNotNull(visualTreeAsset); VisualElement mainContainer = visualTreeAsset.Instantiate(); var styleSheet = Resources.Load(k_StyleSheetPath); Assert.IsNotNull(styleSheet); styleSheets.Add(styleSheet); mainContainer.AddToClassList("mainContainer"); mainContainer.pickingMode = PickingMode.Ignore; m_ContentItem = mainContainer.Q("contentItem"); m_Pill = mainContainer.Q("pill"); m_TypeLabel = mainContainer.Q