コード例 #1
0
ファイル: TemplatePass.cs プロジェクト: EGSP/Flappy-Bird
        public TemplatePass(TemplateSubShader subShader, int subshaderIdx, int passIdx, TemplateIdManager idManager, string uniquePrefix, int offsetIdx, TemplatePassInfo passInfo, ref Dictionary <string, TemplateShaderPropertyData> duplicatesHelper)
        {
            m_idx = passIdx;

            m_uniquePrefix = uniquePrefix;
            idManager.RegisterPassId(passInfo.Data);
            m_isMainPass = passInfo.Data.Contains(TemplatesManager.TemplateMainPassTag);
            if (!m_isMainPass)
            {
                string id      = string.Empty;
                int    idIndex = 0;
                m_isInvisible = TemplateHelperFunctions.FetchInvisibleInfo(passInfo.Data, ref m_invisibleOptions, ref id, ref idIndex);
                if (m_isInvisible)
                {
                    idManager.RegisterId(idIndex, uniquePrefix + id, id, true);
                }
            }

            FetchPassName(offsetIdx, passInfo.Data);
            if (m_passNameContainer.Index > -1)
            {
                idManager.RegisterId(m_passNameContainer.Index, uniquePrefix + m_passNameContainer.Id, m_passNameContainer.Id);
            }
            else
            {
                m_passNameContainer.Data = string.Format(DefaultPassNameStr, subshaderIdx, passIdx);
            }

#if CUSTOM_OPTIONS_AVAILABLE
            m_customOptionsContainer = TemplateOptionsToolsHelper.GenerateOptionsContainer(false, passInfo.Data);
            if (m_customOptionsContainer.Enabled)
            {
                idManager.RegisterId(m_customOptionsContainer.Index, uniquePrefix + m_customOptionsContainer.Body, m_customOptionsContainer.Body, true);
            }
            //m_customOptionsContainer.CopyPortOptionsFrom( subShader.CustomOptionsContainer, m_passNameContainer.Data );
#endif
            m_modules = new TemplateModulesData(m_customOptionsContainer, idManager, m_templateProperties, uniquePrefix + "Module", offsetIdx, passInfo.Data, false);

            if (!m_modules.PassTag.IsValid)
            {
                m_modules.PassTag.StartIdx = passInfo.GlobalStartIdx;
                m_templateProperties.AddId(passInfo.Data, m_modules.PassTag.Id, passInfo.LocalStartIdx, false);
                //m_modules.PassTag.StartIdx -= m_templateProperties.PropertyDict[ m_modules.PassTag.Id ].Indentation.Length;
                //m_templateProperties.PropertyDict[ m_modules.PassTag.Id ].UseIndentationAtStart = false;
                idManager.RegisterId(m_modules.PassTag.StartIdx, m_modules.UniquePrefix + m_modules.PassTag.Id, string.Empty);
            }
            m_modules.SetPassUniqueNameIfUndefined(m_passNameContainer.Data);

            m_modules.SRPType = subShader.Modules.SRPType;
            if (m_modules.SRPType == TemplateSRPType.HD)
            {
                m_modules.SRPIsPBR = passInfo.Data.Contains(TemplateHelperFunctions.HDPBRTag);
            }

            Dictionary <string, TemplateShaderPropertyData> ownDuplicatesDict = new Dictionary <string, TemplateShaderPropertyData>(duplicatesHelper);
            TemplateHelperFunctions.CreateShaderGlobalsList(passInfo.Data, ref m_availableShaderGlobals, ref ownDuplicatesDict);

            // Vertex and Interpolator data
            FetchVertexAndInterpData(subShader.Modules, offsetIdx, passInfo.Data);
            if (m_vertexDataContainer != null)
            {
                idManager.RegisterId(m_vertexDataContainer.VertexDataStartIdx, uniquePrefix + m_vertexDataContainer.VertexDataId, m_vertexDataContainer.VertexDataId);
            }

            if (m_interpolatorDataContainer != null)
            {
                idManager.RegisterId(m_interpolatorDataContainer.InterpDataStartIdx, uniquePrefix + m_interpolatorDataContainer.InterpDataId, m_interpolatorDataContainer.InterpDataId);
            }

            //Fetch function code areas
            FetchCodeAreas(offsetIdx, TemplatesManager.TemplateVertexCodeBeginArea, MasterNodePortCategory.Vertex, passInfo.Data);
            if (m_vertexFunctionData != null)
            {
                idManager.RegisterId(m_vertexFunctionData.Position, uniquePrefix + m_vertexFunctionData.Id, m_vertexFunctionData.Id);
            }

            FetchCodeAreas(offsetIdx, TemplatesManager.TemplateFragmentCodeBeginArea, MasterNodePortCategory.Fragment, passInfo.Data);
            if (m_fragmentFunctionData != null)
            {
                idManager.RegisterId(m_fragmentFunctionData.Position, uniquePrefix + m_fragmentFunctionData.Id, m_fragmentFunctionData.Id);
            }

            //Fetching inputs, must be do
            if (m_fragmentFunctionData != null)
            {
                FetchInputs(offsetIdx, MasterNodePortCategory.Fragment, passInfo.Data);
            }

            if (m_vertexFunctionData != null)
            {
                FetchInputs(offsetIdx, MasterNodePortCategory.Vertex, passInfo.Data);
            }

            //Fetch local variables must be done after fetching code areas as it needs them to see is variable is on vertex or fragment
            TemplateHelperFunctions.FetchLocalVars(passInfo.Data, ref m_localVarsList, m_vertexFunctionData, m_fragmentFunctionData);

            int localVarCount = m_localVarsList.Count;
            if (localVarCount > 0)
            {
                idManager.RegisterTag(TemplatesManager.TemplateLocalVarTag);
                for (int i = 0; i < localVarCount; i++)
                {
                    if (m_localVarsList[i].IsSpecialVar)
                    {
                        idManager.RegisterTag(m_localVarsList[i].Id);
                    }
                }
            }

            int inputsCount = m_inputDataList.Count;
            for (int i = 0; i < inputsCount; i++)
            {
                if (m_inputDataList[i] != null)
                {
                    idManager.RegisterId(m_inputDataList[i].TagGlobalStartIdx, uniquePrefix + m_inputDataList[i].TagId, m_inputDataList[i].TagId);
                }
            }

            //int passEndIndex = passInfo.Data.LastIndexOf( "}" );
            //if( passEndIndex > 0 )
            //{
            //	int identationIndex = -1;
            //	for( int i = passEndIndex; i >= 0; i-- )
            //	{
            //		if( passInfo.Data[ i ] == TemplatesManager.TemplateNewLine )
            //		{
            //			identationIndex = i + 1;
            //			break;
            //		}

            //		if( i == 0 )
            //		{
            //			identationIndex = 0;
            //		}
            //	}

            //	if( identationIndex > -1 )
            //	{
            //		int length = passEndIndex - identationIndex;
            //		string indentation = ( length > 0 ) ? passInfo.Data.Substring( identationIndex, length ) : string.Empty;
            //		TemplateProperty templateProperty = new TemplateProperty( TemplatesManager.TemplateEndPassTag, indentation, false );
            //		m_templateProperties.AddId( templateProperty );
            //		idManager.RegisterId( offsetIdx + passEndIndex, uniquePrefix + TemplatesManager.TemplateEndPassTag, string.Empty );
            //	}
            //}

            ownDuplicatesDict.Clear();
            ownDuplicatesDict = null;
        }
コード例 #2
0
        public void OnCustomOptionSelected(bool isRefreshing, bool invertAction, TemplateMultiPassMasterNode owner, TemplateOptionUIItem uiItem, params TemplateActionItem[] validActions)
        {
            uiItem.CheckOnExecute = false;
            for (int i = 0; i < validActions.Length; i++)
            {
                AseOptionsActionType actionType = validActions[i].ActionType;
                if (invertAction)
                {
                    if (!TemplateOptionsToolsHelper.InvertAction(validActions[i].ActionType, ref actionType))
                    {
                        continue;
                    }
                }

                switch (actionType)
                {
                case AseOptionsActionType.ShowOption:
                {
                    TemplateOptionUIItem item = m_passCustomOptionsUI.Find(x => (x.Options.Name.Equals(validActions[i].ActionData)));
                    if (item != null)
                    {
                        if (isRefreshing)
                        {
                            string optionId = validActions[i].PassName + validActions[i].ActionData + "Option";
                            owner.ContainerGraph.ParentWindow.TemplatesManagerInstance.SetOptionsValue(optionId, true);
                        }
                        item.IsVisible = true;
                        if (!invertAction && validActions[i].ActionDataIdx > -1)
                        {
                            item.CurrentOption = validActions[i].ActionDataIdx;
                        }
                    }
                    else
                    {
                        Debug.LogFormat("Could not find Option {0} for action {1}", validActions[i].ActionData, validActions[i].ActionType);
                    }
                }
                break;

                case AseOptionsActionType.HideOption:
                {
                    TemplateOptionUIItem item = m_passCustomOptionsUI.Find(x => (x.Options.Name.Equals(validActions[i].ActionData)));
                    if (item != null)
                    {
                        bool flag = false;
                        if (isRefreshing)
                        {
                            string optionId = validActions[i].PassName + validActions[i].ActionData + "Option";
                            flag = owner.ContainerGraph.ParentWindow.TemplatesManagerInstance.SetOptionsValue(optionId, false);
                        }

                        item.IsVisible = false || flag;
                        if (!invertAction && validActions[i].ActionDataIdx > -1)
                        {
                            item.CurrentOption = validActions[i].ActionDataIdx;
                        }
                    }
                    else
                    {
                        Debug.LogFormat("Could not find Option {0} for action {1}", validActions[i].ActionData, validActions[i].ActionType);
                    }
                }
                break;

                case AseOptionsActionType.SetOption:
                {
                    TemplateOptionUIItem item = m_passCustomOptionsUI.Find(x => (x.Options.Name.Equals(validActions[i].ActionData)));
                    if (item != null)
                    {
                        item.CurrentOption = validActions[i].ActionDataIdx;
                    }
                    else
                    {
                        Debug.LogFormat("Could not find Option {0} for action {1}", validActions[i].ActionData, validActions[i].ActionType);
                    }
                }
                break;

                case AseOptionsActionType.HidePort:
                {
                    TemplateMultiPassMasterNode passMasterNode = owner;
                    if (!string.IsNullOrEmpty(validActions[i].PassName))
                    {
                        passMasterNode = owner.ContainerGraph.GetMasterNodeOfPass(validActions[i].PassName);
                    }

                    if (passMasterNode != null)
                    {
                        InputPort port = validActions[i].ActionDataIdx > -1 ?
                                         passMasterNode.GetInputPortByUniqueId(validActions[i].ActionDataIdx) :
                                         passMasterNode.InputPorts.Find(x => x.Name.Equals(validActions[i].ActionData));
                        if (port != null)
                        {
                            bool flag = false;
                            if (isRefreshing)
                            {
                                string optionId = validActions[i].PassName + port.Name;
                                flag = owner.ContainerGraph.ParentWindow.TemplatesManagerInstance.SetOptionsValue(optionId, false || port.IsConnected);
                            }

                            port.Visible = false || flag;
                            passMasterNode.SizeIsDirty = true;
                        }
                        else
                        {
                            Debug.LogFormat("Could not find port {0},{1} for action {2}", validActions[i].ActionDataIdx, validActions[i].ActionData, validActions[i].ActionType);
                        }
                    }
                    else
                    {
                        Debug.LogFormat("Could not find pass {0} for action {1} on {2}", validActions[i].PassName, validActions[i].ActionType, validActions[i].ActionData);
                    }
                }
                break;

                case AseOptionsActionType.ShowPort:
                {
                    TemplateMultiPassMasterNode passMasterNode = owner;
                    if (!string.IsNullOrEmpty(validActions[i].PassName))
                    {
                        passMasterNode = owner.ContainerGraph.GetMasterNodeOfPass(validActions[i].PassName);
                    }

                    if (passMasterNode != null)
                    {
                        InputPort port = validActions[i].ActionDataIdx > -1 ?
                                         passMasterNode.GetInputPortByUniqueId(validActions[i].ActionDataIdx) :
                                         passMasterNode.InputPorts.Find(x => x.Name.Equals(validActions[i].ActionData));
                        if (port != null)
                        {
                            if (isRefreshing)
                            {
                                string optionId = validActions[i].PassName + port.Name;
                                owner.ContainerGraph.ParentWindow.TemplatesManagerInstance.SetOptionsValue(optionId, true);
                            }

                            port.Visible = true;
                            passMasterNode.SizeIsDirty = true;
                        }
                        else
                        {
                            Debug.LogFormat("Could not find port {0},{1} for action {2}", validActions[i].ActionDataIdx, validActions[i].ActionData, validActions[i].ActionType);
                        }
                    }
                    else
                    {
                        Debug.LogFormat("Could not find pass {0} for action {1} on {2}", validActions[i].PassName, validActions[i].ActionType, validActions[i].ActionData);
                    }
                }
                break;

                case AseOptionsActionType.SetPortName:
                {
                    TemplateMultiPassMasterNode passMasterNode = owner;
                    if (!string.IsNullOrEmpty(validActions[i].PassName))
                    {
                        passMasterNode = owner.ContainerGraph.GetMasterNodeOfPass(validActions[i].PassName);
                    }

                    if (passMasterNode != null)
                    {
                        InputPort port = passMasterNode.GetInputPortByUniqueId(validActions[i].ActionDataIdx);
                        if (port != null)
                        {
                            port.Name = validActions[i].ActionData;
                            passMasterNode.SizeIsDirty = true;
                        }
                        else
                        {
                            Debug.LogFormat("Could not find port {0},{1} for action {2}", validActions[i].ActionDataIdx, validActions[i].ActionData, validActions[i].ActionType);
                        }
                    }
                    else
                    {
                        Debug.LogFormat("Could not find pass {0} for action {1} on {2}", validActions[i].PassName, validActions[i].ActionType, validActions[i].ActionData);
                    }
                }
                break;

                case AseOptionsActionType.SetDefine:
                {
                    //Debug.Log( "DEFINE "+validActions[ i ].ActionData );
                    if (validActions[i].AllPasses)
                    {
                        string defineValue = "#define " + validActions[i].ActionData;
                        if (isRefreshing)
                        {
                            owner.ContainerGraph.ParentWindow.TemplatesManagerInstance.SetOptionsValue(defineValue, true);
                        }
                        List <TemplateMultiPassMasterNode> nodes = owner.ContainerGraph.MultiPassMasterNodes.NodesList;
                        int count = nodes.Count;
                        for (int nodeIdx = 0; nodeIdx < count; nodeIdx++)
                        {
                            nodes[nodeIdx].OptionsDefineContainer.AddDefine(defineValue, false);
                        }
                    }
                    else if (!string.IsNullOrEmpty(validActions[i].PassName))
                    {
                        TemplateMultiPassMasterNode passMasterNode = owner.ContainerGraph.GetMasterNodeOfPass(validActions[i].PassName);
                        if (passMasterNode != null)
                        {
                            string defineValue = "#define " + validActions[i].ActionData;
                            if (isRefreshing)
                            {
                                string optionsId = validActions[i].PassName + defineValue;
                                owner.ContainerGraph.ParentWindow.TemplatesManagerInstance.SetOptionsValue(optionsId, true);
                            }
                            passMasterNode.OptionsDefineContainer.AddDefine(defineValue, false);
                        }
                        else
                        {
                            Debug.LogFormat("Could not find pass {0} for action {1} on {2}", validActions[i].PassName, validActions[i].ActionType, validActions[i].ActionData);
                        }
                    }
                    else
                    {
                        uiItem.CheckOnExecute = true;
                    }
                }
                break;

                case AseOptionsActionType.RemoveDefine:
                {
                    //Debug.Log( "UNDEFINE " + validActions[ i ].ActionData );
                    if (validActions[i].AllPasses)
                    {
                        string defineValue = "#define " + validActions[i].ActionData;

                        bool flag = false;
                        if (isRefreshing)
                        {
                            flag = owner.ContainerGraph.ParentWindow.TemplatesManagerInstance.SetOptionsValue(defineValue, false);
                        }

                        if (!flag)
                        {
                            List <TemplateMultiPassMasterNode> nodes = owner.ContainerGraph.MultiPassMasterNodes.NodesList;
                            int count = nodes.Count;
                            for (int nodeIdx = 0; nodeIdx < count; nodeIdx++)
                            {
                                nodes[nodeIdx].OptionsDefineContainer.RemoveDefine(defineValue);
                            }
                        }
                    }
                    else if (!string.IsNullOrEmpty(validActions[i].PassName))
                    {
                        TemplateMultiPassMasterNode passMasterNode = owner.ContainerGraph.GetMasterNodeOfPass(validActions[i].PassName);
                        if (passMasterNode != null)
                        {
                            string defineValue = "#define " + validActions[i].ActionData;
                            bool   flag        = false;
                            if (isRefreshing)
                            {
                                string optionId = validActions[i].PassName + defineValue;
                                flag = owner.ContainerGraph.ParentWindow.TemplatesManagerInstance.SetOptionsValue(optionId, false);
                            }
                            if (!flag)
                            {
                                passMasterNode.OptionsDefineContainer.RemoveDefine(defineValue);
                            }
                        }
                        else
                        {
                            Debug.LogFormat("Could not find pass {0} for action {1} on {2}", validActions[i].PassName, validActions[i].ActionType, validActions[i].ActionData);
                        }
                    }
                    else
                    {
                        uiItem.CheckOnExecute = false;
                    }
                }
                break;

                case AseOptionsActionType.SetUndefine:
                {
                    if (validActions[i].AllPasses)
                    {
                        string defineValue = "#undef " + validActions[i].ActionData;
                        if (isRefreshing)
                        {
                            owner.ContainerGraph.ParentWindow.TemplatesManagerInstance.SetOptionsValue(defineValue, true);
                        }
                        List <TemplateMultiPassMasterNode> nodes = owner.ContainerGraph.MultiPassMasterNodes.NodesList;
                        int count = nodes.Count;
                        for (int nodeIdx = 0; nodeIdx < count; nodeIdx++)
                        {
                            nodes[nodeIdx].OptionsDefineContainer.AddDefine(defineValue, false);
                        }
                    }
                    else if (!string.IsNullOrEmpty(validActions[i].PassName))
                    {
                        TemplateMultiPassMasterNode passMasterNode = owner.ContainerGraph.GetMasterNodeOfPass(validActions[i].PassName);
                        if (passMasterNode != null)
                        {
                            string defineValue = "#undef " + validActions[i].ActionData;
                            if (isRefreshing)
                            {
                                string optionsId = validActions[i].PassName + defineValue;
                                owner.ContainerGraph.ParentWindow.TemplatesManagerInstance.SetOptionsValue(optionsId, true);
                            }
                            passMasterNode.OptionsDefineContainer.AddDefine(defineValue, false);
                        }
                        else
                        {
                            Debug.LogFormat("Could not find pass {0} for action {1} on {2}", validActions[i].PassName, validActions[i].ActionType, validActions[i].ActionData);
                        }
                    }
                    else
                    {
                        uiItem.CheckOnExecute = true;
                    }
                }
                break;

                case AseOptionsActionType.RemoveUndefine:
                {
                    if (validActions[i].AllPasses)
                    {
                        string defineValue = "#undef " + validActions[i].ActionData;
                        bool   flag        = false;
                        if (isRefreshing)
                        {
                            flag = owner.ContainerGraph.ParentWindow.TemplatesManagerInstance.SetOptionsValue(defineValue, false);
                        }

                        if (!flag)
                        {
                            List <TemplateMultiPassMasterNode> nodes = owner.ContainerGraph.MultiPassMasterNodes.NodesList;
                            int count = nodes.Count;
                            for (int nodeIdx = 0; nodeIdx < count; nodeIdx++)
                            {
                                nodes[nodeIdx].OptionsDefineContainer.RemoveDefine(defineValue);
                            }
                        }
                    }
                    else if (!string.IsNullOrEmpty(validActions[i].PassName))
                    {
                        TemplateMultiPassMasterNode passMasterNode = owner.ContainerGraph.GetMasterNodeOfPass(validActions[i].PassName);
                        if (passMasterNode != null)
                        {
                            bool   flag        = false;
                            string defineValue = "#undef " + validActions[i].ActionData;
                            if (isRefreshing)
                            {
                                string optionId = validActions[i].PassName + defineValue;
                                flag = owner.ContainerGraph.ParentWindow.TemplatesManagerInstance.SetOptionsValue(optionId, false);
                            }

                            if (!flag)
                            {
                                passMasterNode.OptionsDefineContainer.RemoveDefine(defineValue);
                            }
                        }
                        else
                        {
                            Debug.LogFormat("Could not find pass {0} for action {1} on {2}", validActions[i].PassName, validActions[i].ActionType, validActions[i].ActionData);
                        }
                    }
                    else
                    {
                        uiItem.CheckOnExecute = false;
                    }
                }
                break;

                case AseOptionsActionType.ExcludePass:
                {
                    string optionId = validActions[i].ActionData + "Pass";
                    bool   flag     = isRefreshing ? owner.ContainerGraph.ParentWindow.TemplatesManagerInstance.SetOptionsValue(optionId, false) : false;
                    if (!flag)
                    {
                        owner.SetPassVisible(validActions[i].ActionData, false);
                    }
                }
                break;

                case AseOptionsActionType.IncludePass:
                {
                    string optionId = validActions[i].ActionData + "Pass";
                    owner.ContainerGraph.ParentWindow.TemplatesManagerInstance.SetOptionsValue(optionId, true);
                    owner.SetPassVisible(validActions[i].ActionData, true);
                }
                break;

                case AseOptionsActionType.SetPropertyOnPass:
                {
                    //Refresh happens on hotcode reload and shader load and in those situation
                    // The property own serialization handles its setup
                    if (isRefreshing)
                    {
                        continue;
                    }

                    if (!string.IsNullOrEmpty(validActions[i].PassName))
                    {
                        TemplateMultiPassMasterNode passMasterNode = owner.ContainerGraph.GetMasterNodeOfPass(validActions[i].PassName);
                        if (passMasterNode != null)
                        {
                            passMasterNode.SetPropertyActionFromItem(passMasterNode.PassModule, validActions[i]);
                        }
                        else
                        {
                            Debug.LogFormat("Could not find pass {0} for action {1} on {2}", validActions[i].PassName, validActions[i].ActionType, validActions[i].ActionData);
                        }
                    }
                    else
                    {
                        owner.SetPropertyActionFromItem(owner.PassModule, validActions[i]);
                    }
                }
                break;

                case AseOptionsActionType.SetPropertyOnSubShader:
                {
                    //Refresh happens on hotcode reload and shader load and in those situation
                    // The property own serialization handles its setup
                    if (isRefreshing)
                    {
                        continue;
                    }

                    owner.SetPropertyActionFromItem(owner.SubShaderModule, validActions[i]);
                }
                break;

                case AseOptionsActionType.SetShaderProperty:
                {
                    //This action is only check when shader is compiled over
                    //the TemplateMultiPassMasterNode via the on CheckPropertyChangesOnOptions() method
                }
                break;
                }
            }
        }
コード例 #3
0
		public TemplateSubShader( int subShaderIx, TemplateIdManager idManager, string uniquePrefix, TemplateSubShaderInfo subShaderInfo, ref Dictionary<string, TemplateShaderPropertyData> duplicatesHelper )
		{
			m_idx = subShaderIx:

			m_uniquePrefix = uniquePrefix:

			FetchLOD( subShaderInfo.StartIdx, subShaderInfo.Modules ):
			if( m_LODContainer.Index > -1 )
			{
				idManager.RegisterId( m_LODContainer.Index, uniquePrefix + "Module" + m_LODContainer.Id, m_LODContainer.Id ):
			}

			m_customOptionsContainer = TemplateOptionsToolsHelper.GenerateOptionsContainer( true, subShaderInfo.Data ):
			if( m_customOptionsContainer.Enabled )
			{
				idManager.RegisterId( m_customOptionsContainer.Index, uniquePrefix + m_customOptionsContainer.Body, m_customOptionsContainer.Body, true ):
			}

			m_modules = new TemplateModulesData( m_customOptionsContainer, idManager, m_templateProperties, uniquePrefix + "Module", subShaderInfo.StartIdx, subShaderInfo.Modules, true ):
			if( m_modules.SRPType == TemplateSRPType.HD )
			{
				m_modules.SRPIsPBR = subShaderInfo.Data.Contains( TemplateHelperFunctions.HDPBRTag ):
			}

			Dictionary<string, TemplateShaderPropertyData> ownDuplicatesDict = new Dictionary<string, TemplateShaderPropertyData>( duplicatesHelper ):

			TemplateHelperFunctions.CreateShaderGlobalsList( subShaderInfo.Modules, ref m_availableShaderGlobals, ref ownDuplicatesDict ):

			m_passAmount = subShaderInfo.Passes.Count:
			
			//if( !m_modules.PassTag.IsValid )
			//{
			//	m_modules.PassTag.StartIdx = subShaderData.Passes[ 0 ].GlobalStartIdx:
			//	m_templateProperties.AddId( subShaderData.Data, m_modules.PassTag.Id, subShaderData.Passes[ 0 ].LocalStartIdx, m_modules.PassTag.SearchIndentation ):
			//	m_modules.PassTag.StartIdx -= m_templateProperties.PropertyDict[ m_modules.PassTag.Id ].Indentation.Length:
			//	m_templateProperties.PropertyDict[ m_modules.PassTag.Id ].UseIndentationAtStart = true:
			//	idManager.RegisterId( m_modules.PassTag.StartIdx, m_modules.UniquePrefix + m_modules.PassTag.Id, string.Empty ):
			//}
			
			int firstVisible = -1:
			int currAddedPassIdx = 0:
			for( int passIdx = 0: passIdx < m_passAmount: passIdx++ )
			{
				TemplatePass newPass = new TemplatePass( this,subShaderIx, passIdx, idManager, uniquePrefix + "Pass" + passIdx, subShaderInfo.Passes[ passIdx ].GlobalStartIdx, subShaderInfo.Passes[ passIdx ], ref ownDuplicatesDict ):
				if( newPass.AddToList )
				{
					if( newPass.IsMainPass && m_mainPass < 0  )
					{
						m_mainPass = currAddedPassIdx:
						m_foundMainPassTag = true:
					}
					else if(!newPass.IsInvisible && firstVisible < 0 )
					{
						firstVisible = currAddedPassIdx:
					}

					m_passes.Add( newPass ):
					currAddedPassIdx++:
				}
				else
				{
					newPass.Destroy():
					newPass = null:
				}

			}

			if( m_mainPass < 0 )
			{
				// If no main pass was set then choose the first visible one
				m_mainPass = ( firstVisible < 0 ) ? 0 : firstVisible:
				m_passes[ m_mainPass ].IsMainPass = true:
			}

			ownDuplicatesDict.Clear():
			ownDuplicatesDict = null:
		}
コード例 #4
0
        public void OnCustomOptionSelected(bool actionFromUser, bool isRefreshing, bool invertAction, TemplateMultiPassMasterNode owner, TemplateOptionUIItem uiItem, params TemplateActionItem[] validActions)
        {
            uiItem.CheckOnExecute = false;
            for (int i = 0; i < validActions.Length; i++)
            {
                AseOptionsActionType actionType = validActions[i].ActionType;
                if (invertAction)
                {
                    if (!TemplateOptionsToolsHelper.InvertAction(validActions[i].ActionType, ref actionType))
                    {
                        continue;
                    }
                }


                switch (actionType)
                {
                case AseOptionsActionType.ShowOption:
                {
                    TemplateOptionUIItem item = m_passCustomOptionsUI.Find(x => (x.Options.Name.Equals(validActions[i].ActionData)));
                    if (item != null)
                    {
                        if (isRefreshing)
                        {
                            string optionId = validActions[i].PassName + validActions[i].ActionData + "Option";
                            owner.ContainerGraph.ParentWindow.TemplatesManagerInstance.SetOptionsValue(optionId, true);
                        }

                        // this prevents options from showing up when loading by checking if they were hidden by another option
                        // it works on the assumption that an option that may possible hide this one is checked first
                        if (!isRefreshing)
                        {
                            item.IsVisible = true;
                        }
                        else if (item.WasVisible)
                        {
                            item.IsVisible = true;
                        }

                        if (!invertAction && validActions[i].ActionDataIdx > -1)
                        {
                            item.CurrentOption = validActions[i].ActionDataIdx;
                        }

                        item.CheckEnDisable(actionFromUser);
                    }
                    else
                    {
                        Debug.LogFormat("Could not find Option {0} for action {1}", validActions[i].ActionData, validActions[i].ActionType);
                    }
                }
                break;

                case AseOptionsActionType.HideOption:
                {
                    TemplateOptionUIItem item = m_passCustomOptionsUI.Find(x => (x.Options.Name.Equals(validActions[i].ActionData)));
                    if (item != null)
                    {
                        bool flag = false;
                        if (isRefreshing)
                        {
                            string optionId = validActions[i].PassName + validActions[i].ActionData + "Option";
                            flag = owner.ContainerGraph.ParentWindow.TemplatesManagerInstance.SetOptionsValue(optionId, false);
                        }

                        item.IsVisible = false || flag;
                        if (!invertAction && validActions[i].ActionDataIdx > -1)
                        {
                            item.CurrentOption = validActions[i].ActionDataIdx;
                        }

                        item.CheckEnDisable(actionFromUser);
                    }
                    else
                    {
                        Debug.LogFormat("Could not find Option {0} for action {1}", validActions[i].ActionData, validActions[i].ActionType);
                    }
                }
                break;

                case AseOptionsActionType.SetOption:
                {
                    if (!uiItem.IsVisible)
                    {
                        break;
                    }

                    TemplateOptionUIItem item = m_passCustomOptionsUI.Find(x => (x.Options.Name.Equals(validActions[i].ActionData)));
                    if (item != null)
                    {
                        item.CurrentOption = validActions[i].ActionDataIdx;
                        item.Refresh();
                    }
                    else
                    {
                        Debug.LogFormat("Could not find Option {0} for action {1}", validActions[i].ActionData, validActions[i].ActionType);
                    }
                }
                break;

                case AseOptionsActionType.HidePort:
                {
                    TemplateMultiPassMasterNode passMasterNode = owner;
                    if (!string.IsNullOrEmpty(validActions[i].PassName))
                    {
                        passMasterNode = owner.ContainerGraph.GetMasterNodeOfPass(validActions[i].PassName, owner.LODIndex);
                    }

                    if (passMasterNode != null)
                    {
                        InputPort port = validActions[i].ActionDataIdx > -1 ?
                                         passMasterNode.GetInputPortByUniqueId(validActions[i].ActionDataIdx) :
                                         passMasterNode.InputPorts.Find(x => x.Name.Equals(validActions[i].ActionData));
                        if (port != null)
                        {
                            if (isRefreshing)
                            {
                                string optionId = validActions[i].PassName + port.Name;
                                owner.ContainerGraph.ParentWindow.TemplatesManagerInstance.SetOptionsValue(optionId, port.IsConnected);
                                port.Visible = port.IsConnected;
                            }
                            else
                            {
                                port.Visible = false;
                            }
                            passMasterNode.SizeIsDirty = true;
                        }
                        else
                        {
                            Debug.LogFormat("Could not find port {0},{1} for action {2}", validActions[i].ActionDataIdx, validActions[i].ActionData, validActions[i].ActionType);
                        }
                    }
                    else
                    {
                        Debug.LogFormat("Could not find pass {0} for action {1} on {2}", validActions[i].PassName, validActions[i].ActionType, validActions[i].ActionData);
                    }
                }
                break;

                case AseOptionsActionType.ShowPort:
                {
                    if (!uiItem.IsVisible)
                    {
                        break;
                    }

                    TemplateMultiPassMasterNode passMasterNode = owner;
                    if (!string.IsNullOrEmpty(validActions[i].PassName))
                    {
                        passMasterNode = owner.ContainerGraph.GetMasterNodeOfPass(validActions[i].PassName, owner.LODIndex);
                    }

                    if (passMasterNode != null)
                    {
                        InputPort port = validActions[i].ActionDataIdx > -1 ?
                                         passMasterNode.GetInputPortByUniqueId(validActions[i].ActionDataIdx) :
                                         passMasterNode.InputPorts.Find(x => x.Name.Equals(validActions[i].ActionData));
                        if (port != null)
                        {
                            if (isRefreshing)
                            {
                                string optionId = validActions[i].PassName + port.Name;
                                owner.ContainerGraph.ParentWindow.TemplatesManagerInstance.SetOptionsValue(optionId, true);
                            }

                            port.Visible = true;
                            passMasterNode.SizeIsDirty = true;
                        }
                        else
                        {
                            Debug.LogFormat("Could not find port {0},{1} for action {2}", validActions[i].ActionDataIdx, validActions[i].ActionData, validActions[i].ActionType);
                        }
                    }
                    else
                    {
                        Debug.LogFormat("Could not find pass {0} for action {1} on {2}", validActions[i].PassName, validActions[i].ActionType, validActions[i].ActionData);
                    }
                }
                break;

                case AseOptionsActionType.SetPortName:
                {
                    if (!uiItem.IsVisible)
                    {
                        break;
                    }

                    TemplateMultiPassMasterNode passMasterNode = owner;
                    if (!string.IsNullOrEmpty(validActions[i].PassName))
                    {
                        passMasterNode = owner.ContainerGraph.GetMasterNodeOfPass(validActions[i].PassName, owner.LODIndex);
                    }

                    if (passMasterNode != null)
                    {
                        InputPort port = passMasterNode.GetInputPortByUniqueId(validActions[i].ActionDataIdx);
                        if (port != null)
                        {
                            port.Name = validActions[i].ActionData;
                            passMasterNode.SizeIsDirty = true;
                        }
                        else
                        {
                            Debug.LogFormat("Could not find port {0},{1} for action {2}", validActions[i].ActionDataIdx, validActions[i].ActionData, validActions[i].ActionType);
                        }
                    }
                    else
                    {
                        Debug.LogFormat("Could not find pass {0} for action {1} on {2}", validActions[i].PassName, validActions[i].ActionType, validActions[i].ActionData);
                    }
                }
                break;

                case AseOptionsActionType.SetDefine:
                {
                    if (!uiItem.IsVisible)
                    {
                        uiItem.CheckOnExecute = true;
                        break;
                    }

                    //Debug.Log( "DEFINE " + validActions[ i ].ActionData );
                    if (validActions[i].AllPasses)
                    {
                        string actionData  = validActions[i].ActionData;
                        string defineValue = string.Empty;
                        bool   isPragma    = false;
                        if (actionData.StartsWith("pragma"))
                        {
                            defineValue = "#" + actionData;
                            isPragma    = true;
                        }
                        else
                        {
                            defineValue = "#define " + validActions[i].ActionData;
                        }
                        if (isRefreshing)
                        {
                            owner.ContainerGraph.ParentWindow.TemplatesManagerInstance.SetOptionsValue(defineValue, true);
                        }
                        List <TemplateMultiPassMasterNode> nodes = owner.ContainerGraph.GetMultiPassMasterNodes(owner.LODIndex);
                        int count = nodes.Count;
                        for (int nodeIdx = 0; nodeIdx < count; nodeIdx++)
                        {
                            nodes[nodeIdx].OptionsDefineContainer.AddDirective(defineValue, false, isPragma);
                        }
                    }
                    else if (!string.IsNullOrEmpty(validActions[i].PassName))
                    {
                        TemplateMultiPassMasterNode passMasterNode = owner.ContainerGraph.GetMasterNodeOfPass(validActions[i].PassName, owner.LODIndex);
                        if (passMasterNode != null)
                        {
                            string actionData  = validActions[i].ActionData;
                            string defineValue = string.Empty;
                            bool   isPragma    = false;
                            if (actionData.StartsWith("pragma"))
                            {
                                defineValue = "#" + actionData;
                                isPragma    = true;
                            }
                            else
                            {
                                defineValue = "#define " + validActions[i].ActionData;
                            }
                            if (isRefreshing)
                            {
                                string optionsId = validActions[i].PassName + defineValue;
                                owner.ContainerGraph.ParentWindow.TemplatesManagerInstance.SetOptionsValue(optionsId, true);
                            }
                            passMasterNode.OptionsDefineContainer.AddDirective(defineValue, false, isPragma);
                        }
                        else
                        {
                            Debug.LogFormat("Could not find pass {0} for action {1} on {2}", validActions[i].PassName, validActions[i].ActionType, validActions[i].ActionData);
                        }
                    }
                    else
                    {
                        uiItem.CheckOnExecute = true;
                    }
                }
                break;

                case AseOptionsActionType.RemoveDefine:
                {
                    //Debug.Log( "UNDEFINE " + validActions[ i ].ActionData );
                    if (validActions[i].AllPasses)
                    {
                        string actionData  = validActions[i].ActionData;
                        string defineValue = string.Empty;
                        if (actionData.StartsWith("pragma"))
                        {
                            defineValue = "#" + actionData;
                        }
                        else
                        {
                            defineValue = "#define " + validActions[i].ActionData;
                        }

                        bool flag = false;
                        if (isRefreshing)
                        {
                            flag = owner.ContainerGraph.ParentWindow.TemplatesManagerInstance.SetOptionsValue(defineValue, false);
                        }

                        if (!flag)
                        {
                            List <TemplateMultiPassMasterNode> nodes = owner.ContainerGraph.GetMultiPassMasterNodes(owner.LODIndex);
                            int count = nodes.Count;
                            for (int nodeIdx = 0; nodeIdx < count; nodeIdx++)
                            {
                                nodes[nodeIdx].OptionsDefineContainer.RemoveDirective(defineValue);
                            }
                        }
                    }
                    else if (!string.IsNullOrEmpty(validActions[i].PassName))
                    {
                        TemplateMultiPassMasterNode passMasterNode = owner.ContainerGraph.GetMasterNodeOfPass(validActions[i].PassName, owner.LODIndex);
                        if (passMasterNode != null)
                        {
                            string actionData  = validActions[i].ActionData;
                            string defineValue = string.Empty;
                            if (actionData.StartsWith("pragma"))
                            {
                                defineValue = "#" + actionData;
                            }
                            else
                            {
                                defineValue = "#define " + validActions[i].ActionData;
                            }
                            bool flag = false;
                            if (isRefreshing)
                            {
                                string optionId = validActions[i].PassName + defineValue;
                                flag = owner.ContainerGraph.ParentWindow.TemplatesManagerInstance.SetOptionsValue(optionId, false);
                            }
                            if (!flag)
                            {
                                passMasterNode.OptionsDefineContainer.RemoveDirective(defineValue);
                            }
                        }
                        else
                        {
                            Debug.LogFormat("Could not find pass {0} for action {1} on {2}", validActions[i].PassName, validActions[i].ActionType, validActions[i].ActionData);
                        }
                    }
                    else
                    {
                        uiItem.CheckOnExecute = false;
                    }
                }
                break;

                case AseOptionsActionType.SetUndefine:
                {
                    if (!uiItem.IsVisible)
                    {
                        uiItem.CheckOnExecute = true;
                        break;
                    }

                    if (validActions[i].AllPasses)
                    {
                        string defineValue = "#undef " + validActions[i].ActionData;
                        if (isRefreshing)
                        {
                            owner.ContainerGraph.ParentWindow.TemplatesManagerInstance.SetOptionsValue(defineValue, true);
                        }
                        List <TemplateMultiPassMasterNode> nodes = owner.ContainerGraph.GetMultiPassMasterNodes(owner.LODIndex);
                        int count = nodes.Count;
                        for (int nodeIdx = 0; nodeIdx < count; nodeIdx++)
                        {
                            nodes[nodeIdx].OptionsDefineContainer.AddDirective(defineValue, false);
                        }
                    }
                    else if (!string.IsNullOrEmpty(validActions[i].PassName))
                    {
                        TemplateMultiPassMasterNode passMasterNode = owner.ContainerGraph.GetMasterNodeOfPass(validActions[i].PassName, owner.LODIndex);
                        if (passMasterNode != null)
                        {
                            string defineValue = "#undef " + validActions[i].ActionData;
                            if (isRefreshing)
                            {
                                string optionsId = validActions[i].PassName + defineValue;
                                owner.ContainerGraph.ParentWindow.TemplatesManagerInstance.SetOptionsValue(optionsId, true);
                            }
                            passMasterNode.OptionsDefineContainer.AddDirective(defineValue, false);
                        }
                        else
                        {
                            Debug.LogFormat("Could not find pass {0} for action {1} on {2}", validActions[i].PassName, validActions[i].ActionType, validActions[i].ActionData);
                        }
                    }
                    else
                    {
                        uiItem.CheckOnExecute = true;
                    }
                }
                break;

                case AseOptionsActionType.RemoveUndefine:
                {
                    if (validActions[i].AllPasses)
                    {
                        string defineValue = "#undef " + validActions[i].ActionData;
                        bool   flag        = false;
                        if (isRefreshing)
                        {
                            flag = owner.ContainerGraph.ParentWindow.TemplatesManagerInstance.SetOptionsValue(defineValue, false);
                        }

                        if (!flag)
                        {
                            List <TemplateMultiPassMasterNode> nodes = owner.ContainerGraph.GetMultiPassMasterNodes(owner.LODIndex);
                            int count = nodes.Count;
                            for (int nodeIdx = 0; nodeIdx < count; nodeIdx++)
                            {
                                nodes[nodeIdx].OptionsDefineContainer.RemoveDirective(defineValue);
                            }
                        }
                    }
                    else if (!string.IsNullOrEmpty(validActions[i].PassName))
                    {
                        TemplateMultiPassMasterNode passMasterNode = owner.ContainerGraph.GetMasterNodeOfPass(validActions[i].PassName, owner.LODIndex);
                        if (passMasterNode != null)
                        {
                            bool   flag        = false;
                            string defineValue = "#undef " + validActions[i].ActionData;
                            if (isRefreshing)
                            {
                                string optionId = validActions[i].PassName + defineValue;
                                flag = owner.ContainerGraph.ParentWindow.TemplatesManagerInstance.SetOptionsValue(optionId, false);
                            }

                            if (!flag)
                            {
                                passMasterNode.OptionsDefineContainer.RemoveDirective(defineValue);
                            }
                        }
                        else
                        {
                            Debug.LogFormat("Could not find pass {0} for action {1} on {2}", validActions[i].PassName, validActions[i].ActionType, validActions[i].ActionData);
                        }
                    }
                    else
                    {
                        uiItem.CheckOnExecute = false;
                    }
                }
                break;

                case AseOptionsActionType.ExcludePass:
                {
                    string optionId = validActions[i].ActionData + "Pass";
                    bool   flag     = isRefreshing ? owner.ContainerGraph.ParentWindow.TemplatesManagerInstance.SetOptionsValue(optionId, false) : false;
                    if (!flag)
                    {
                        owner.SetPassVisible(validActions[i].ActionData, false);
                    }
                }
                break;

                case AseOptionsActionType.IncludePass:
                {
                    if (!uiItem.IsVisible)
                    {
                        break;
                    }

                    string optionId = validActions[i].ActionData + "Pass";
                    owner.ContainerGraph.ParentWindow.TemplatesManagerInstance.SetOptionsValue(optionId, true);
                    owner.SetPassVisible(validActions[i].ActionData, true);
                }
                break;

                case AseOptionsActionType.SetPropertyOnPass:
                {
                    //Debug.Log( "PASSPROP " + validActions[ i ].ActionData );
                    //Refresh happens on hotcode reload and shader load and in those situation
                    // The property own serialization handles its setup
                    if (isRefreshing)
                    {
                        continue;
                    }

                    if (!string.IsNullOrEmpty(validActions[i].PassName))
                    {
                        TemplateMultiPassMasterNode passMasterNode = owner.ContainerGraph.GetMasterNodeOfPass(validActions[i].PassName, owner.LODIndex);
                        if (passMasterNode != null)
                        {
                            passMasterNode.SetPropertyActionFromItem(actionFromUser, passMasterNode.PassModule, validActions[i]);
                        }
                        else
                        {
                            Debug.LogFormat("Could not find pass {0} for action {1} on {2}", validActions[i].PassName, validActions[i].ActionType, validActions[i].ActionData);
                        }
                    }
                    else
                    {
                        owner.SetPropertyActionFromItem(actionFromUser, owner.PassModule, validActions[i]);
                    }
                }
                break;

                case AseOptionsActionType.SetPropertyOnSubShader:
                {
                    //Refresh happens on hotcode reload and shader load and in those situation
                    // The property own serialization handles its setup
                    if (isRefreshing)
                    {
                        continue;
                    }

                    owner.SetPropertyActionFromItem(actionFromUser, owner.SubShaderModule, validActions[i]);
                }
                break;

                case AseOptionsActionType.SetShaderProperty:
                {
                    //This action is only check when shader is compiled over
                    //the TemplateMultiPassMasterNode via the on CheckPropertyChangesOnOptions() method
                }
                break;

                case AseOptionsActionType.ExcludeAllPassesBut:
                {
                    //This action is only check when shader is compiled over
                    //the TemplateMultiPassMasterNode via the on CheckExcludeAllPassOptions() method
                }
                break;

                case AseOptionsActionType.SetMaterialProperty:
                {
                    if (isRefreshing)
                    {
                        continue;
                    }

                    if (!uiItem.IsVisible)
                    {
                        break;
                    }

                    if (owner.ContainerGraph.CurrentMaterial != null)
                    {
                        string prop = validActions[i].ActionData;
                        if (owner.ContainerGraph.CurrentMaterial.HasProperty(prop))
                        {
                            if (uiItem.Options.UIWidget == AseOptionsUIWidget.Float || uiItem.Options.UIWidget == AseOptionsUIWidget.FloatRange)
                            {
                                owner.ContainerGraph.CurrentMaterial.SetFloat(prop, uiItem.CurrentFieldValue);
                            }
                            else
                            {
                                owner.ContainerGraph.CurrentMaterial.SetInt(prop, (int)uiItem.CurrentFieldValue);
                            }

                            if (ASEMaterialInspector.Instance != null)
                            {
                                ASEMaterialInspector.Instance.Repaint();
                            }
                        }
                    }
                }
                break;
                }
            }
        }