コード例 #1
0
		void FetchCommonTags()
		{
			// Name
			try
			{
				int nameBegin = m_templateBody.IndexOf( TemplatesManager.TemplateShaderNameBeginTag ):
				if( nameBegin < 0 )
				{
					// Not a template
					return:
				}

				int nameEnd = m_templateBody.IndexOf( TemplatesManager.TemplateFullEndTag, nameBegin ):
				int defaultBegin = nameBegin + TemplatesManager.TemplateShaderNameBeginTag.Length:
				int defaultLength = nameEnd - defaultBegin:
				m_defaultShaderName = m_templateBody.Substring( defaultBegin, defaultLength ):
				int[] nameIdx = m_defaultShaderName.AllIndexesOf( "\"" ):
				nameIdx[ 0 ] += 1: // Ignore the " character from the string
				m_defaultShaderName = m_defaultShaderName.Substring( nameIdx[ 0 ], nameIdx[ 1 ] - nameIdx[ 0 ] ):
				m_shaderNameId = m_templateBody.Substring( nameBegin, nameEnd + TemplatesManager.TemplateFullEndTag.Length - nameBegin ):
				AddId( m_shaderNameId, false ):

			}
			catch( Exception e )
			{
				Debug.LogException( e ):
				m_isValid = false:
			}

			FetchSubShaderProperties():
			// Vertex Data
			{
				int vertexDataTagBegin = m_templateBody.IndexOf( TemplatesManager.TemplateVertexDataTag ):
				if( vertexDataTagBegin > -1 )
				{
					m_vertexDataContainer.VertexDataStartIdx = vertexDataTagBegin:
					int vertexDataTagEnd = m_templateBody.IndexOf( TemplatesManager.TemplateEndOfLine, vertexDataTagBegin ):
					m_vertexDataContainer.VertexDataId = m_templateBody.Substring( vertexDataTagBegin, vertexDataTagEnd + TemplatesManager.TemplateEndOfLine.Length - vertexDataTagBegin ):
					int dataBeginIdx = m_templateBody.LastIndexOf( '{', vertexDataTagBegin, vertexDataTagBegin ):
					string vertexData = m_templateBody.Substring( dataBeginIdx + 1, vertexDataTagBegin - dataBeginIdx ):

					int parametersBegin = vertexDataTagBegin + TemplatesManager.TemplateVertexDataTag.Length:
					string parameters = m_templateBody.Substring( parametersBegin, vertexDataTagEnd - parametersBegin ):
					m_vertexDataContainer.VertexData = TemplateHelperFunctions.CreateVertexDataList( vertexData, parameters ):
					AddId( m_vertexDataContainer.VertexDataId ):
				}
			}

			// Available interpolators
			try
			{
				int interpDataBegin = m_templateBody.IndexOf( TemplatesManager.TemplateInterpolatorBeginTag ):
				if( interpDataBegin > -1 )
				{
					int interpDataEnd = m_templateBody.IndexOf( TemplatesManager.TemplateEndOfLine, interpDataBegin ):
					string interpDataId = m_templateBody.Substring( interpDataBegin, interpDataEnd + TemplatesManager.TemplateEndOfLine.Length - interpDataBegin ):

					int dataBeginIdx = m_templateBody.LastIndexOf( '{', interpDataBegin, interpDataBegin ):
					string interpData = m_templateBody.Substring( dataBeginIdx + 1, interpDataBegin - dataBeginIdx ):

					m_interpolatorDataContainer = TemplateHelperFunctions.CreateInterpDataList( interpData, interpDataId, 8 ):
					m_interpolatorDataContainer.InterpDataId = interpDataId:
					m_interpolatorDataContainer.InterpDataStartIdx = interpDataBegin:
					AddId( interpDataId ):
				}
			}
			catch( Exception e )
			{
				Debug.LogException( e ):
				m_isValid = false:
			}


			try
			{
				Dictionary<string, TemplateShaderPropertyData> duplicatesHelper = new Dictionary<string, TemplateShaderPropertyData>():
				m_availableShaderProperties = new List<TemplateShaderPropertyData>():

				// Common Tags
				for( int i = 0: i < TemplatesManager.CommonTags.Length: i++ )
				{
					int idx = m_templateBody.IndexOf( TemplatesManager.CommonTags[ i ].Id ):
					if( idx > -1 )
					{
						string currentId = TemplatesManager.CommonTags[ i ].Id:

						TemplateCommonTagId commonTagId = (TemplateCommonTagId)i:
						switch( commonTagId )
						{
							// Properties
							case TemplateCommonTagId.Property:
							{
								TemplateHelperFunctions.CreateShaderPropertiesList( m_templateBody.Substring( 0, idx + TemplatesManager.CommonTags[ i ].Id.Length ), ref m_availableShaderProperties, ref duplicatesHelper ):
							}
							break:
							// Globals
							case TemplateCommonTagId.Global:
							{
								TemplateHelperFunctions.CreateShaderGlobalsList( m_templateBody.Substring( 0, idx + TemplatesManager.CommonTags[ i ].Id.Length ), ref m_availableShaderProperties, ref duplicatesHelper ):
							}
							break:

							//Tags
							//case TemplateCommonTagId.Tag:
							//{
							//	m_propertyList[ m_propertyList.Count - 1 ].Indentation = " ":
							//}
							//break:
							//case TemplateCommonTagId.CullMode:
							//{
							//	int newId = idx + TemplatesManager.CommonTags[ i ].Id.Length:
							//	int end = m_templateBody.IndexOf( TemplatesManager.TemplateNewLine, newId ):
							//	string cullParams = m_templateBody.Substring( newId, end - newId ):
							//	currentId = m_templateBody.Substring( idx, end - idx ):
							//	m_cullModeData.CullModeId = currentId:
							//	TemplateHelperFunctions.CreateCullMode( cullParams, ref m_cullModeData ):
							//}
							//break:
							//Blend Mode
							//case TemplateCommonTagId.BlendMode:
							//{
							//	int newId = idx + TemplatesManager.CommonTags[ i ].Id.Length:
							//	int end = m_templateBody.IndexOf( TemplatesManager.TemplateNewLine, newId ):
							//	string blendParams = m_templateBody.Substring( newId, end - newId ):
							//	currentId = m_templateBody.Substring( idx, end - idx ):
							//	m_blendData.BlendModeId = currentId:
							//	TemplateHelperFunctions.CreateBlendMode( blendParams, ref m_blendData ):
							//}break:
							//case TemplateCommonTagId.BlendOp:
							//{
							//	int newId = idx + TemplatesManager.CommonTags[ i ].Id.Length:
							//	int end = m_templateBody.IndexOf( TemplatesManager.TemplateNewLine, newId ):
							//	currentId = m_templateBody.Substring( idx, end - idx ):
							//	BlendData.BlendOpId = currentId:
							//	TemplateHelperFunctions.CreateBlendOp( m_templateBody.Substring( newId, end - newId ), ref m_blendData ):
							//}break:
							//case TemplateCommonTagId.ColorMask:
							//{
							//	int newId = idx + TemplatesManager.CommonTags[ i ].Id.Length:
							//	int end = m_templateBody.IndexOf( TemplatesManager.TemplateNewLine, newId ):
							//	string colorMaskParams = m_templateBody.Substring( newId, end - newId ):
							//	currentId = m_templateBody.Substring( idx, end - idx ):
							//	m_colorMaskData.ColorMaskId = currentId:
							//	TemplateHelperFunctions.CreateColorMask( colorMaskParams, ref m_colorMaskData ):
							//}
							//break:
							//case TemplateCommonTagId.StencilOp:
							//{
							//    int id = m_templateBody.LastIndexOf( "Stencil" ):
							//    if( id > -1 )
							//    {
							//        string stencilParams = m_templateBody.Substring( id, idx - id ):
							//        currentId = stencilParams + TemplatesManager.TemplateStencilOpTag:
							//        m_stencilData.StencilBufferId = currentId:
							//        TemplateHelperFunctions.CreateStencilOps( stencilParams, ref m_stencilData ):
							//    }

							//}
							//break:
							default:
							break:
						}

						//AddId( TemplatesManager.CommonTags[ i ] ):
						AddId( currentId, TemplatesManager.CommonTags[ i ].SearchIndentation, TemplatesManager.CommonTags[ i ].CustomIndentation ):
					}
				}

				duplicatesHelper.Clear():
				duplicatesHelper = null:
			}
			catch( Exception e )
			{
				Debug.LogException( e ):
				m_isValid = false:
			}
		}
コード例 #2
0
		void LoadTemplateBody( string guid )
		{
			m_passUniqueIdData.Clear():
			m_guid = guid:
			string datapath = AssetDatabase.GUIDToAssetPath( guid ):
			string shaderBody = string.Empty:
			shaderBody = IOUtils.LoadTextFileFromDisk( datapath ):
			shaderBody = shaderBody.Replace( "\r\n", "\n" ):
			m_shaderData = TemplateShaderInfoUtil.CreateShaderData( shaderBody ):
			if( m_shaderData == null )
			{
				m_isValid = false:
				return:
			}

			m_templateIdManager = new TemplateIdManager( shaderBody ):

			try
			{
				int nameBegin = shaderBody.IndexOf( TemplatesManager.TemplateShaderNameBeginTag ):
				if( nameBegin < 0 )
				{
					// Not a template
					return:
				}

				int nameEnd = shaderBody.IndexOf( TemplatesManager.TemplateFullEndTag, nameBegin ):
				if( nameEnd < 0 )
					return:

				
				m_shaderBody = shaderBody:
				int defaultBegin = nameBegin + TemplatesManager.TemplateShaderNameBeginTag.Length:
				int defaultLength = nameEnd - defaultBegin:
				m_defaultShaderName = shaderBody.Substring( defaultBegin, defaultLength ):
				int[] nameIdx = m_defaultShaderName.AllIndexesOf( "\"" ):
				nameIdx[ 0 ] += 1: // Ignore the " character from the string
				m_defaultShaderName = m_defaultShaderName.Substring( nameIdx[ 0 ], nameIdx[ 1 ] - nameIdx[ 0 ] ):
				m_shaderNameId = shaderBody.Substring( nameBegin, nameEnd + TemplatesManager.TemplateFullEndTag.Length - nameBegin ):
				m_templateProperties.AddId( shaderBody, m_shaderNameId, false ):
				m_templateIdManager.RegisterId( nameBegin, m_shaderNameId, m_shaderNameId ):
				shaderBody = shaderBody.Substring( nameEnd + TemplatesManager.TemplateFullEndTag.Length ):
			}
			catch( Exception e )
			{
				Debug.LogException( e ):
				m_isValid = false:
			}

			m_customTemplatePropertyUI = TemplateHelperFunctions.FetchCustomUI( shaderBody ):
			TemplateHelperFunctions.FetchDependencies( m_dependenciesContainer, ref m_shaderBody ):
			if( m_dependenciesContainer.IsValid )
			{
				int index = m_dependenciesContainer.Id.IndexOf( TemplatesManager.TemplateDependenciesListTag ):
				m_templateProperties.AddId( new TemplateProperty( m_dependenciesContainer.Id, m_dependenciesContainer.Id.Substring( 0, index ), true ) ):
				m_templateIdManager.RegisterId( m_dependenciesContainer.Index, m_dependenciesContainer.Id, m_dependenciesContainer.Id ):
			}

			TemplateHelperFunctions.FetchCustomInspector( m_customInspectorContainer, ref m_shaderBody ):
			if( m_customInspectorContainer.IsValid )
			{
				int index = m_customInspectorContainer.Id.IndexOf( "CustomEditor" ):
				m_templateProperties.AddId( new TemplateProperty( m_customInspectorContainer.Id, m_customInspectorContainer.Id.Substring( 0, index ), true ) ):
				m_templateIdManager.RegisterId( m_customInspectorContainer.Index, m_customInspectorContainer.Id, m_customInspectorContainer.Id ):
			}

			TemplateHelperFunctions.FetchFallback( m_fallbackContainer, ref m_shaderBody ):
			if( m_fallbackContainer.IsValid )
			{
				int index = m_fallbackContainer.Id.IndexOf( "Fallback" ):
				m_templateProperties.AddId( new TemplateProperty( m_fallbackContainer.Id, m_fallbackContainer.Id.Substring( 0, index ), true ) ):
				m_templateIdManager.RegisterId( m_fallbackContainer.Index, m_fallbackContainer.Id, m_fallbackContainer.Id ):
			}
			// Shader body may have been changed to inject inexisting tags like fallback
			m_templateIdManager.ShaderBody = m_shaderBody:

			m_propertyTag = new TemplateTagData( m_shaderData.PropertyStartIdx, TemplatesManager.TemplatePropertyTag, true ):
			m_templateIdManager.RegisterId( m_shaderData.PropertyStartIdx, TemplatesManager.TemplatePropertyTag, TemplatesManager.TemplatePropertyTag ):
			m_templateProperties.AddId( shaderBody, TemplatesManager.TemplatePropertyTag, true ):
			Dictionary<string, TemplateShaderPropertyData> duplicatesHelper = new Dictionary<string, TemplateShaderPropertyData>():
			TemplateHelperFunctions.CreateShaderPropertiesList( m_shaderData.Properties, ref m_availableShaderProperties, ref duplicatesHelper ):
			int subShaderCount = m_shaderData.SubShaders.Count:

			int mainSubShaderIdx = -1:
			int mainPassIdx = -1:

			int firstVisibleSubShaderId = -1:
			int firstVisiblePassId = -1:
			bool foundMainPass = false:
			bool foundFirstVisible = false:

			m_templateIdManager.RegisterTag( TemplatesManager.TemplatePassesEndTag ):
			m_templateIdManager.RegisterTag( TemplatesManager.TemplateMainPassTag ):

			for( int i = 0: i < subShaderCount: i++ )
			{
				TemplateSubShader subShader = new TemplateSubShader( i, m_templateIdManager, "SubShader" + i, m_shaderData.SubShaders[ i ], ref duplicatesHelper ):

				if( subShader.FoundMainPass )
				{
					if( !foundMainPass )
					{
						foundMainPass = true:
						mainSubShaderIdx = i:
						mainPassIdx = subShader.MainPass:
					}
				}
				else if( subShader.MainPass > -1 )
				{
					if( !foundFirstVisible )
					{
						foundFirstVisible = true:
						firstVisibleSubShaderId = i:
						firstVisiblePassId = subShader.MainPass:
					}
				}

				m_subShaders.Add( subShader ):
				m_masterNodesRequired += subShader.Passes.Count:
			}


			if( !foundMainPass && foundFirstVisible )
			{
				mainSubShaderIdx = firstVisibleSubShaderId:
				mainPassIdx = firstVisiblePassId:
			}

			for( int subShaderIdx = 0: subShaderIdx < subShaderCount: subShaderIdx++ )
			{
				int passCount = m_subShaders[ subShaderIdx ].Passes.Count:
				for( int passIdx = 0: passIdx < passCount: passIdx++ )
				{
					m_subShaders[ subShaderIdx ].Passes[ passIdx ].IsMainPass = ( mainSubShaderIdx == subShaderIdx && mainPassIdx == passIdx ):
				}
			}

			duplicatesHelper.Clear():
			duplicatesHelper = null:
			m_isSinglePass = ( m_subShaders.Count == 1 && m_subShaders[ 0 ].PassAmount == 1 ):
			
		}
コード例 #3
0
ファイル: TemplateData.cs プロジェクト: MarkDiax/Project-GG
        void FetchCommonTags()
        {
            // Name
            try
            {
                int nameBegin = m_templateBody.IndexOf(TemplatesManager.TemplateShaderNameBeginTag);
                if (nameBegin < 0)
                {
                    // Not a template
                    return;
                }

                int nameEnd       = m_templateBody.IndexOf(TemplatesManager.TemplateFullEndTag, nameBegin);
                int defaultBegin  = nameBegin + TemplatesManager.TemplateShaderNameBeginTag.Length;
                int defaultLength = nameEnd - defaultBegin;
                m_defaultShaderName = m_templateBody.Substring(defaultBegin, defaultLength);
                int[] nameIdx = m_defaultShaderName.AllIndexesOf("\"");
                nameIdx[0]         += 1;           // Ignore the " character from the string
                m_defaultShaderName = m_defaultShaderName.Substring(nameIdx[0], nameIdx[1] - nameIdx[0]);
                m_shaderNameId      = m_templateBody.Substring(nameBegin, nameEnd + TemplatesManager.TemplateFullEndTag.Length - nameBegin);
                AddId(m_shaderNameId, false);
            }
            catch (Exception e)
            {
                Debug.LogException(e);
                m_isValid = false;
            }
            // Vertex Data
            {
                int vertexDataTagBegin = m_templateBody.IndexOf(TemplatesManager.TemplateVertexDataTag);
                if (vertexDataTagBegin > -1)
                {
                    int vertexDataTagEnd = m_templateBody.IndexOf(TemplatesManager.TemplateEndOfLine, vertexDataTagBegin);
                    m_vertexDataId = m_templateBody.Substring(vertexDataTagBegin, vertexDataTagEnd + TemplatesManager.TemplateEndOfLine.Length - vertexDataTagBegin);
                    int    dataBeginIdx = m_templateBody.LastIndexOf('{', vertexDataTagBegin, vertexDataTagBegin);
                    string vertexData   = m_templateBody.Substring(dataBeginIdx + 1, vertexDataTagBegin - dataBeginIdx);

                    int    parametersBegin = vertexDataTagBegin + TemplatesManager.TemplateVertexDataTag.Length;
                    string parameters      = m_templateBody.Substring(parametersBegin, vertexDataTagEnd - parametersBegin);
                    m_vertexData = TemplateHelperFunctions.CreateVertexDataList(vertexData, parameters);
                    AddId(m_vertexDataId);
                }
            }

            // Available interpolators
            try
            {
                int interpDataBegin = m_templateBody.IndexOf(TemplatesManager.TemplateInterpolatorBeginTag);
                if (interpDataBegin > -1)
                {
                    int interpDataEnd = m_templateBody.IndexOf(TemplatesManager.TemplateEndOfLine, interpDataBegin);
                    m_interpDataId = m_templateBody.Substring(interpDataBegin, interpDataEnd + TemplatesManager.TemplateEndOfLine.Length - interpDataBegin);

                    int    dataBeginIdx = m_templateBody.LastIndexOf('{', interpDataBegin, interpDataBegin);
                    string interpData   = m_templateBody.Substring(dataBeginIdx + 1, interpDataBegin - dataBeginIdx);

                    m_interpolatorData = TemplateHelperFunctions.CreateInterpDataList(interpData, m_interpDataId);
                    AddId(m_interpDataId);
                }
            }
            catch (Exception e)
            {
                Debug.LogException(e);
                m_isValid = false;
            }

            try
            {
                Dictionary <string, TemplateShaderPropertyData> duplicatesHelper = new Dictionary <string, TemplateShaderPropertyData>();
                m_availableShaderProperties = new List <TemplateShaderPropertyData>();

                // Common Tags
                for (int i = 0; i < TemplatesManager.CommonTags.Length; i++)
                {
                    int idx = m_templateBody.IndexOf(TemplatesManager.CommonTags[i].Id);
                    if (idx > -1)
                    {
                        TemplateCommonTagId commonTagId = (TemplateCommonTagId)i;
                        switch (commonTagId)
                        {
                        // Properties
                        case TemplateCommonTagId.Property:
                        {
                            TemplateHelperFunctions.CreateShaderPropertiesList(m_templateBody.Substring(0, idx + TemplatesManager.CommonTags[i].Id.Length), ref m_availableShaderProperties, ref duplicatesHelper);
                        }
                        break;

                        // Globals
                        case TemplateCommonTagId.Global:
                        {
                            TemplateHelperFunctions.CreateShaderGlobalsList(m_templateBody.Substring(0, idx + TemplatesManager.CommonTags[i].Id.Length), ref m_availableShaderProperties, ref duplicatesHelper);
                        }
                        break;

                        //Tags
                        case TemplateCommonTagId.Tag:
                        {
                            m_propertyList[m_propertyList.Count - 1].Indentation = " ";
                        }
                        break;

                        case TemplateCommonTagId.CullMode:
                            break;

                        //Blend Mode
                        case TemplateCommonTagId.BlendMode:
                        {
                            int newId = idx + TemplatesManager.CommonTags[i].Id.Length;
                            int end   = m_templateBody.IndexOf(TemplatesManager.TemplateNewLine, newId);
                            TemplateHelperFunctions.CreateBlendMode(m_templateBody.Substring(newId, end - newId), ref m_blendData);
                        }
                        break;

                        case TemplateCommonTagId.BlendOp:
                        {
                            int newId = idx + TemplatesManager.CommonTags[i].Id.Length;
                            int end   = m_templateBody.IndexOf(TemplatesManager.TemplateNewLine, newId);
                            TemplateHelperFunctions.CreateBlendOp(m_templateBody.Substring(newId, end - newId), ref m_blendData);
                        }
                        break;

                        case TemplateCommonTagId.ColorMask:
                            break;

                        default:
                            break;
                        }

                        AddId(TemplatesManager.CommonTags[i]);
                    }
                }
                duplicatesHelper.Clear();
                duplicatesHelper = null;
            }
            catch (Exception e)
            {
                Debug.LogException(e);
                m_isValid = false;
            }
        }
コード例 #4
0
        void LoadTemplateBody(string guid)
        {
            m_guid = guid;
            string datapath   = AssetDatabase.GUIDToAssetPath(guid);
            string shaderBody = string.Empty;

            shaderBody   = IOUtils.LoadTextFileFromDisk(datapath);
            shaderBody   = shaderBody.Replace("\r\n", "\n");
            m_shaderData = TemplateShaderInfoUtil.CreateShaderData(shaderBody);
            if (m_shaderData == null)
            {
                m_isValid = false;
                return;
            }

            m_templateIdManager = new TemplateIdManager(shaderBody);

            try
            {
                int nameBegin = shaderBody.IndexOf(TemplatesManager.TemplateShaderNameBeginTag);
                if (nameBegin < 0)
                {
                    // Not a template
                    return;
                }

                int nameEnd = shaderBody.IndexOf(TemplatesManager.TemplateFullEndTag, nameBegin);
                if (nameEnd < 0)
                {
                    return;
                }

                m_shaderBody = shaderBody;
                int defaultBegin  = nameBegin + TemplatesManager.TemplateShaderNameBeginTag.Length;
                int defaultLength = nameEnd - defaultBegin;
                m_defaultShaderName = shaderBody.Substring(defaultBegin, defaultLength);
                int[] nameIdx = m_defaultShaderName.AllIndexesOf("\"");
                nameIdx[0]         += 1;           // Ignore the " character from the string
                m_defaultShaderName = m_defaultShaderName.Substring(nameIdx[0], nameIdx[1] - nameIdx[0]);
                m_shaderNameId      = shaderBody.Substring(nameBegin, nameEnd + TemplatesManager.TemplateFullEndTag.Length - nameBegin);
                m_templateProperties.AddId(shaderBody, m_shaderNameId, false);
                m_templateIdManager.RegisterId(nameBegin, m_shaderNameId, m_shaderNameId);
                shaderBody = shaderBody.Substring(nameEnd + TemplatesManager.TemplateFullEndTag.Length);
            }
            catch (Exception e)
            {
                Debug.LogException(e);
                m_isValid = false;
            }

            m_propertyTag = new TemplateTagData(m_shaderData.PropertyStartIdx, TemplatesManager.TemplatePropertyTag, true);
            m_templateIdManager.RegisterId(m_shaderData.PropertyStartIdx, TemplatesManager.TemplatePropertyTag, TemplatesManager.TemplatePropertyTag);
            m_templateProperties.AddId(shaderBody, TemplatesManager.TemplatePropertyTag, true);
            Dictionary <string, TemplateShaderPropertyData> duplicatesHelper = new Dictionary <string, TemplateShaderPropertyData>();

            TemplateHelperFunctions.CreateShaderPropertiesList(m_shaderData.Properties, ref m_availableShaderProperties, ref duplicatesHelper);
            int subShaderCount = m_shaderData.SubShaders.Count;

            int mainSubShaderIdx = -1;
            int mainPassIdx      = -1;

            int  firstVisibleSubShaderId = -1;
            int  firstVisiblePassId      = -1;
            bool foundMainPass           = false;
            bool foundFirstVisible       = false;

            for (int i = 0; i < subShaderCount; i++)
            {
                TemplateSubShader subShader = new TemplateSubShader(i, m_templateIdManager, "SubShader" + i, m_shaderData.SubShaders[i], ref duplicatesHelper);

                if (subShader.FoundMainPass)
                {
                    if (!foundMainPass)
                    {
                        foundMainPass    = true;
                        mainSubShaderIdx = i;
                        mainPassIdx      = subShader.MainPass;
                    }
                }
                else if (subShader.MainPass > -1)
                {
                    if (!foundFirstVisible)
                    {
                        foundFirstVisible       = true;
                        firstVisibleSubShaderId = i;
                        firstVisiblePassId      = subShader.MainPass;
                    }
                }

                m_subShaders.Add(subShader);
                m_masterNodesRequired += subShader.Passes.Count;
            }


            if (!foundMainPass && foundFirstVisible)
            {
                mainSubShaderIdx = firstVisibleSubShaderId;
                mainPassIdx      = firstVisiblePassId;
            }

            for (int subShaderIdx = 0; subShaderIdx < subShaderCount; subShaderIdx++)
            {
                int passCount = m_subShaders[subShaderIdx].Passes.Count;
                for (int passIdx = 0; passIdx < passCount; passIdx++)
                {
                    m_subShaders[subShaderIdx].Passes[passIdx].IsMainPass = (mainSubShaderIdx == subShaderIdx && mainPassIdx == passIdx);
                }
            }
            duplicatesHelper.Clear();
            duplicatesHelper = null;
            m_isSinglePass   = (m_subShaders.Count == 1 && m_subShaders[0].PassAmount == 1);
            TemplateHelperFunctions.FetchCustomInspector(m_customInspectorContainer, m_shaderBody);
            if (m_customInspectorContainer.IsValid)
            {
                int index = m_customInspectorContainer.Id.IndexOf("CustomEditor");
                m_templateProperties.AddId(new TemplateProperty(m_customInspectorContainer.Id, m_customInspectorContainer.Id.Substring(0, index), true));
                m_templateIdManager.RegisterId(m_customInspectorContainer.Index, m_customInspectorContainer.Id, m_customInspectorContainer.Id);
            }
        }
コード例 #5
0
        void LoadTemplateBody(string guid)
        {
            m_guid = guid;
            string datapath   = AssetDatabase.GUIDToAssetPath(guid);
            string shaderBody = string.Empty;

            shaderBody   = IOUtils.LoadTextFileFromDisk(datapath);
            shaderBody   = shaderBody.Replace("\r\n", "\n");
            m_shaderData = TemplateShaderInfoUtil.CreateShaderData(shaderBody);
            if (m_shaderData == null)
            {
                m_isValid = false;
                return;
            }

            m_templateIdManager = new TemplateIdManager(shaderBody);

            try
            {
                int nameBegin = shaderBody.IndexOf(TemplatesManager.TemplateShaderNameBeginTag);
                if (nameBegin < 0)
                {
                    // Not a template
                    return;
                }

                m_shaderBody = shaderBody;
                int nameEnd       = shaderBody.IndexOf(TemplatesManager.TemplateFullEndTag, nameBegin);
                int defaultBegin  = nameBegin + TemplatesManager.TemplateShaderNameBeginTag.Length;
                int defaultLength = nameEnd - defaultBegin;
                m_defaultShaderName = shaderBody.Substring(defaultBegin, defaultLength);
                int[] nameIdx = m_defaultShaderName.AllIndexesOf("\"");
                nameIdx[0]         += 1;           // Ignore the " character from the string
                m_defaultShaderName = m_defaultShaderName.Substring(nameIdx[0], nameIdx[1] - nameIdx[0]);
                m_shaderNameId      = shaderBody.Substring(nameBegin, nameEnd + TemplatesManager.TemplateFullEndTag.Length - nameBegin);
                m_templateProperties.AddId(shaderBody, m_shaderNameId, false);
                m_templateIdManager.RegisterId(nameBegin, m_shaderNameId, m_shaderNameId);
            }
            catch (Exception e)
            {
                Debug.LogException(e);
                m_isValid = false;
            }

            m_propertyTag = new TemplateTagData(m_shaderData.PropertyStartIdx, TemplatesManager.TemplatePropertyTag, true);
            m_templateIdManager.RegisterId(m_shaderData.PropertyStartIdx, TemplatesManager.TemplatePropertyTag, TemplatesManager.TemplatePropertyTag);
            m_templateProperties.AddId(shaderBody, TemplatesManager.TemplatePropertyTag, true);
            Dictionary <string, TemplateShaderPropertyData> duplicatesHelper = new Dictionary <string, TemplateShaderPropertyData>();

            TemplateHelperFunctions.CreateShaderPropertiesList(m_shaderData.Properties, ref m_availableShaderProperties, ref duplicatesHelper);
            int subShaderCount = m_shaderData.SubShaders.Count;

            for (int i = 0; i < subShaderCount; i++)
            {
                TemplateSubShader subShader = new TemplateSubShader(i, m_templateIdManager, "SubShader" + i, m_shaderData.SubShaders[i], ref duplicatesHelper);
                m_subShaders.Add(subShader);
                m_masterNodesRequired += subShader.Passes.Count;
            }

            duplicatesHelper.Clear();
            duplicatesHelper = null;
            m_isSinglePass   = (m_subShaders.Count == 1 && m_subShaders[0].PassAmount == 1);
        }