Beispiel #1
0
        public bool RecursiveConnectedProperties()
        {
            bool connected = false;

            if (m_propertyList != null)
            {
                for (int i = 0; i < m_propertyList.Count; i++)
                {
                    ReordenatorNode renode = (m_propertyList[i] as ReordenatorNode);
                    if (renode != null)
                    {
                        bool temp = renode.RecursiveConnectedProperties();
                        if (temp)
                        {
                            connected = true;
                        }
                    }
                    else
                    {
                        if ((m_propertyList[i] as PropertyNode).IsConnected)
                        {
                            connected = true;
                        }
                    }
                }
            }
            return(connected);
        }
        private void ReorderList(ref List <PropertyNode> nodes)
        {
            // clear lock list before reordering because of multiple sf being used
            for (int i = 0; i < nodes.Count; i++)
            {
                ReordenatorNode rnode = nodes[i] as ReordenatorNode;
                if (rnode != null)
                {
                    rnode.RecursiveClear();
                }
            }

            int propoffset = 0;
            int count      = 0;

            for (int i = 0; i < m_propertyReordableNodes.Count; i++)
            {
                ReordenatorNode renode = m_propertyReordableNodes[i] as ReordenatorNode;
                if (renode != null)
                {
                    if (!renode.IsInside)
                    {
                        m_propertyReordableNodes[i].OrderIndex = count + propoffset;

                        if (renode.PropertyListCount > 0)
                        {
                            propoffset += renode.RecursiveCount();

                            // the same reordenator can exist multiple times, apply ordering to all of them
                            for (int j = 0; j < nodes.Count; j++)
                            {
                                ReordenatorNode pnode = (nodes[j] as ReordenatorNode);
                                if (pnode != null && pnode.PropertyName.Equals(renode.PropertyName))
                                {
                                    pnode.OrderIndex = renode.RawOrderIndex;
                                    pnode.RecursiveSetOrderOffset(renode.RawOrderIndex, true);
                                }
                            }
                        }
                        else
                        {
                            count++;
                        }
                    }
                    else
                    {
                        m_propertyReordableNodes[i].OrderIndex = 0;
                    }
                }
                else
                {
                    m_propertyReordableNodes[i].OrderIndex = count + propoffset;
                    count++;
                }
            }
        }
        public void DrawFunctionProperties()
        {
            List <ParentNode> nodes = UIUtils.PropertyNodesList();

            if (m_propertyReordableList == null || nodes.Count != m_lastCount)
            {
                m_propertyReordableNodes.Clear();

                for (int i = 0; i < nodes.Count; i++)
                {
                    PropertyNode node = nodes[i] as PropertyNode;
                    if (node != null)
                    {
                        ReordenatorNode rnode = nodes[i] as ReordenatorNode;
                        if ((rnode == null || !rnode.IsInside) && (!m_propertyReordableNodes.Exists(x => x.PropertyName.Equals(node.PropertyName))))
                        {
                            m_propertyReordableNodes.Add(node);
                        }
                    }
                }

                m_propertyReordableNodes.Sort((x, y) => { return(x.OrderIndex.CompareTo(y.OrderIndex)); });

                m_propertyReordableList = new ReorderableList(m_propertyReordableNodes, typeof(PropertyNode), true, false, false, false);
                m_propertyReordableList.headerHeight          = 0;
                m_propertyReordableList.footerHeight          = 0;
                m_propertyReordableList.showDefaultBackground = false;

                m_propertyReordableList.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) =>
                {
                    EditorGUI.LabelField(rect, /*m_propertyReordableNodes[ index ].OrderIndex + " " + */ m_propertyReordableNodes[index].PropertyInspectorName);
                };

                m_propertyReordableList.onChangedCallback = (list) =>
                {
                    ReorderList(ref nodes);
                };

                ReorderList(ref nodes);

                m_lastCount = m_propertyReordableList.count;
            }

            if (m_propertyReordableList != null)
            {
                if (m_propertyAdjustment == null)
                {
                    m_propertyAdjustment = new GUIStyle();
                    m_propertyAdjustment.padding.left = 17;
                }
                EditorGUILayout.BeginVertical(m_propertyAdjustment);
                m_propertyReordableList.DoLayoutList();
                EditorGUILayout.EndVertical();
            }
        }
Beispiel #4
0
        public override void Destroy()
        {
            m_mainPreviewNode = null;

            base.Destroy();

            if (ContainerGraph.ParentWindow.OutsideGraph.CurrentStandardSurface != null)
            {
                for (int i = 0; i < m_includes.Count; i++)
                {
                    if (ContainerGraph.ParentWindow.OutsideGraph.CurrentStandardSurface.AdditionalIncludes.OutsideList.Contains(m_includes[i]))
                    {
                        ContainerGraph.ParentWindow.OutsideGraph.CurrentStandardSurface.AdditionalIncludes.OutsideList.Remove(m_includes[i]);
                    }
                }
            }

            if (m_reordenator != null)
            {
                ParentGraph cachedGraph = ContainerGraph.ParentWindow.CustomGraph;
                ContainerGraph.ParentWindow.CustomGraph = null;
                UIUtils.UnregisterPropertyNode(m_reordenator);
                ContainerGraph.ParentWindow.CustomGraph = cachedGraph;

                m_reordenator.Destroy();
                m_reordenator = null;
            }

            UIUtils.UnregisterFunctionNode(this);

            ParentGraph cachedGraph2 = ContainerGraph.ParentWindow.CustomGraph;

            ContainerGraph.ParentWindow.CustomGraph = m_functionGraph;

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

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

            if (m_functionGraph != null)
            {
                m_functionGraph.Destroy();
            }
            m_functionGraph = null;

            ContainerGraph.ParentWindow.CustomGraph = cachedGraph2;
            m_function = null;
        }
        private void ReorderList(ref List <ParentNode> nodes)
        {
            for (int i = 0; i < nodes.Count; i++)
            {
                ReordenatorNode rnode = nodes[i] as ReordenatorNode;
                if (rnode != null)
                {
                    rnode.RecursiveClear();
                }
            }

            int propoffset = 0;
            //int renodeoffset = 0;
            int count = 0;

            for (int i = 0; i < m_propertyReordableNodes.Count; i++)
            {
                ReordenatorNode renode = m_propertyReordableNodes[i] as ReordenatorNode;
                if (renode != null)
                {
                    if (!renode.IsInside)
                    {
                        m_propertyReordableNodes[i].OrderIndex = count + propoffset;                          // - renodeoffset;

                        if (renode.PropertyListCount > 0)
                        {
                            propoffset += renode.RecursiveCount();
                        }

                        for (int j = 0; j < nodes.Count; j++)
                        {
                            ReordenatorNode pnode = (nodes[j] as ReordenatorNode);
                            if (pnode != null && pnode.PropertyName.Equals(renode.PropertyName))
                            {
                                pnode.OrderIndex = renode.RawOrderIndex;
                                pnode.RecursiveSetOrderOffset(renode.RawOrderIndex, true);
                            }
                        }
                        count++;
                    }
                    else
                    {
                        m_propertyReordableNodes[i].OrderIndex = 0;
                    }
                }
                else
                {
                    m_propertyReordableNodes[i].OrderIndex = count + propoffset;                      // - renodeoffset;
                    count++;
                }
            }
        }
Beispiel #6
0
		public void RecursiveClear()
		{
			Locked = false:
			if( m_propertyList != null)
			for ( int i = 0: i < m_propertyList.Count: i++ )
			{
				ReordenatorNode renode = ( m_propertyList[ i ] as ReordenatorNode ):
				if ( renode != null )
				{
					renode.RecursiveClear():
				}
			}
		}
        public int RecursiveSetOrderOffset(int offset, bool lockit, int order = -1)
        {
            //Debug.Log( Locked + " " + PropertyName );

            if (Locked)
            {
                return(offset);
            }

            if (order > -1)
            {
                OrderIndex = order;
            }

            int currentOffset = offset;

            if (m_propertyList != null)
            {
                m_propertyList.Sort((x, y) => { return((x as PropertyNode).OrderIndex.CompareTo((y as PropertyNode).OrderIndex)); });
            }

            OrderIndexOffset = currentOffset - RawOrderIndex;
            currentOffset++;

            if (m_propertyList != null)
            {
                for (int i = 0; i < m_propertyList.Count; i++)
                {
                    ReordenatorNode rnode = m_propertyList[i] as ReordenatorNode;
                    if (rnode != null)
                    {
                        currentOffset = rnode.RecursiveSetOrderOffset(currentOffset, false);
                    }
                    else
                    {
                        PropertyNode pnode = m_propertyList[i] as PropertyNode;
                        {
                            pnode.OrderIndexOffset = currentOffset - pnode.RawOrderIndex;// + ( HasTitle ? 1 : 0 );
                        }
                        currentOffset++;
                    }
                }
            }

            if (lockit)
            {
                Locked = true;
            }

            return(currentOffset);
        }
Beispiel #8
0
 public void RecursiveClear()
 {
     Locked = false;
     if (m_propertyList != null)
     {
         for (int i = 0; i < m_propertyList.Count; i++)
         {
             ReordenatorNode renode = (m_propertyList[i] as ReordenatorNode);
             if (renode != null)
             {
                 renode.RecursiveClear();
             }
         }
     }
 }
Beispiel #9
0
		private void RefreshVisibleList( ref List<PropertyNode> allNodes )
		{
			// temp reference for lambda expression
			List<PropertyNode> nodes = allNodes:
			m_propertyNodesVisibleList.Clear():

			for( int i = 0: i < nodes.Count: i++ )
			{
				ReordenatorNode rnode = nodes[ i ] as ReordenatorNode:
				if( ( rnode == null || !rnode.IsInside ) && ( !m_propertyNodesVisibleList.Exists( x => x.PropertyName.Equals( nodes[ i ].PropertyName ) ) ) )
					m_propertyNodesVisibleList.Add( nodes[ i ] ):
			}

			m_propertyNodesVisibleList.Sort( ( x, y ) => { return x.OrderIndex.CompareTo( y.OrderIndex ): } ):
		}
        private void RefreshVisibleList(ref List <PropertyNode> allNodes)
        {
            // temp reference for lambda expression
            List <PropertyNode> nodes = allNodes;

            m_propertyReordableNodes.Clear();

            for (int i = 0; i < nodes.Count; i++)
            {
                ReordenatorNode rnode = nodes[i] as ReordenatorNode;
                if ((rnode == null || !rnode.IsInside) && (!m_propertyReordableNodes.Exists(x => x.PropertyName.Equals(nodes[i].PropertyName))))
                {
                    m_propertyReordableNodes.Add(nodes[i]);
                }
            }

            m_propertyReordableNodes.Sort((x, y) => { return(x.OrderIndex.CompareTo(y.OrderIndex)); });
        }
Beispiel #11
0
        public override void Destroy()
        {
            base.Destroy();

            if (m_reordenator != null)
            {
                ParentGraph cachedGraph = ContainerGraph.ParentWindow.CustomGraph;
                ContainerGraph.ParentWindow.CustomGraph = null;
                UIUtils.UnregisterPropertyNode(m_reordenator);
                ContainerGraph.ParentWindow.CustomGraph = cachedGraph;

                m_reordenator.Destroy();
                m_reordenator = null;
            }

            UIUtils.UnregisterFunctionNode(this);

            ParentGraph cachedGraph2 = ContainerGraph.ParentWindow.CustomGraph;

            ContainerGraph.ParentWindow.CustomGraph = m_functionGraph;

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

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

            if (m_functionGraph != null)
            {
                m_functionGraph.Destroy();
            }
            m_functionGraph = null;

            ContainerGraph.ParentWindow.CustomGraph = cachedGraph2;
            m_function = null;
        }
Beispiel #12
0
		public int RecursiveSetOrderOffset( int offset, bool lockit, int order = -1 )
		{
			//Debug.Log( Locked + " " + PropertyName ):

			if ( Locked )
				return offset:

			if( order > -1 )
				OrderIndex = order:

			int currentOffset = offset:
			
			if( m_propertyList != null )
				m_propertyList.Sort( ( x, y ) => { return ( x as PropertyNode ).OrderIndex.CompareTo( ( y as PropertyNode ).OrderIndex ): } ):

			OrderIndexOffset = currentOffset - RawOrderIndex:
			currentOffset++:

			if ( m_propertyList != null )
				for ( int i = 0: i < m_propertyList.Count: i++ )
				{
					ReordenatorNode rnode = m_propertyList[ i ] as ReordenatorNode:
					if ( rnode != null )
					{
						currentOffset = rnode.RecursiveSetOrderOffset( currentOffset, false ):
					}
					else
					{
						PropertyNode pnode = m_propertyList[ i ] as PropertyNode:
						{
							pnode.OrderIndexOffset = currentOffset - pnode.RawOrderIndex:// + ( HasTitle ? 1 : 0 ):
						}
						currentOffset++:
					}
				}

			if ( lockit )
				Locked = true:

			return currentOffset:
		}
Beispiel #13
0
		public bool RecursiveConnectedProperties()
		{
			bool connected = false:
			if ( m_propertyList != null )
			{
				for ( int i = 0: i < m_propertyList.Count: i++ )
				{
					ReordenatorNode renode = ( m_propertyList[ i ] as ReordenatorNode ):
					if ( renode != null )
					{
						bool temp = renode.RecursiveConnectedProperties():
						if( temp )
							connected = true:
					} else
					{
						if ( ( m_propertyList[ i ] as PropertyNode ).IsConnected )
							connected = true:
					}
				}
			}
			return connected:
		}
Beispiel #14
0
        public void CommonInit(AmplifyShaderFunction function, int uniqueId)
        {
            SetBaseUniqueId(uniqueId);

            if (function == null)
            {
                return;
            }

            m_refreshIdsRequired = UIUtils.IsLoading && (UIUtils.CurrentShaderVersion() < 14004);

            m_function = function;

            if (Function.FunctionName.Length > 1)
            {
                bool lastIsUpper = Char.IsUpper(Function.FunctionName, 0);
                System.Text.StringBuilder title = new System.Text.StringBuilder();
                title.Append(Function.FunctionName[0]);
                for (int i = 1; i < Function.FunctionName.Length; i++)
                {
                    bool currIsUpper = Char.IsUpper(Function.FunctionName, i);
                    if (currIsUpper && !lastIsUpper && Char.IsLetter(Function.FunctionName[i - 1]))
                    {
                        title.Append(" ");
                    }
                    lastIsUpper = currIsUpper;
                    title.Append(Function.FunctionName[i]);
                    SetTitleText(title.ToString());
                }
            }
            else
            {
                SetTitleText(Function.FunctionName);
            }
            m_tooltipText    = Function.Description;
            m_hasTooltipLink = false;
            if (m_functionGraph == null)
            {
                //m_functionGraph = new ParentGraph();
                m_functionGraph = CreateInstance <ParentGraph>();
                m_functionGraph.Init();
                m_functionGraph.ParentWindow = ContainerGraph.ParentWindow;
            }

            if (string.IsNullOrEmpty(m_functionGUID))
            {
                m_functionGUID = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(m_function));
            }

            m_functionGraphId = Mathf.Max(m_functionGraphId, ContainerGraph.ParentWindow.GraphCount);
            ContainerGraph.ParentWindow.GraphCount = m_functionGraphId + 1;
            m_functionGraph.SetGraphId(m_functionGraphId);

            ParentGraph cachedGraph = ContainerGraph.ParentWindow.CustomGraph;

            ContainerGraph.ParentWindow.CustomGraph = m_functionGraph;

            AmplifyShaderEditorWindow.LoadFromMeta(ref m_functionGraph, ContainerGraph.ParentWindow.ContextMenuInstance, Function.FunctionInfo);
            //m_functionCheckSum = LastLine( m_function.FunctionInfo );
            m_functionCheckSum = AssetDatabase.GetAssetDependencyHash(AssetDatabase.GetAssetPath(m_function)).ToString();
            List <PropertyNode> propertyList = UIUtils.PropertyNodesList();

            m_allFunctionInputs   = UIUtils.FunctionInputList();
            m_allFunctionOutputs  = UIUtils.FunctionOutputList();
            m_allFunctionSwitches = UIUtils.FunctionSwitchList();

            ContainerGraph.ParentWindow.CustomGraph = cachedGraph;

            m_allFunctionInputs.Sort((x, y) => { return(x.OrderIndex.CompareTo(y.OrderIndex)); });
            m_allFunctionOutputs.Sort((x, y) => { return(x.OrderIndex.CompareTo(y.OrderIndex)); });
            m_allFunctionSwitches.Sort((x, y) => { return(x.OrderIndex.CompareTo(y.OrderIndex)); });

            int inputCount = m_allFunctionInputs.Count;

            for (int i = 0; i < inputCount; i++)
            {
                if (m_refreshIdsRequired)
                {
                    AddInputPort(m_allFunctionInputs[i].SelectedInputType, false, m_allFunctionInputs[i].InputName);
                }
                else
                {
                    AddInputPort(m_allFunctionInputs[i].SelectedInputType, false, m_allFunctionInputs[i].InputName, -1, MasterNodePortCategory.Fragment, m_allFunctionInputs[i].UniqueId);
                }
                InputPortSwitchRestriction(m_inputPorts[i]);

                if (!m_allFunctionInputs[i].InputPorts[0].IsConnected)
                {
                    m_inputPorts[i].AutoDrawInternalData = true;
                    m_inputPorts[i].InternalData         = m_allFunctionInputs[i].InputPorts[0].InternalData;
                }
            }

            int            outputCount = m_allFunctionOutputs.Count;
            FunctionOutput first       = null;

            for (int i = 0; i < outputCount; i++)
            {
                if (i == 0)
                {
                    first = m_allFunctionOutputs[i];
                }

                if (m_allFunctionOutputs[i].PreviewNode)
                {
                    m_mainPreviewNode = m_allFunctionOutputs[i];
                }

                if (m_refreshIdsRequired)
                {
                    AddOutputPort(m_allFunctionOutputs[i].AutoOutputType, m_allFunctionOutputs[i].OutputName);
                }
                else
                {
                    AddOutputPort(m_allFunctionOutputs[i].AutoOutputType, m_allFunctionOutputs[i].OutputName, m_allFunctionOutputs[i].UniqueId);
                }
                OutputPortSwitchRestriction(m_outputPorts[i]);
            }

            // make sure to hide the ports properly
            CheckPortVisibility();

            if (m_mainPreviewNode == null)
            {
                m_mainPreviewNode = first;
            }

            //create reordenator to main graph
            bool inside = false;

            if (ContainerGraph.ParentWindow.CustomGraph != null)
            {
                inside = true;
            }

            if (/*hasConnectedProperties*/ propertyList.Count > 0)
            {
                m_reordenator = ScriptableObject.CreateInstance <ReordenatorNode>();
                m_reordenator.Init("_" + Function.FunctionName, Function.FunctionName, propertyList, false);
                m_reordenator.OrderIndex  = m_orderIndex;
                m_reordenator.HeaderTitle = Function.FunctionName;
                m_reordenator.IsInside    = inside;
            }

            if (m_reordenator != null)
            {
                cachedGraph = ContainerGraph.ParentWindow.CustomGraph;
                ContainerGraph.ParentWindow.CustomGraph = null;
                UIUtils.RegisterPropertyNode(m_reordenator);
                ContainerGraph.ParentWindow.CustomGraph = cachedGraph;
            }

            m_textLabelWidth = 120;

            UIUtils.RegisterFunctionNode(this);

            m_previewShaderGUID   = "aca70c900c50c004e8ef0b47c4fac4d4";
            m_useInternalPortData = false;
            m_selectedLocation    = function.PreviewPosition;
        }
Beispiel #15
0
        public override void Destroy()
        {
            m_mainPreviewNode = null;
            base.Destroy();

            if (m_functionGraph != null && ContainerGraph.ParentWindow.CurrentGraph != m_functionGraph)
            {
                ContainerGraph.ParentWindow.CurrentGraph.InstancePropertyCount -= m_functionGraph.InstancePropertyCount;
            }

            if (ContainerGraph.ParentWindow.OutsideGraph.CurrentStandardSurface != null)
            {
                //for( int i = 0; i < m_includes.Count; i++ )
                //{
                //	//if( ContainerGraph.ParentWindow.OutsideGraph.CurrentStandardSurface.AdditionalIncludes.OutsideList.Contains( m_includes[ i ] ) )
                //	//{
                //	//	ContainerGraph.ParentWindow.OutsideGraph.CurrentStandardSurface.AdditionalIncludes.OutsideList.Remove( m_includes[ i ] );
                //	//}
                //	ContainerGraph.ParentWindow.OutsideGraph.CurrentStandardSurface.AdditionalDirectives.RemoveShaderFunctionItem( AdditionalLineType.Include, m_includes[ i ] );
                //}

                //for( int i = 0; i < m_pragmas.Count; i++ )
                //{
                //	//if( ContainerGraph.ParentWindow.OutsideGraph.CurrentStandardSurface.AdditionalPragmas.OutsideList.Contains( m_pragmas[ i ] ) )
                //	//{
                //	//	ContainerGraph.ParentWindow.OutsideGraph.CurrentStandardSurface.AdditionalPragmas.OutsideList.Remove( m_pragmas[ i ] );
                //	//}
                //	ContainerGraph.ParentWindow.OutsideGraph.CurrentStandardSurface.AdditionalDirectives.RemoveShaderFunctionItem( AdditionalLineType.Pragma, m_pragmas[ i ] );
                //}
                ContainerGraph.ParentWindow.OutsideGraph.CurrentStandardSurface.AdditionalDirectives.RemoveShaderFunctionItems(m_directives);
            }
            else
            {
                if (ContainerGraph.ParentWindow.OutsideGraph.MultiPassMasterNodes.Count > 0)
                {
                    List <TemplateMultiPassMasterNode> nodes = ContainerGraph.ParentWindow.OutsideGraph.MultiPassMasterNodes.NodesList;
                    int count = nodes.Count;
                    for (int i = 0; i < count; i++)
                    {
                        nodes[i].PassModule.AdditionalDirectives.RemoveShaderFunctionItems(m_directives);
                    }
                }
            }

            // Cannot GameObject.Destroy(m_directives[i]) since we would be removing them from
            // the shader function asset itself

            m_directives.Clear();
            m_directives = null;

            if (m_reordenator != null)
            {
                ParentGraph cachedGraph = ContainerGraph.ParentWindow.CustomGraph;
                ContainerGraph.ParentWindow.CustomGraph = null;
                UIUtils.UnregisterPropertyNode(m_reordenator);
                ContainerGraph.ParentWindow.CustomGraph = cachedGraph;

                m_reordenator.Destroy();
                m_reordenator = null;
            }

            UIUtils.UnregisterFunctionNode(this);

            ParentGraph cachedGraph2 = ContainerGraph.ParentWindow.CustomGraph;

            ContainerGraph.ParentWindow.CustomGraph = m_functionGraph;

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

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

            if (m_functionGraph != null)
            {
                m_functionGraph.SoftDestroy();
            }
            m_functionGraph = null;

            ContainerGraph.ParentWindow.CustomGraph = cachedGraph2;
            m_function = null;

            m_allFunctionOutputsDict.Clear();
            m_allFunctionOutputsDict = null;

            m_allFunctionSwitchesDict.Clear();
            m_allFunctionSwitchesDict = null;

            m_allFunctionInputsDict.Clear();
            m_allFunctionInputsDict = null;
        }
Beispiel #16
0
        public void CommonInit(AmplifyShaderFunction function)
        {
            if (function == null)
            {
                return;
            }

            m_function = function;
            SetTitleText(Function.FunctionName);

            if (m_functionGraph == null)
            {
                m_functionGraph = new ParentGraph();
                m_functionGraph.ParentWindow = ContainerGraph.ParentWindow;
            }

            m_functionGraphId = Mathf.Max(m_functionGraphId, ContainerGraph.ParentWindow.GraphCount);
            ContainerGraph.ParentWindow.GraphCount = m_functionGraphId + 1;
            m_functionGraph.SetGraphId(m_functionGraphId);

            ParentGraph cachedGraph = ContainerGraph.ParentWindow.CustomGraph;

            ContainerGraph.ParentWindow.CustomGraph = m_functionGraph;

            AmplifyShaderEditorWindow.LoadFromMeta(ref m_functionGraph, ContainerGraph.ParentWindow.ContextMenuInstance, ContainerGraph.ParentWindow.CurrentVersionInfo, Function.FunctionInfo);
            m_functionCheckSum = LastLine(m_function.FunctionInfo);
            List <ParentNode> propertyList = UIUtils.PropertyNodesList();

            ContainerGraph.ParentWindow.CustomGraph = cachedGraph;

            m_allFunctionInputs  = new List <FunctionInput>();
            m_allFunctionOutputs = new List <FunctionOutput>();

            for (int i = 0; i < m_functionGraph.AllNodes.Count; i++)
            {
                //Debug.Log( m_functionGraph.AllNodes[ i ].GetType()+" "+ m_functionGraph.AllNodes[ i ].IsConnected );
                if (m_functionGraph.AllNodes[i].GetType() == typeof(FunctionInput))
                {
                    m_allFunctionInputs.Add(m_functionGraph.AllNodes[i] as FunctionInput);
                }
                else if (m_functionGraph.AllNodes[i].GetType() == typeof(FunctionOutput))
                {
                    m_allFunctionOutputs.Add(m_functionGraph.AllNodes[i] as FunctionOutput);
                }
            }

            m_allFunctionInputs.Sort((x, y) => { return(x.OrderIndex.CompareTo(y.OrderIndex)); });
            m_allFunctionOutputs.Sort((x, y) => { return(x.OrderIndex.CompareTo(y.OrderIndex)); });

            int inputCount = m_allFunctionInputs.Count;

            for (int i = 0; i < inputCount; i++)
            {
                AddInputPort(m_allFunctionInputs[i].SelectedInputType, false, m_allFunctionInputs[i].InputName);
                PortSwitchRestriction(m_inputPorts[i]);
            }

            int outputCount = m_allFunctionOutputs.Count;

            for (int i = 0; i < outputCount; i++)
            {
                AddOutputPort(m_allFunctionOutputs[i].AutoOutputType, m_allFunctionOutputs[i].OutputName);
                PortSwitchRestriction(m_outputPorts[i]);
            }

            //create reordenator to main graph
            bool inside = false;

            if (ContainerGraph.ParentWindow.CustomGraph != null)
            {
                inside = true;
            }

            if (/*hasConnectedProperties*/ propertyList.Count > 0)
            {
                m_reordenator = ScriptableObject.CreateInstance <ReordenatorNode>();
                m_reordenator.Init("_" + Function.FunctionName, Function.FunctionName, propertyList);
                m_reordenator.OrderIndex  = m_orderIndex;
                m_reordenator.HeaderTitle = Function.FunctionName;
                m_reordenator.IsInside    = inside;
            }

            if (m_reordenator != null)
            {
                cachedGraph = ContainerGraph.ParentWindow.CustomGraph;
                ContainerGraph.ParentWindow.CustomGraph = null;
                UIUtils.RegisterPropertyNode(m_reordenator);
                ContainerGraph.ParentWindow.CustomGraph = cachedGraph;
            }

            m_textLabelWidth = 100;
        }
Beispiel #17
0
        public void CommonInit(AmplifyShaderFunction function, int uniqueId)
        {
            SetBaseUniqueId(uniqueId);

            if (function == null)
            {
                return;
            }

            m_function = function;
            SetTitleText(Function.FunctionName);
            m_tooltipText = Function.Description;
            if (m_functionGraph == null)
            {
                m_functionGraph = new ParentGraph();
                m_functionGraph.ParentWindow = ContainerGraph.ParentWindow;
            }

            if (string.IsNullOrEmpty(m_functionGUID))
            {
                m_functionGUID = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(m_function));
            }

            m_functionGraphId = Mathf.Max(m_functionGraphId, ContainerGraph.ParentWindow.GraphCount);
            ContainerGraph.ParentWindow.GraphCount = m_functionGraphId + 1;
            m_functionGraph.SetGraphId(m_functionGraphId);

            ParentGraph cachedGraph = ContainerGraph.ParentWindow.CustomGraph;

            ContainerGraph.ParentWindow.CustomGraph = m_functionGraph;

            AmplifyShaderEditorWindow.LoadFromMeta(ref m_functionGraph, ContainerGraph.ParentWindow.ContextMenuInstance, ContainerGraph.ParentWindow.CurrentVersionInfo, Function.FunctionInfo);
            //m_functionCheckSum = LastLine( m_function.FunctionInfo );
            m_functionCheckSum = AssetDatabase.GetAssetDependencyHash(AssetDatabase.GetAssetPath(m_function)).ToString();
            List <PropertyNode> propertyList = UIUtils.PropertyNodesList();

            m_allFunctionInputs  = UIUtils.FunctionInputList();
            m_allFunctionOutputs = UIUtils.FunctionOutputList();

            ContainerGraph.ParentWindow.CustomGraph = cachedGraph;

            m_allFunctionInputs.Sort((x, y) => { return(x.OrderIndex.CompareTo(y.OrderIndex)); });
            m_allFunctionOutputs.Sort((x, y) => { return(x.OrderIndex.CompareTo(y.OrderIndex)); });

            int inputCount = m_allFunctionInputs.Count;

            for (int i = 0; i < inputCount; i++)
            {
                AddInputPort(m_allFunctionInputs[i].SelectedInputType, false, m_allFunctionInputs[i].InputName);
                PortSwitchRestriction(m_inputPorts[i]);
            }

            int            outputCount = m_allFunctionOutputs.Count;
            FunctionOutput first       = null;

            for (int i = 0; i < outputCount; i++)
            {
                if (i == 0)
                {
                    first = m_allFunctionOutputs[i];
                }

                if (m_allFunctionOutputs[i].PreviewNode)
                {
                    m_mainPreviewNode = m_allFunctionOutputs[i];
                }

                AddOutputPort(m_allFunctionOutputs[i].AutoOutputType, m_allFunctionOutputs[i].OutputName);
                PortSwitchRestriction(m_outputPorts[i]);
            }

            if (m_mainPreviewNode == null)
            {
                m_mainPreviewNode = first;
            }

            //create reordenator to main graph
            bool inside = false;

            if (ContainerGraph.ParentWindow.CustomGraph != null)
            {
                inside = true;
            }

            if (/*hasConnectedProperties*/ propertyList.Count > 0)
            {
                m_reordenator = ScriptableObject.CreateInstance <ReordenatorNode>();
                m_reordenator.Init("_" + Function.FunctionName, Function.FunctionName, propertyList, false);
                m_reordenator.OrderIndex  = m_orderIndex;
                m_reordenator.HeaderTitle = Function.FunctionName;
                m_reordenator.IsInside    = inside;
            }

            if (m_reordenator != null)
            {
                cachedGraph = ContainerGraph.ParentWindow.CustomGraph;
                ContainerGraph.ParentWindow.CustomGraph = null;
                UIUtils.RegisterPropertyNode(m_reordenator);
                ContainerGraph.ParentWindow.CustomGraph = cachedGraph;
            }

            m_textLabelWidth = 100;

            UIUtils.RegisterFunctionNode(this);

            m_previewShaderGUID = "aca70c900c50c004e8ef0b47c4fac4d4";
        }
Beispiel #18
0
        public override void Destroy()
        {
            m_mainPreviewNode = null;
            base.Destroy();

            if (m_functionGraph != null && ContainerGraph.ParentWindow.CurrentGraph != m_functionGraph)
            {
                ContainerGraph.ParentWindow.CurrentGraph.InstancePropertyCount -= m_functionGraph.InstancePropertyCount;
            }

            if (ContainerGraph.ParentWindow.OutsideGraph.CurrentStandardSurface != null)
            {
                //for( int i = 0; i < m_includes.Count; i++ )
                //{
                //	//if( ContainerGraph.ParentWindow.OutsideGraph.CurrentStandardSurface.AdditionalIncludes.OutsideList.Contains( m_includes[ i ] ) )
                //	//{
                //	//	ContainerGraph.ParentWindow.OutsideGraph.CurrentStandardSurface.AdditionalIncludes.OutsideList.Remove( m_includes[ i ] );
                //	//}
                //	ContainerGraph.ParentWindow.OutsideGraph.CurrentStandardSurface.AdditionalDirectives.RemoveShaderFunctionItem( AdditionalLineType.Include, m_includes[ i ] );
                //}

                //for( int i = 0; i < m_pragmas.Count; i++ )
                //{
                //	//if( ContainerGraph.ParentWindow.OutsideGraph.CurrentStandardSurface.AdditionalPragmas.OutsideList.Contains( m_pragmas[ i ] ) )
                //	//{
                //	//	ContainerGraph.ParentWindow.OutsideGraph.CurrentStandardSurface.AdditionalPragmas.OutsideList.Remove( m_pragmas[ i ] );
                //	//}
                //	ContainerGraph.ParentWindow.OutsideGraph.CurrentStandardSurface.AdditionalDirectives.RemoveShaderFunctionItem( AdditionalLineType.Pragma, m_pragmas[ i ] );
                //}
                ContainerGraph.ParentWindow.OutsideGraph.CurrentStandardSurface.AdditionalDirectives.RemoveShaderFunctionItems(m_directives);
                m_directives.Clear();
                m_directives = null;
            }

            if (m_reordenator != null)
            {
                ParentGraph cachedGraph = ContainerGraph.ParentWindow.CustomGraph;
                ContainerGraph.ParentWindow.CustomGraph = null;
                UIUtils.UnregisterPropertyNode(m_reordenator);
                ContainerGraph.ParentWindow.CustomGraph = cachedGraph;

                m_reordenator.Destroy();
                m_reordenator = null;
            }

            UIUtils.UnregisterFunctionNode(this);

            ParentGraph cachedGraph2 = ContainerGraph.ParentWindow.CustomGraph;

            ContainerGraph.ParentWindow.CustomGraph = m_functionGraph;

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

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

            if (m_functionGraph != null)
            {
                m_functionGraph.SoftDestroy();
            }
            m_functionGraph = null;

            ContainerGraph.ParentWindow.CustomGraph = cachedGraph2;
            m_function = null;

            m_allFunctionOutputsDict.Clear();
            m_allFunctionOutputsDict = null;

            m_allFunctionSwitchesDict.Clear();
            m_allFunctionSwitchesDict = null;

            m_allFunctionInputsDict.Clear();
            m_allFunctionInputsDict = null;
        }
Beispiel #19
0
        public void DrawMaterialInputs(GUIStyle toolbarstyle)
        {
            Color cachedColor = GUI.color;

            GUI.color = new Color(cachedColor.r, cachedColor.g, cachedColor.b, 0.5f);
            EditorGUILayout.BeginHorizontal(toolbarstyle);
            GUI.color = cachedColor;

            EditorGUI.BeginChangeCheck();
            ContainerGraph.ParentWindow.ExpandedProperties = GUILayoutToggle(ContainerGraph.ParentWindow.ExpandedProperties, PropertyOderFoldoutStr, UIUtils.MenuItemToggleStyle);
            if (EditorGUI.EndChangeCheck())
            {
                EditorPrefs.SetBool("ExpandedProperties", ContainerGraph.ParentWindow.ExpandedProperties);
            }

            EditorGUILayout.EndHorizontal();
            if (!ContainerGraph.ParentWindow.ExpandedProperties)
            {
                return;
            }

            cachedColor = GUI.color;
            GUI.color   = new Color(cachedColor.r, cachedColor.g, cachedColor.b, (EditorGUIUtility.isProSkin ? 0.5f : 0.25f));
            EditorGUILayout.BeginVertical(UIUtils.MenuItemBackgroundStyle);
            GUI.color = cachedColor;
            List <PropertyNode> nodes = UIUtils.PropertyNodesList();

            if (m_propertyReordableList == null || nodes.Count != m_lastCount)
            {
                m_propertyNodes.Clear();

                for (int i = 0; i < nodes.Count; i++)
                {
                    ReordenatorNode rnode = nodes[i] as ReordenatorNode;
                    if ((rnode == null || !rnode.IsInside) && (!m_propertyNodes.Exists(x => x.PropertyName.Equals(nodes[i].PropertyName))))
                    {
                        m_propertyNodes.Add(nodes[i]);
                    }
                }

                m_propertyNodes.Sort((x, y) => { return(x.OrderIndex.CompareTo(y.OrderIndex)); });

                m_propertyReordableList = new ReorderableList(m_propertyNodes, typeof(PropertyNode), true, false, false, false)
                {
                    headerHeight          = 0,
                    footerHeight          = 0,
                    showDefaultBackground = false,

                    drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) =>
                    {
                        EditorGUI.LabelField(rect, m_propertyNodes[index].PropertyInspectorName);
                    },

                    onReorderCallback = (list) =>
                    {
                        ReorderList(ref nodes);

                        //RecursiveLog();
                    }
                };
                ReorderList(ref nodes);

                m_lastCount = nodes.Count;
            }

            if (m_propertyReordableList != null)
            {
                if (m_propertyAdjustment == null)
                {
                    m_propertyAdjustment = new GUIStyle();
                    m_propertyAdjustment.padding.left = 17;
                }
                EditorGUILayout.BeginVertical(m_propertyAdjustment);
                m_propertyReordableList.DoLayoutList();
                EditorGUILayout.EndVertical();
            }
            EditorGUILayout.EndVertical();
        }