Skip to content

Commit 28a73e2

Browse files
committed
Shaders are searched for #include_with_pragmas references in addition to #include references
1 parent c7e5246 commit 28a73e2

3 files changed

Lines changed: 25 additions & 21 deletions

File tree

Plugins/AssetUsageDetector/Editor/AssetUsageDetectorSearchFunctions.cs

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,7 +1121,7 @@ private ReferenceNode SearchShaderGraph( Object unityObject )
11211121
{
11221122
// New Shader Graph serialization format is used: https://github.com/Unity-Technologies/Graphics/pull/222
11231123
// Iterate over all these occurrences: "guid\": \"GUID_VALUE\" (\" is used instead of " because it is a nested JSON)
1124-
IterateOverValuesInString( graphJson, "\"guid\\\"", '"', ( guid ) =>
1124+
IterateOverValuesInString( graphJson, new string[] { "\"guid\\\"" }, '"', ( guid ) =>
11251125
{
11261126
if( guid.Length > 1 )
11271127
{
@@ -1141,7 +1141,7 @@ private ReferenceNode SearchShaderGraph( Object unityObject )
11411141
if( shaderIncludesToSearchSet.Count > 0 )
11421142
{
11431143
// Iterate over all these occurrences: "m_FunctionSource": "GUID_VALUE" (this one is not nested JSON)
1144-
IterateOverValuesInString( graphJson, "\"m_FunctionSource\"", '"', ( guid ) =>
1144+
IterateOverValuesInString( graphJson, new string[] { "\"m_FunctionSource\"" }, '"', ( guid ) =>
11451145
{
11461146
string referencePath = AssetDatabase.GUIDToAssetPath( guid );
11471147
if( !string.IsNullOrEmpty( referencePath ) && assetsToSearchPathsSet.Contains( referencePath ) )
@@ -1324,8 +1324,8 @@ private void SearchShaderSourceCodeForCGIncludes( ReferenceNode referenceNode )
13241324
{
13251325
string shaderPath = AssetDatabase.GetAssetPath( (Object) referenceNode.nodeObject );
13261326

1327-
// Iterate over all these occurrences: #include: "INCLUDE_REFERENCE"
1328-
IterateOverValuesInString( File.ReadAllText( shaderPath ), "#include ", '"', ( include ) =>
1327+
// Iterate over all these occurrences: #include "INCLUDE_REFERENCE" or #include_with_pragmas "INCLUDE_REFERENCE"
1328+
IterateOverValuesInString( File.ReadAllText( shaderPath ), new string[] { "#include ", "#include_with_pragmas " }, '"', ( include ) =>
13291329
{
13301330
bool isIncludePotentialReference = shaderIncludesToSearchSet.Contains( include );
13311331
if( !isIncludePotentialReference )
@@ -1744,26 +1744,30 @@ private object GetFieldValue( object source, string fieldName, int arrayIndex )
17441744
// Iterates over all occurrences of specific key-value pairs in string
17451745
// Example1: #include "VALUE" valuePrefix=#include, valueWrapperChar="
17461746
// Example2: "guid": "VALUE" valuePrefix="guid", valueWrapperChar="
1747-
private void IterateOverValuesInString( string str, string valuePrefix, char valueWrapperChar, Action<string> valueAction )
1747+
private void IterateOverValuesInString( string str, string[] valuePrefixes, char valueWrapperChar, Action<string> valueAction )
17481748
{
1749-
int valueStartIndex, valueEndIndex = 0;
1750-
while( true )
1749+
for( int i = 0; i < valuePrefixes.Length; i++ )
17511750
{
1752-
valueStartIndex = str.IndexOf( valuePrefix, valueEndIndex );
1753-
if( valueStartIndex < 0 )
1754-
return;
1751+
string valuePrefix = valuePrefixes[i];
1752+
int valueStartIndex, valueEndIndex = 0;
1753+
while( true )
1754+
{
1755+
valueStartIndex = str.IndexOf( valuePrefix, valueEndIndex );
1756+
if( valueStartIndex < 0 )
1757+
break;
17551758

1756-
valueStartIndex = str.IndexOf( valueWrapperChar, valueStartIndex + valuePrefix.Length );
1757-
if( valueStartIndex < 0 )
1758-
return;
1759+
valueStartIndex = str.IndexOf( valueWrapperChar, valueStartIndex + valuePrefix.Length );
1760+
if( valueStartIndex < 0 )
1761+
break;
17591762

1760-
valueStartIndex++;
1761-
valueEndIndex = str.IndexOf( valueWrapperChar, valueStartIndex );
1762-
if( valueEndIndex < 0 )
1763-
return;
1763+
valueStartIndex++;
1764+
valueEndIndex = str.IndexOf( valueWrapperChar, valueStartIndex );
1765+
if( valueEndIndex < 0 )
1766+
break;
17641767

1765-
if( valueEndIndex > valueStartIndex )
1766-
valueAction( str.Substring( valueStartIndex, valueEndIndex - valueStartIndex ) );
1768+
if( valueEndIndex > valueStartIndex )
1769+
valueAction( str.Substring( valueStartIndex, valueEndIndex - valueStartIndex ) );
1770+
}
17671771
}
17681772
}
17691773

Plugins/AssetUsageDetector/README.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
= Asset Usage Detector =
1+
= Asset Usage Detector (v2.2.3) =
22

33
Online documentation available at: https://github.com/yasirkula/UnityAssetUsageDetector
44
E-mail: yasirkula@gmail.com

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "com.yasirkula.assetusagedetector",
33
"displayName": "Asset Usage Detector",
4-
"version": "2.2.2",
4+
"version": "2.2.3",
55
"documentationUrl": "https://github.com/yasirkula/UnityAssetUsageDetector",
66
"changelogUrl": "https://github.com/yasirkula/UnityAssetUsageDetector/releases",
77
"licensesUrl": "https://github.com/yasirkula/UnityAssetUsageDetector/blob/master/LICENSE.txt",

0 commit comments

Comments
 (0)