Example #1
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);
            }
        }
Example #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 ):
			
		}
Example #3
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);
        }