using System; using System.Linq; using UnityEditor.Experimental.GraphView; using UnityEditor.Graphing; using UnityEditor.Rendering; using UnityEditor.ShaderGraph.Drawing; using UnityEditor.ShaderGraph.Drawing.Controls; using UnityEditor.ShaderGraph.Internal; using UnityEngine; using UnityEngine.UIElements; using UnityEditor.ShaderGraph.Drawing.Inspector.PropertyDrawers; using ContextualMenuManipulator = UnityEngine.UIElements.ContextualMenuManipulator; namespace UnityEditor.ShaderGraph { sealed class PropertyNodeView : TokenNode, IShaderNodeView, IInspectable, IShaderInputObserver { static readonly Texture2D exposedIcon = Resources.Load("GraphView/Nodes/BlackboardFieldExposed"); public static StyleSheet styleSheet; // When the properties are changed, this delegate is used to trigger an update in the view that represents those properties Action m_TriggerInspectorUpdate; Action m_ResetReferenceNameAction; public PropertyNodeView(PropertyNode node, EdgeConnectorListener edgeConnectorListener) : base(null, ShaderPort.Create(node.GetOutputSlots().First(), edgeConnectorListener)) { if (styleSheet == null) styleSheet = Resources.Load("Styles/PropertyNodeView"); styleSheets.Add(styleSheet); this.node = node; viewDataKey = node.objectId.ToString(); userData = node; // Getting the generatePropertyBlock property to see if it is exposed or not UpdateIcon(); // Setting the position of the node, otherwise it ends up in the center of the canvas SetPosition(new Rect(node.drawState.position.x, node.drawState.position.y, 0, 0)); // Removing the title label since it is not used and taking up space this.Q("title-label").RemoveFromHierarchy(); // Add disabled overlay Add(new VisualElement() { name = "disabledOverlay", pickingMode = PickingMode.Ignore }); // Update active state SetActive(node.isActive); // Registering the hovering callbacks for highlighting RegisterCallback(OnMouseHover); RegisterCallback(OnMouseHover); // add the right click context menu IManipulator contextMenuManipulator = new ContextualMenuManipulator(AddContextMenuOptions); this.AddManipulator(contextMenuManipulator); if (property != null) { property.onAfterVersionChange += () => { m_TriggerInspectorUpdate?.Invoke(); }; } } // Updating the text label of the output slot void UpdateDisplayName() { var slot = node.GetSlots().ToList().First(); this.Q