//public bool m_autoInclude = true;
        //public const string m_defaultIncludePath = "assets/VertExmotion/Shaders/VertExmotion.cginc";

        protected override void CommonInit(int uniqueId)
        {
            if (!UIUtils.HasColorCategory("VertExmotion"))
            {
                UIUtils.AddColorCategory("VertExmotion", new Color(.945f, .624f, 0, 1));
            }

            base.CommonInit(uniqueId);
        }
예제 #2
0
        public void 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 <Type, NodeAttributes>();

            if (m_deprecatedItemsDict != null)
            {
                m_deprecatedItemsDict.Clear();
            }

            m_deprecatedItemsDict = new Dictionary <Type, NodeAttributes>();

            if (m_castTypes != null)
            {
                m_castTypes.Clear();
            }

            m_castTypes = new Dictionary <Type, 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
            IEnumerable <Type> availableTypes = AppDomain.CurrentDomain.GetAssemblies().ToList().SelectMany(type => type.GetTypes());

            foreach (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 (/*!attribute.AvailableInFunctionsOnly*/ UIUtils.GetNodeAvailabilityInBitArray(attribute.NodeAvailabilityFlags, NodeAvailability.SurfaceShader))
                        {
                            m_items.Add(newItem);
                        }

                        m_itemsDict.Add(type, attribute);
                        m_itemFunctions.Add(newItem);
                    }
                    else
                    {
                        m_deprecatedItemsDict.Add(type, attribute);
                    }
                }
            }

            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, "Functions", allFunctions[i].Description, KeyCode.None, true, 0, int.MaxValue, typeof(AmplifyShaderFunction));
                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));
        }
예제 #3
0
		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() ):
				Type[] availableTypes = GetTypesInNamespace( Assembly.GetExecutingAssembly(), "AmplifyShaderEditor" ):
				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 ):
							else if( UIUtils.GetNodeAvailabilityInBitArray( attribute.NodeAvailabilityFlags, currentGraph.CurrentCanvasMode ) )
								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++ )
			{
				if( !allFunctions[ i ].Hidden )
				{
					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:
		}
예제 #4
0
        public void RefreshNodes(ParentGraph currentGraph)
        {
            if (m_items != null)
            {
                m_items.Clear();
            }

            m_items = new List <ContextMenuItem>();

            if (m_itemsDict != null)
            {
                m_itemsDict.Clear();
            }

            m_itemsDict = new Dictionary <Type, NodeAttributes>();

            if (m_deprecatedItemsDict != null)
            {
                m_deprecatedItemsDict.Clear();
            }

            m_deprecatedItemsDict = new Dictionary <Type, NodeAttributes>();

            if (m_castTypes != null)
            {
                m_castTypes.Clear();
            }

            m_castTypes = new Dictionary <Type, Type>();

            if (m_shortcutTypes != null)
            {
                m_shortcutTypes.Clear();
            }

            m_shortcutTypes = new Dictionary <KeyCode, ShortcuKeyData>();

            m_lastKeyPressed = KeyCode.None;

            // Fetch all available nodes by their attributes
            IEnumerable <Type> availableTypes = AppDomain.CurrentDomain.GetAssemblies().ToList().SelectMany(type => type.GetTypes());

            foreach (Type type in availableTypes)
            {
                foreach (NodeAttributes attribute in Attribute.GetCustomAttributes(type).OfType <NodeAttributes>())
                {
                    if (attribute.Available && !attribute.Deprecated)
                    {
                        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 ShortcuKeyData(type));
                        }

                        m_itemsDict.Add(type, attribute);
                        m_items.Add(new ContextMenuItem(attribute, type, attribute.Name, attribute.Category, attribute.Description, attribute.ShortcutKey, (Type newType, Vector2 position) =>
                        {
                            ParentNode newNode = ( ParentNode )ScriptableObject.CreateInstance(newType);
                            if (newNode != null)
                            {
                                newNode.Vec2Position = position;
                                currentGraph.AddNode(newNode, true);
                                if (UIUtils.InputPortReference.IsValid)
                                {
                                    OutputPort port = newNode.GetFirstOutputPortOfType(UIUtils.InputPortReference.DataType, true);
                                    if (port != null)
                                    {
                                        port.ConnectTo(UIUtils.InputPortReference.NodeId, UIUtils.InputPortReference.PortId, UIUtils.InputPortReference.DataType, UIUtils.InputPortReference.TypeLocked);
                                        UIUtils.GetNode(UIUtils.InputPortReference.NodeId).GetInputPortByUniqueId(UIUtils.InputPortReference.PortId).ConnectTo(port.NodeId, port.PortId, port.DataType, UIUtils.InputPortReference.TypeLocked);
                                    }
                                }
                                if (UIUtils.OutputPortReference.IsValid)
                                {
                                    InputPort port = newNode.GetFirstInputPortOfType(UIUtils.OutputPortReference.DataType, true);
                                    if (port != null)
                                    {
                                        port.ConnectTo(UIUtils.OutputPortReference.NodeId, UIUtils.OutputPortReference.PortId, UIUtils.OutputPortReference.DataType, port.TypeLocked);
                                        UIUtils.GetNode(UIUtils.OutputPortReference.NodeId).GetOutputPortByUniqueId(UIUtils.OutputPortReference.PortId).ConnectTo(port.NodeId, port.PortId, port.DataType, port.TypeLocked);
                                    }
                                }
                                UIUtils.InvalidateReferences();
                            }
                            return(newNode);
                        }));
                    }
                    else
                    {
                        m_deprecatedItemsDict.Add(type, attribute);
                    }
                }
            }

            //Sort out the final list by name
            m_items.Sort((ContextMenuItem item0, ContextMenuItem item1) => { return(item0.Name.CompareTo(item1.Name)); });

            // Add them to the context menu
            m_menu = new GenericMenu();
            foreach (ContextMenuItem item in m_items)
            {
                //The / on the GUIContent creates categories on the context menu
                m_menu.AddItem(new GUIContent(item.Category + "/" + item.Name, item.Description), false, OnItemSelected, item);
            }
        }
        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() );
                var    mainAssembly   = Assembly.GetExecutingAssembly();
                Type[] availableTypes = GetTypesInNamespace(mainAssembly, "AmplifyShaderEditor");

#if UNITY_2017_3_OR_NEWER
                try
                {
                    var editorAssembly = Assembly.Load("Assembly-CSharp-Editor");
                    if (mainAssembly != editorAssembly)
                    {
                        Type[] extraTypes = GetTypesInNamespace(editorAssembly, "AmplifyShaderEditor");
                        availableTypes = availableTypes.Concat <Type>(extraTypes).ToArray();
                    }
                }
                catch (Exception)
                {
                    // quiet catch because we don't care if it fails to find the assembly, we'll just skip it
                }
#endif

                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.Tags, 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);
                            }
                            else if (UIUtils.GetNodeAvailabilityInBitArray(attribute.NodeAvailabilityFlags, currentGraph.CurrentCanvasMode))
                            {
                                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++)
            {
                if (!allFunctions[i].Hidden)
                {
                    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, AddSpacesToSentence(attribute.Name), attribute.Tags, 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);
        }