public bool RefreshNodes(ParentGraph currentGraph) { if (m_items != null) { m_items.Clear(); m_items = null; } if (m_itemFunctions != null) { m_itemFunctions.Clear(); m_itemFunctions = null; } m_items = new List <ContextMenuItem>(); m_itemFunctions = new List <ContextMenuItem>(); if (m_itemsDict != null) { m_itemsDict.Clear(); } m_itemsDict = new Dictionary <System.Type, NodeAttributes>(); if (m_deprecatedItemsDict != null) { m_deprecatedItemsDict.Clear(); } m_deprecatedItemsDict = new Dictionary <System.Type, NodeAttributes>(); if (m_castTypes != null) { m_castTypes.Clear(); } m_castTypes = new Dictionary <System.Type, System.Type>(); if (m_shortcutTypes != null) { m_shortcutTypes.Clear(); } m_shortcutTypes = new Dictionary <KeyCode, ShortcutKeyData>(); m_lastKeyPressed = KeyCode.None; // Fetch all available nodes by their attributes try { IEnumerable <System.Type> availableTypes = AppDomain.CurrentDomain.GetAssemblies().ToList().SelectMany(type => type.GetTypes()); foreach (System.Type type in availableTypes) { foreach (NodeAttributes attribute in Attribute.GetCustomAttributes(type).OfType <NodeAttributes>()) { if (attribute.Available && !attribute.Deprecated) { //if ( !UIUtils.CurrentWindow.IsShaderFunctionWindow && attribute.AvailableInFunctionsOnly ) // continue; if (!UIUtils.HasColorCategory(attribute.Category)) { if (!String.IsNullOrEmpty(attribute.CustomCategoryColor)) { try { Color color = new Color(); ColorUtility.TryParseHtmlString(attribute.CustomCategoryColor, out color); UIUtils.AddColorCategory(attribute.Category, color); } catch (Exception e) { Debug.LogException(e); UIUtils.AddColorCategory(attribute.Category, Constants.DefaultCategoryColor); } } //else //{ // UIUtils.AddColorCategory( attribute.Category, Constants.DefaultCategoryColor ); //} } if (attribute.CastType != null && attribute.CastType.Length > 0 && type != null) { for (int i = 0; i < attribute.CastType.Length; i++) { m_castTypes.Add(attribute.CastType[i], type); } } if (attribute.ShortcutKey != KeyCode.None && type != null) { m_shortcutTypes.Add(attribute.ShortcutKey, new ShortcutKeyData(type, attribute.Name)); } ContextMenuItem newItem = new ContextMenuItem(attribute, type, attribute.Name, attribute.Category, attribute.Description, null, attribute.ShortcutKey); if (UIUtils.GetNodeAvailabilityInBitArray(attribute.NodeAvailabilityFlags, NodeAvailability.SurfaceShader)) { m_items.Add(newItem); } else if (UIUtils.GetNodeAvailabilityInBitArray(attribute.NodeAvailabilityFlags, currentGraph.ParentWindow.CurrentNodeAvailability)) { m_items.Add(newItem); } m_itemsDict.Add(type, attribute); m_itemFunctions.Add(newItem); } else { m_deprecatedItemsDict.Add(type, attribute); } } } } catch (ReflectionTypeLoadException exception) { Debug.LogException(exception); return(false); } string[] guids = AssetDatabase.FindAssets("t:AmplifyShaderFunction"); List <AmplifyShaderFunction> allFunctions = new List <AmplifyShaderFunction>(); for (int i = 0; i < guids.Length; i++) { allFunctions.Add(AssetDatabase.LoadAssetAtPath <AmplifyShaderFunction>(AssetDatabase.GUIDToAssetPath(guids[i]))); } int functionCount = allFunctions.Count; if (functionCount > 0) { m_castTypes.Add(typeof(AmplifyShaderFunction), typeof(FunctionNode)); } for (int i = 0; i < functionCount; i++) { NodeAttributes attribute = new NodeAttributes(allFunctions[i].FunctionName, allFunctions[i].CustomNodeCategory, allFunctions[i].Description, KeyCode.None, true, 0, int.MaxValue, typeof(AmplifyShaderFunction)); System.Type type = typeof(FunctionNode); ContextMenuItem newItem = new ContextMenuItem(attribute, type, attribute.Name, attribute.Category, attribute.Description, allFunctions[i], attribute.ShortcutKey); m_items.Add(newItem); m_itemFunctions.Add(newItem); } //Sort out the final list by name m_items.Sort((x, y) => x.Category.CompareTo(y.Category)); m_itemFunctions.Sort((x, y) => x.Category.CompareTo(y.Category)); return(true); }
public void Destroy() { m_guiContent = null; m_nodeAttributes = null; }