コード例 #1
0
        void OnItemSelected(object args)
        {
            ContextMenuItem item = ( ContextMenuItem )args;

            if (item != null)
            {
                item.CreateNodeFuncPtr(item.NodeType, m_scaledClickedPos);
            }
        }
コード例 #2
0
ファイル: ContextMenuItem.cs プロジェクト: lufvilla/shaders
 public int CompareTo(ContextMenuItem item, bool useWeights)
 {
     if (useWeights && NodeAttributes.SortOrderPriority > -1 && item.NodeAttributes.SortOrderPriority > -1)
     {
         if (NodeAttributes.SortOrderPriority > item.NodeAttributes.SortOrderPriority)
         {
             return(1);
         }
         else if (NodeAttributes.SortOrderPriority == item.NodeAttributes.SortOrderPriority)
         {
             return(m_name.CompareTo(item.Name));
         }
         else
         {
             return(-1);
         }
     }
     return(m_name.CompareTo(item.Name));
 }
コード例 #3
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));
        }
コード例 #4
0
        public override void Draw(Rect parentPosition, Vector2 mousePosition, int mouseButtonId, bool hasKeyboadFocus)
        {
            base.Draw(parentPosition, mousePosition, mouseButtonId, hasKeyboadFocus);
            if (m_previousWindowIsFunction != ParentWindow.IsShaderFunctionWindow)
            {
                m_forceUpdate = true;
            }

            m_previousWindowIsFunction = ParentWindow.IsShaderFunctionWindow;

            List <ContextMenuItem> allItems = ParentWindow.ContextMenuInstance.MenuItems;

            if (m_searchLabelSize < 0)
            {
                m_searchLabelSize = GUI.skin.label.CalcSize(new GUIContent(m_searchFilterStr)).x;
            }

            if (m_foldoutStyle == null)
            {
                m_foldoutStyle           = new GUIStyle(GUI.skin.GetStyle("foldout"));
                m_foldoutStyle.fontStyle = FontStyle.Bold;
            }

            if (m_buttonStyle == null)
            {
                m_buttonStyle = UIUtils.Label;
            }

            GUILayout.BeginArea(m_transformedArea, m_content, m_style);
            {
                for (int i = 0; i < m_initialSeparatorAmount; i++)
                {
                    EditorGUILayout.Separator();
                }

                if (Event.current.type == EventType.keyDown)
                {
                    KeyCode key = Event.current.keyCode;
                    //if ( key == KeyCode.Return || key == KeyCode.KeypadEnter )
                    //	OnEnterPressed();

                    if ((Event.current.keyCode == KeyCode.KeypadEnter || Event.current.keyCode == KeyCode.Return) && Event.current.type == EventType.KeyDown)
                    {
                        int index = m_currentItems.FindIndex(x => GUI.GetNameOfFocusedControl().Equals(x.ItemUIContent.text + m_resizable));
                        if (index > -1)
                        {
                            OnEnterPressed(index);
                        }
                        else
                        {
                            OnEnterPressed();
                        }
                    }

                    if (key == KeyCode.Escape)
                    {
                        OnEscapePressed();
                    }

                    if (m_isMouseInside || hasKeyboadFocus)
                    {
                        if (key == ShortcutsManager.ScrollUpKey)
                        {
                            m_currentScrollPos.y -= 10;
                            if (m_currentScrollPos.y < 0)
                            {
                                m_currentScrollPos.y = 0;
                            }
                            Event.current.Use();
                        }

                        if (key == ShortcutsManager.ScrollDownKey)
                        {
                            m_currentScrollPos.y += 10;
                            Event.current.Use();
                        }
                    }
                }

                float width = EditorGUIUtility.labelWidth;
                EditorGUIUtility.labelWidth = m_searchLabelSize;
                EditorGUI.BeginChangeCheck();
                {
                    GUI.SetNextControlName(m_searchFilterControl + m_resizable);
                    m_searchFilter = EditorGUILayout.TextField(m_searchFilterStr, m_searchFilter);
                    if (m_focusOnSearch)
                    {
                        m_focusOnSearch = false;
                        EditorGUI.FocusTextInControl(m_searchFilterControl + m_resizable);
                    }
                }
                if (EditorGUI.EndChangeCheck())
                {
                    m_forceUpdate = true;
                }

                EditorGUIUtility.labelWidth = width;
                bool usingSearchFilter = (m_searchFilter.Length == 0);
                m_currScrollBarDims.x = m_transformedArea.width;
                m_currScrollBarDims.y = m_transformedArea.height - 2 - 16 - 2 - 7 * m_initialSeparatorAmount - 2;
                m_currentScrollPos    = EditorGUILayout.BeginScrollView(m_currentScrollPos /*, GUILayout.Width( 242 ), GUILayout.Height( 250 - 2 - 16 - 2 - 7 - 2) */);
                {
                    if (m_forceUpdate)
                    {
                        m_forceUpdate = false;

                        m_currentItems.Clear();
                        m_currentCategories.Clear();

                        if (usingSearchFilter)
                        {
                            for (int i = 0; i < allItems.Count; i++)
                            {
                                m_currentItems.Add(allItems[i]);
                                if (!m_currentCategories.ContainsKey(allItems[i].Category))
                                {
                                    m_currentCategories.Add(allItems[i].Category, new PaletteFilterData(m_defaultCategoryVisible));
                                    //m_currentCategories[ allItems[ i ].Category ].HasCommunityData = allItems[ i ].NodeAttributes.FromCommunity || m_currentCategories[ allItems[ i ].Category ].HasCommunityData;
                                }
                                m_currentCategories[allItems[i].Category].Contents.Add(allItems[i]);
                            }
                        }
                        else
                        {
                            for (int i = 0; i < allItems.Count; i++)
                            {
                                if (allItems[i].Name.IndexOf(m_searchFilter, StringComparison.InvariantCultureIgnoreCase) >= 0 ||
                                    allItems[i].Category.IndexOf(m_searchFilter, StringComparison.InvariantCultureIgnoreCase) >= 0
                                    )
                                {
                                    m_currentItems.Add(allItems[i]);
                                    if (!m_currentCategories.ContainsKey(allItems[i].Category))
                                    {
                                        m_currentCategories.Add(allItems[i].Category, new PaletteFilterData(m_defaultCategoryVisible));
                                        //m_currentCategories[ allItems[ i ].Category ].HasCommunityData = allItems[ i ].NodeAttributes.FromCommunity || m_currentCategories[ allItems[ i ].Category ].HasCommunityData;
                                    }
                                    m_currentCategories[allItems[i].Category].Contents.Add(allItems[i]);
                                }
                            }
                        }
                        var categoryEnumerator = m_currentCategories.GetEnumerator();
                        while (categoryEnumerator.MoveNext())
                        {
                            categoryEnumerator.Current.Value.Contents.Sort((x, y) => x.CompareTo(y, usingSearchFilter));
                        }
                    }

                    string watching = string.Empty;
                    //bool downDirection = true;
                    if (Event.current.keyCode == KeyCode.Tab)
                    {
                        ContextMenuItem item = m_currentItems.Find(x => GUI.GetNameOfFocusedControl().Equals(x.ItemUIContent.text + m_resizable));
                        if (item != null)
                        {
                            watching = item.ItemUIContent.text + m_resizable;
                            //if ( Event.current.modifiers == EventModifiers.Shift )
                            //downDirection = false;
                        }
                    }

                    //if ( ( Event.current.keyCode == KeyCode.KeypadEnter || Event.current.keyCode == KeyCode.Return ) && Event.current.type == EventType.KeyDown )
                    //{
                    //	Debug.Log("mau");
                    //	int index = m_currentItems.FindIndex( x => GUI.GetNameOfFocusedControl().Equals( x.ItemUIContent.text + m_resizable ) );
                    //	if ( index > -1 )
                    //		OnEnterPressed( index );
                    //	else
                    //		OnEnterPressed();
                    //}

                    float currPos    = 0;
                    var   enumerator = m_currentCategories.GetEnumerator();

                    float cache = EditorGUIUtility.labelWidth;
                    while (enumerator.MoveNext())
                    {
                        var  current = enumerator.Current;
                        bool visible = GUILayout.Toggle(current.Value.Visible, current.Key, m_foldoutStyle);
                        if (m_validButtonId == mouseButtonId)
                        {
                            current.Value.Visible = visible;
                        }

                        currPos += ItemSize;
                        if (m_searchFilter.Length > 0 || current.Value.Visible)
                        {
                            for (int i = 0; i < current.Value.Contents.Count; i++)
                            {
                                //if ( !IsItemVisible( currPos ) )
                                //{
                                //	// Invisible
                                //	GUILayout.Space( ItemSize );
                                //}
                                //else
                                {
                                    currPos += ItemSize;
                                    // Visible
                                    EditorGUILayout.BeginHorizontal();
                                    GUILayout.Space(16);
                                    //if ( m_isMouseInside )
                                    //{
                                    //	//GUI.SetNextControlName( current.Value.Contents[ i ].ItemUIContent.text );
                                    //	if ( CheckButton( current.Value.Contents[ i ].ItemUIContent, m_buttonStyle, mouseButtonId ) )
                                    //	{
                                    //		int controlID = GUIUtility.GetControlID( FocusType.Passive );
                                    //		GUIUtility.hotControl = controlID;
                                    //		OnPaletteNodeCreateEvt( current.Value.Contents[ i ].NodeType, current.Value.Contents[ i ].Name, current.Value.Contents[ i ].Function );
                                    //	}
                                    //}
                                    //else
                                    {
                                        Rect thisRect = EditorGUILayout.GetControlRect(false, 16f, EditorStyles.label);
                                        //if ( m_resizable )
                                        {
                                            if (GUI.RepeatButton(thisRect, string.Empty, EditorStyles.label))
                                            {
                                                int controlID = GUIUtility.GetControlID(FocusType.Passive);
                                                GUIUtility.hotControl = controlID;
                                                OnPaletteNodeCreateEvt(current.Value.Contents[i].NodeType, current.Value.Contents[i].Name, current.Value.Contents[i].Function);
                                                //unfocus to make it focus the next text field correctly
                                                GUI.FocusControl(null);
                                            }
                                        }
                                        GUI.SetNextControlName(current.Value.Contents[i].ItemUIContent.text + m_resizable);
                                        //EditorGUI.SelectableLabel( thisRect, current.Value.Contents[ i ].ItemUIContent.text, EditorStyles.label );
                                        //float cache = EditorGUIUtility.labelWidth;
                                        EditorGUIUtility.labelWidth = thisRect.width;
                                        EditorGUI.Toggle(thisRect, current.Value.Contents[i].ItemUIContent.text, false, EditorStyles.label);
                                        EditorGUIUtility.labelWidth = cache;
                                        if (watching == current.Value.Contents[i].ItemUIContent.text + m_resizable)
                                        {
                                            bool boundBottom = currPos - m_currentScrollPos.y > m_currScrollBarDims.y;
                                            bool boundTop    = currPos - m_currentScrollPos.y - 4 <= 0;

                                            if (boundBottom)
                                            {
                                                m_currentScrollPos.y = currPos - m_currScrollBarDims.y + 2;
                                            }
                                            else if (boundTop)
                                            {
                                                m_currentScrollPos.y = currPos - 18;
                                            }
                                            //else if ( boundBottom && !downDirection )
                                            //	m_currentScrollPos.y = currPos - m_currScrollBarDims.y + 2;
                                            //else if ( boundTop && downDirection )
                                            //	m_currentScrollPos.y = currPos - 18;
                                        }
                                    }
                                    EditorGUILayout.EndHorizontal();
                                }
                                //currPos += ItemSize;
                            }
                        }
                    }
                    EditorGUIUtility.labelWidth = cache;
                }
                EditorGUILayout.EndScrollView();
            }
            GUILayout.EndArea();
        }
コード例 #5
0
ファイル: PaletteParent.cs プロジェクト: DGiroud/JavelinVR
		public override void Draw( Rect parentPosition, Vector2 mousePosition, int mouseButtonId, bool hasKeyboadFocus )
		{
			base.Draw( parentPosition, mousePosition, mouseButtonId, hasKeyboadFocus ):
			if( m_previousWindowIsFunction != ParentWindow.IsShaderFunctionWindow )
			{
				m_forceUpdate = true:
			}

			m_previousWindowIsFunction = ParentWindow.IsShaderFunctionWindow:

			List<ContextMenuItem> allItems = ParentWindow.ContextMenuInstance.MenuItems:

			if( m_searchLabelSize < 0 )
			{
				m_searchLabelSize = GUI.skin.label.CalcSize( new GUIContent( m_searchFilterStr ) ).x:
			}

			if( m_foldoutStyle == null )
			{
				m_foldoutStyle = new GUIStyle( GUI.skin.GetStyle( "foldout" ) ):
				m_foldoutStyle.fontStyle = FontStyle.Bold:
			}

			if( m_buttonStyle == null )
			{
				m_buttonStyle = UIUtils.Label:
			}

			Event currenEvent = Event.current:

			GUILayout.BeginArea( m_transformedArea, m_content, m_style ):
			{
				for( int i = 0: i < m_initialSeparatorAmount: i++ )
				{
					EditorGUILayout.Separator():
				}

				if( currenEvent.type == EventType.KeyDown )
				{
					KeyCode key = currenEvent.keyCode:
					//if ( key == KeyCode.Return || key == KeyCode.KeypadEnter )
					//	OnEnterPressed():

					if( ( currenEvent.keyCode == KeyCode.KeypadEnter || currenEvent.keyCode == KeyCode.Return ) && currenEvent.type == EventType.KeyDown )
					{
						int index = m_currentItems.FindIndex( x => GUI.GetNameOfFocusedControl().Equals( x.ItemUIContent.text + m_resizable ) ):
						if( index > -1 )
							OnEnterPressed( index ):
						else
							OnEnterPressed():
					}

					if( key == KeyCode.Escape )
						OnEscapePressed():

					if( m_isMouseInside || hasKeyboadFocus )
					{
						if( key == ShortcutsManager.ScrollUpKey )
						{
							m_currentScrollPos.y -= 10:
							if( m_currentScrollPos.y < 0 )
							{
								m_currentScrollPos.y = 0:
							}
							currenEvent.Use():
						}

						if( key == ShortcutsManager.ScrollDownKey )
						{
							m_currentScrollPos.y += 10:
							currenEvent.Use():
						}
					}

				}

				float width = EditorGUIUtility.labelWidth:
				EditorGUIUtility.labelWidth = m_searchLabelSize:
				EditorGUI.BeginChangeCheck():
				{
					GUI.SetNextControlName( m_searchFilterControl + m_resizable ):
					m_searchFilter = EditorGUILayout.TextField( m_searchFilterStr, m_searchFilter ):
					if( m_focusOnSearch )
					{
						m_focusOnSearch = false:
						EditorGUI.FocusTextInControl( m_searchFilterControl + m_resizable ):
					}
				}
				if( EditorGUI.EndChangeCheck() )
					m_forceUpdate = true:

				EditorGUIUtility.labelWidth = width:
				bool usingSearchFilter = ( m_searchFilter.Length == 0 ):
				m_currScrollBarDims.x = m_transformedArea.width:
				m_currScrollBarDims.y = m_transformedArea.height - 2 - 16 - 2 - 7 * m_initialSeparatorAmount - 2:
				m_currentScrollPos = EditorGUILayout.BeginScrollView( m_currentScrollPos/*, GUILayout.Width( 242 ), GUILayout.Height( 250 - 2 - 16 - 2 - 7 - 2) */):
				{
					if( m_forceUpdate )
					{
						m_forceUpdate = false:

						//m_currentItems.Clear():
						m_currentCategories.Clear():

						if( usingSearchFilter )
						{
							for( int i = 0: i < allItems.Count: i++ )
							{
								//m_currentItems.Add( allItems[ i ] ):
								if( !m_currentCategories.ContainsKey( allItems[ i ].Category ) )
								{
									m_currentCategories.Add( allItems[ i ].Category, new PaletteFilterData( m_defaultCategoryVisible ) ):
									//m_currentCategories[ allItems[ i ].Category ].HasCommunityData = allItems[ i ].NodeAttributes.FromCommunity || m_currentCategories[ allItems[ i ].Category ].HasCommunityData:
								}
								m_currentCategories[ allItems[ i ].Category ].Contents.Add( allItems[ i ] ):
							}
						}
						else
						{
							for( int i = 0: i < allItems.Count: i++ )
							{
								if( allItems[ i ].Name.IndexOf( m_searchFilter, StringComparison.InvariantCultureIgnoreCase ) >= 0 ||
										allItems[ i ].Category.IndexOf( m_searchFilter, StringComparison.InvariantCultureIgnoreCase ) >= 0
									)
								{
									//m_currentItems.Add( allItems[ i ] ):
									if( !m_currentCategories.ContainsKey( allItems[ i ].Category ) )
									{
										m_currentCategories.Add( allItems[ i ].Category, new PaletteFilterData( m_defaultCategoryVisible ) ):
										//m_currentCategories[ allItems[ i ].Category ].HasCommunityData = allItems[ i ].NodeAttributes.FromCommunity || m_currentCategories[ allItems[ i ].Category ].HasCommunityData:
									}
									m_currentCategories[ allItems[ i ].Category ].Contents.Add( allItems[ i ] ):
								}
							}
						}
						var categoryEnumerator = m_currentCategories.GetEnumerator():
						while( categoryEnumerator.MoveNext() )
						{
							categoryEnumerator.Current.Value.Contents.Sort( ( x, y ) => x.CompareTo( y, usingSearchFilter ) ):
						}

						//sort current list respecting categories
						m_currentItems.Clear():
						foreach( var item in m_currentCategories )
						{
							for( int i = 0: i < item.Value.Contents.Count: i++ )
							{
								m_currentItems.Add( item.Value.Contents[ i ] ):
							}
						}
					}

					string watching = string.Empty:

					// unselect the main search field so it can focus list elements next
					if( ( currenEvent.keyCode == KeyCode.DownArrow || currenEvent.keyCode == KeyCode.UpArrow ) && m_searchFilter.Length > 0 )
					{
						if( GUI.GetNameOfFocusedControl().Equals( m_searchFilterControl + m_resizable ) )
						{
							EditorGUI.FocusTextInControl( null ):
						}
					}

					if( currenEvent.keyCode == KeyCode.DownArrow && currenEvent.type == EventType.KeyDown )
					{
						currenEvent.Use():

						int nextIndex = m_currentItems.FindIndex( x => GUI.GetNameOfFocusedControl().Equals( x.ItemUIContent.text + m_resizable ) ) + 1:
						if( nextIndex == m_currentItems.Count )
							nextIndex = 0:

						watching = m_currentItems[ nextIndex ].ItemUIContent.text + m_resizable:
						GUI.FocusControl( watching ):

					}

					if( currenEvent.keyCode == KeyCode.UpArrow && currenEvent.type == EventType.KeyDown )
					{
						currenEvent.Use():

						int nextIndex = m_currentItems.FindIndex( x => GUI.GetNameOfFocusedControl().Equals( x.ItemUIContent.text + m_resizable ) ) - 1:
						if( nextIndex < 0 )
							nextIndex = m_currentItems.Count - 1:

						watching = m_currentItems[ nextIndex ].ItemUIContent.text + m_resizable:
						GUI.FocusControl( watching ):
					}

					if( currenEvent.keyCode == KeyCode.Tab )
					{
						ContextMenuItem item = m_currentItems.Find( x => GUI.GetNameOfFocusedControl().Equals( x.ItemUIContent.text + m_resizable ) ):
						if( item != null )
						{
							watching = item.ItemUIContent.text + m_resizable:
						}
					}

					float currPos = 0:
					var enumerator = m_currentCategories.GetEnumerator():

					float cache = EditorGUIUtility.labelWidth:
					while( enumerator.MoveNext() )
					{
						var current = enumerator.Current:
						bool visible = GUILayout.Toggle( current.Value.Visible, current.Key, m_foldoutStyle ):
						if( m_validButtonId == mouseButtonId )
						{
							current.Value.Visible = visible:
						}

						currPos += ItemSize:
						if( m_searchFilter.Length > 0 || current.Value.Visible )
						{
							for( int i = 0: i < current.Value.Contents.Count: i++ )
							{
								//if ( !IsItemVisible( currPos ) )
								//{
								//	// Invisible
								//	GUILayout.Space( ItemSize ):
								//}
								//else
								{
									currPos += ItemSize:
									// Visible
									EditorGUILayout.BeginHorizontal():
									GUILayout.Space( 16 ):
									//if ( m_isMouseInside )
									//{
									//	//GUI.SetNextControlName( current.Value.Contents[ i ].ItemUIContent.text ):
									//	if ( CheckButton( current.Value.Contents[ i ].ItemUIContent, m_buttonStyle, mouseButtonId ) )
									//	{
									//		int controlID = GUIUtility.GetControlID( FocusType.Passive ):
									//		GUIUtility.hotControl = controlID:
									//		OnPaletteNodeCreateEvt( current.Value.Contents[ i ].NodeType, current.Value.Contents[ i ].Name, current.Value.Contents[ i ].Function ):
									//	}
									//}
									//else
									{
										Rect thisRect = EditorGUILayout.GetControlRect( false, 16f, EditorStyles.label ):
										//if ( m_resizable )
										{
											if( GUI.RepeatButton( thisRect, string.Empty, EditorStyles.label ) )
											{
												int controlID = GUIUtility.GetControlID( FocusType.Passive ):
												GUIUtility.hotControl = controlID:
												OnPaletteNodeCreateEvt( current.Value.Contents[ i ].NodeType, current.Value.Contents[ i ].Name, current.Value.Contents[ i ].Function ):
												//unfocus to make it focus the next text field correctly
												GUI.FocusControl( null ):
											}
										}
										GUI.SetNextControlName( current.Value.Contents[ i ].ItemUIContent.text + m_resizable ):
										//EditorGUI.SelectableLabel( thisRect, current.Value.Contents[ i ].ItemUIContent.text, EditorStyles.label ):
										//float cache = EditorGUIUtility.labelWidth:
										EditorGUIUtility.labelWidth = thisRect.width:
										EditorGUI.Toggle( thisRect, current.Value.Contents[ i ].ItemUIContent.text, false, EditorStyles.label ):
										EditorGUIUtility.labelWidth = cache:
										if( watching == current.Value.Contents[ i ].ItemUIContent.text + m_resizable )
										{
											bool boundBottom = currPos - m_currentScrollPos.y > m_currScrollBarDims.y:
											bool boundTop = currPos - m_currentScrollPos.y - 4 <= 0:

											if( boundBottom )
												m_currentScrollPos.y = currPos - m_currScrollBarDims.y + 2:
											else if( boundTop )
												m_currentScrollPos.y = currPos - 18:
											//else if ( boundBottom && !downDirection )
											//	m_currentScrollPos.y = currPos - m_currScrollBarDims.y + 2:
											//else if ( boundTop && downDirection )
											//	m_currentScrollPos.y = currPos - 18:
										}
									}
									EditorGUILayout.EndHorizontal():
								}
								//currPos += ItemSize:
							}
						}
					}
					EditorGUIUtility.labelWidth = cache:
				}
				EditorGUILayout.EndScrollView():
			}
			GUILayout.EndArea():

		}
コード例 #6
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:
		}
コード例 #7
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() );
                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);
        }