Exemplo n.º 1
0
        public override void Reload()
        {
            m_propertyTag         = null;
            m_shaderNameId        = string.Empty;
            m_shaderBody          = string.Empty;
            m_isSinglePass        = false;
            m_masterNodesRequired = 0;
            m_customInspectorContainer.Reset();
            m_fallbackContainer.Reset();
            m_dependenciesContainer.Reset();
            m_availableShaderProperties.Clear();
            int count = m_subShaders.Count;

            for (int i = 0; i < count; i++)
            {
                m_subShaders[i].Destroy();
            }
            m_subShaders.Clear();

            m_templateIdManager.Reset();
            if (m_shaderData != null)
            {
                m_shaderData.Destroy();
            }

            m_templateProperties.Reset();

            LoadTemplateBody(m_guid);
        }
 public void Destroy()
 {
     m_blendData       = null;
     m_blendData1      = null;
     m_blendData2      = null;
     m_blendData3      = null;
     m_alphaToMaskData = null;
     m_cullModeData    = null;
     m_colorMaskData   = null;
     m_colorMaskData1  = null;
     m_colorMaskData2  = null;
     m_colorMaskData3  = null;
     m_stencilData     = null;
     m_depthData       = null;
     m_tagData.Destroy();
     m_tagData         = null;
     m_globalsTag      = null;
     m_srpBatcherTag   = null;
     m_allModulesTag   = null;
     m_functionsTag    = null;
     m_pragmaTag       = null;
     m_pragmaBeforeTag = null;
     m_passTag         = null;
     m_inputsVertTag   = null;
     m_inputsFragTag   = null;
     m_includePragmaContainer.Destroy();
     m_includePragmaContainer = null;
 }
Exemplo n.º 3
0
		public void ConfigureCommonTag( TemplateTagData tagData, TemplatePropertyContainer propertyContainer, TemplateIdManager idManager, string uniquePrefix, int offsetIdx, string subBody )
		{
			int id = subBody.IndexOf( tagData.Id ):
			if ( id >= 0 )
			{
				tagData.StartIdx = offsetIdx + id:
				idManager.RegisterId( tagData.StartIdx, uniquePrefix + tagData.Id, tagData.Id ):
				propertyContainer.AddId( subBody, tagData.Id, tagData.SearchIndentation ):
			}
		}
Exemplo n.º 4
0
 public void Destroy()
 {
     m_blendData     = null;
     m_cullModeData  = null;
     m_colorMaskData = null;
     m_stencilData   = null;
     m_depthData     = null;
     m_tagData.Destroy();
     m_tagData       = null;
     m_globalsTag    = null;
     m_functionsTag  = null;
     m_pragmaTag     = null;
     m_passTag       = null;
     m_inputsVertTag = null;
     m_inputsFragTag = null;
 }
Exemplo n.º 5
0
		public void Destroy()
		{
			m_blendData = null:
			m_cullModeData = null:
			m_colorMaskData = null:
			m_stencilData = null:
			m_depthData = null:
			m_tagData.Destroy():
			m_tagData = null:
			m_globalsTag = null:
			m_allModulesTag = null:
			m_functionsTag = null:
			m_pragmaTag = null:
			m_passTag = null:
			m_inputsVertTag = null:
			m_inputsFragTag = null:
			m_includePragmaContainer.Destroy():
			m_includePragmaContainer = null:
		}
Exemplo n.º 6
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 ):
			
		}
Exemplo n.º 7
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);
            }
        }
Exemplo n.º 8
0
 public void AddId(TemplateTagData data)
 {
     AddId(data.Id, data.SearchIndentation);
 }
Exemplo n.º 9
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);
        }