public void GenerateNodeEntries() { Profiler.BeginSample("SearchWindowProvider.GenerateNodeEntries"); // First build up temporary data structure containing group & title as an array of strings (the last one is the actual title) and associated node type. List <NodeEntry> nodeEntries = new List <NodeEntry>(); if (target is ContextView contextView) { // Iterate all BlockFieldDescriptors currently cached on GraphData foreach (var field in m_Graph.blockFieldDescriptors) { if (field.isHidden) { continue; } // Test stage if (field.shaderStage != contextView.contextData.shaderStage) { continue; } // Create title List <string> title = ListPool <string> .Get(); if (!string.IsNullOrEmpty(field.path)) { var path = field.path.Split('/').ToList(); title.AddRange(path); } title.Add(field.displayName); // Create and initialize BlockNode instance then add entry var node = (BlockNode)Activator.CreateInstance(typeof(BlockNode)); node.Init(field); AddEntries(node, title.ToArray(), nodeEntries); } SortEntries(nodeEntries); currentNodeEntries = nodeEntries; return; } foreach (var type in NodeClassCache.knownNodeTypes) { if ((!type.IsClass || type.IsAbstract) || type == typeof(PropertyNode) || type == typeof(KeywordNode) || type == typeof(SubGraphNode)) { continue; } TitleAttribute titleAttribute = NodeClassCache.GetAttributeOnNodeType <TitleAttribute>(type); if (titleAttribute != null) { var node = (AbstractMaterialNode)Activator.CreateInstance(type); if (ShaderGraphPreferences.allowDeprecatedBehaviors && node.latestVersion > 0) { var versions = node.allowedNodeVersions ?? Enumerable.Range(0, node.latestVersion + 1); bool multiple = (versions.Count() > 1); foreach (int i in versions) { var depNode = (AbstractMaterialNode)Activator.CreateInstance(type); depNode.ChangeVersion(i); if (multiple) { AddEntries(depNode, titleAttribute.title.Append($"V{i}").ToArray(), nodeEntries); } else { AddEntries(depNode, titleAttribute.title, nodeEntries); } } } else { AddEntries(node, titleAttribute.title, nodeEntries); } } } foreach (var guid in AssetDatabase.FindAssets(string.Format("t:{0}", typeof(SubGraphAsset)))) { var asset = AssetDatabase.LoadAssetAtPath <SubGraphAsset>(AssetDatabase.GUIDToAssetPath(guid)); var node = new SubGraphNode { asset = asset }; var title = asset.path.Split('/').ToList(); if (asset.descendents.Contains(m_Graph.assetGuid) || asset.assetGuid == m_Graph.assetGuid) { continue; } if (string.IsNullOrEmpty(asset.path)) { AddEntries(node, new string[1] { asset.name }, nodeEntries); } else if (title[0] != k_HiddenFolderName) { title.Add(asset.name); AddEntries(node, title.ToArray(), nodeEntries); } } foreach (var property in m_Graph.properties) { if (property is Serialization.MultiJsonInternal.UnknownShaderPropertyType) { continue; } var node = new PropertyNode(); node.property = property; AddEntries(node, new[] { "Properties", "Property: " + property.displayName }, nodeEntries); } foreach (var keyword in m_Graph.keywords) { var node = new KeywordNode(); node.keyword = keyword; AddEntries(node, new[] { "Keywords", "Keyword: " + keyword.displayName }, nodeEntries); } SortEntries(nodeEntries); currentNodeEntries = nodeEntries; Profiler.EndSample(); }
public void GenerateNodeEntries() { Profiler.BeginSample("SearchWindowProvider.GenerateNodeEntries"); // First build up temporary data structure containing group & title as an array of strings (the last one is the actual title) and associated node type. List <NodeEntry> nodeEntries = new List <NodeEntry>(); bool hideCustomInterpolators = m_Graph.activeTargets.All(at => at.ignoreCustomInterpolators); if (target is ContextView contextView) { // Iterate all BlockFieldDescriptors currently cached on GraphData foreach (var field in m_Graph.blockFieldDescriptors) { if (field.isHidden) { continue; } // Test stage if (field.shaderStage != contextView.contextData.shaderStage) { continue; } // Create title List <string> title = ListPool <string> .Get(); if (!string.IsNullOrEmpty(field.path)) { var path = field.path.Split('/').ToList(); title.AddRange(path); } title.Add(field.displayName); // Create and initialize BlockNode instance then add entry var node = (BlockNode)Activator.CreateInstance(typeof(BlockNode)); node.Init(field); AddEntries(node, title.ToArray(), nodeEntries); } SortEntries(nodeEntries); if (contextView.contextData.shaderStage == ShaderStage.Vertex && !hideCustomInterpolators) { var customBlockNodeStub = (BlockNode)Activator.CreateInstance(typeof(BlockNode)); customBlockNodeStub.InitCustomDefault(); AddEntries(customBlockNodeStub, new string[] { "Custom Interpolator" }, nodeEntries); } currentNodeEntries = nodeEntries; return; } Profiler.BeginSample("SearchWindowProvider.GenerateNodeEntries.IterateKnowNodes"); foreach (var type in NodeClassCache.knownNodeTypes) { if ((!type.IsClass || type.IsAbstract) || type == typeof(PropertyNode) || type == typeof(KeywordNode) || type == typeof(DropdownNode) || type == typeof(SubGraphNode)) { continue; } TitleAttribute titleAttribute = NodeClassCache.GetAttributeOnNodeType <TitleAttribute>(type); if (titleAttribute != null) { var node = (AbstractMaterialNode)Activator.CreateInstance(type); if (!node.ExposeToSearcher) { continue; } if (ShaderGraphPreferences.allowDeprecatedBehaviors && node.latestVersion > 0) { var versions = node.allowedNodeVersions ?? Enumerable.Range(0, node.latestVersion + 1); bool multiple = (versions.Count() > 1); foreach (int i in versions) { var depNode = (AbstractMaterialNode)Activator.CreateInstance(type); depNode.ChangeVersion(i); if (multiple) { AddEntries(depNode, titleAttribute.title.Append($"v{i}").ToArray(), nodeEntries); } else { AddEntries(depNode, titleAttribute.title, nodeEntries); } } } else { AddEntries(node, titleAttribute.title, nodeEntries); } } } Profiler.EndSample(); Profiler.BeginSample("SearchWindowProvider.GenerateNodeEntries.IterateSubgraphAssets"); foreach (var asset in NodeClassCache.knownSubGraphAssets) { if (asset == null) { continue; } var node = new SubGraphNode { asset = asset }; var title = asset.path.Split('/').ToList(); if (asset.descendents.Contains(m_Graph.assetGuid) || asset.assetGuid == m_Graph.assetGuid) { continue; } if (string.IsNullOrEmpty(asset.path)) { AddEntries(node, new string[1] { asset.name }, nodeEntries); } else if (title[0] != k_HiddenFolderName) { title.Add(asset.name); AddEntries(node, title.ToArray(), nodeEntries); } } Profiler.EndSample(); Profiler.BeginSample("SearchWindowProvider.GenerateNodeEntries.IterateGraphInputs"); foreach (var property in m_Graph.properties) { if (property is Serialization.MultiJsonInternal.UnknownShaderPropertyType) { continue; } var node = new PropertyNode(); node.property = property; AddEntries(node, new[] { "Properties", "Property: " + property.displayName }, nodeEntries); } foreach (var keyword in m_Graph.keywords) { var node = new KeywordNode(); node.keyword = keyword; AddEntries(node, new[] { "Keywords", "Keyword: " + keyword.displayName }, nodeEntries); } foreach (var dropdown in m_Graph.dropdowns) { var node = new DropdownNode(); node.dropdown = dropdown; AddEntries(node, new[] { "Dropdowns", "dropdown: " + dropdown.displayName }, nodeEntries); } if (!hideCustomInterpolators) { foreach (var cibnode in m_Graph.vertexContext.blocks.Where(b => b.value.isCustomBlock)) { var node = Activator.CreateInstance <CustomInterpolatorNode>(); node.ConnectToCustomBlock(cibnode.value); AddEntries(node, new[] { "Custom Interpolator", cibnode.value.customName }, nodeEntries); } } Profiler.EndSample(); SortEntries(nodeEntries); currentNodeEntries = nodeEntries; Profiler.EndSample(); }