using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using UnityEditor.Experimental.GraphView; using UnityEditor.ShaderGraph.Drawing.Inspector.PropertyDrawers; using UnityEditor.ShaderGraph.Drawing.Views; using UnityEngine; using UnityEngine.UIElements; namespace UnityEditor.ShaderGraph.Drawing.Inspector { class InspectorView : GraphSubWindow { const float k_InspectorUpdateInterval = 0.25f; const int k_InspectorElementLimit = 20; bool m_GraphSettingsTabFocused = false; int m_CurrentlyInspectedElementsCount = 0; readonly List m_PropertyDrawerList = new List(); HashSet cachedInspectables = new(); // There's persistent data that is stored in the graph settings property drawer that we need to hold onto between interactions IPropertyDrawer m_graphSettingsPropertyDrawer = new GraphDataPropertyDrawer(); public override string windowTitle => "Graph Inspector"; public override string elementName => "InspectorView"; public override string styleName => "InspectorView"; public override string UxmlName => "GraphInspector"; public override string layoutKey => "UnityEditor.ShaderGraph.InspectorWindow"; TabbedView m_GraphInspectorView; TabbedView m_NodeSettingsTab; protected VisualElement m_GraphSettingsContainer; protected VisualElement m_NodeSettingsContainer; Label m_MaxItemsMessageLabel; void RegisterPropertyDrawer(Type newPropertyDrawerType) { if (typeof(IPropertyDrawer).IsAssignableFrom(newPropertyDrawerType) == false) { Debug.Log("Attempted to register a property drawer that doesn't inherit from IPropertyDrawer!"); return; } var newPropertyDrawerAttribute = newPropertyDrawerType.GetCustomAttribute(); if (newPropertyDrawerAttribute != null) { foreach (var existingPropertyDrawerType in m_PropertyDrawerList) { var existingPropertyDrawerAttribute = existingPropertyDrawerType.GetCustomAttribute(); if (newPropertyDrawerAttribute.propertyType.IsSubclassOf(existingPropertyDrawerAttribute.propertyType)) { // Derived types need to be at start of list m_PropertyDrawerList.Insert(0, newPropertyDrawerType); return; } if (existingPropertyDrawerAttribute.propertyType.IsSubclassOf(newPropertyDrawerAttribute.propertyType)) { // Add new base class type to end of list m_PropertyDrawerList.Add(newPropertyDrawerType); // Shift already added existing type to the beginning of the list m_PropertyDrawerList.Remove(existingPropertyDrawerType); m_PropertyDrawerList.Insert(0, existingPropertyDrawerType); return; } } m_PropertyDrawerList.Add(newPropertyDrawerType); } else Debug.Log("Attempted to register property drawer: " + newPropertyDrawerType + " that isn't marked up with the SGPropertyDrawer attribute!"); } public InspectorView(InspectorViewModel viewModel) : base(viewModel) { m_GraphInspectorView = m_MainContainer.Q("GraphInspectorView"); m_GraphSettingsContainer = m_GraphInspectorView.Q("GraphSettingsContainer"); m_NodeSettingsContainer = m_GraphInspectorView.Q("NodeSettingsContainer"); m_MaxItemsMessageLabel = m_GraphInspectorView.Q