@@ -31,6 +31,9 @@ public static void GenerateShader(string path, ModularShader shader, bool hideVa
31
31
/// <param name="hideVariants">Hide variants from the shader selector on the material, showing only the shader with all variants disabled from the menu</param>
32
32
public static void GenerateShader ( string path , ModularShader shader , Action < StringBuilder , ShaderContext > postGeneration , bool hideVariants = false )
33
33
{
34
+
35
+ path = GetPathRelativeToProject ( path ) ;
36
+
34
37
var modules = FindAllModules ( shader ) ;
35
38
36
39
// Countermeasure for unity dogshit scriptedImporter assets reimport/update system
@@ -95,6 +98,20 @@ public static void GenerateShader(string path, ModularShader shader, Action<Stri
95
98
AssetDatabase . Refresh ( ) ;
96
99
}
97
100
101
+ private static string GetPathRelativeToProject ( string path )
102
+ {
103
+ if ( ! Directory . Exists ( path ) )
104
+ throw new DirectoryNotFoundException ( $ "The folder \" { path } \" is not found") ;
105
+
106
+ if ( ! path . Contains ( Application . dataPath ) && ! path . StartsWith ( "Assets" ) )
107
+ throw new DirectoryNotFoundException ( $ "The folder \" { path } \" is not part of the unity project") ;
108
+
109
+ if ( ! path . StartsWith ( "Assets" ) )
110
+ path = path . Replace ( Application . dataPath , "" ) ;
111
+
112
+ return path ;
113
+ }
114
+
98
115
/// <summary>
99
116
/// Generates a shader for selected materials
100
117
/// </summary>
@@ -104,6 +121,8 @@ public static void GenerateShader(string path, ModularShader shader, Action<Stri
104
121
/// <param name="postGeneration">Actions to performs post generation and before cleanup </param>
105
122
public static void GenerateMinimalShader ( string path , ModularShader shader , IEnumerable < Material > materials , Action < StringBuilder , ShaderContext > postGeneration = null )
106
123
{
124
+ path = GetPathRelativeToProject ( path ) ;
125
+
107
126
var modules = FindAllModules ( shader ) ;
108
127
var possibleVariants = GetMinimalVariants ( modules , materials ) ;
109
128
var contexts = new List < ShaderContext > ( ) ;
@@ -136,6 +155,8 @@ public static void GenerateMinimalShader(string path, ModularShader shader, IEnu
136
155
/// <param name="postGeneration">Actions to performs post generation and before cleanup </param>
137
156
public static List < ShaderContext > EnqueueShadersToGenerate ( string path , ModularShader shader , IEnumerable < Material > materials , Action < StringBuilder , ShaderContext > postGeneration = null )
138
157
{
158
+ path = GetPathRelativeToProject ( path ) ;
159
+
139
160
var modules = FindAllModules ( shader ) ;
140
161
var possibleVariants = GetMinimalVariants ( modules , materials ) ;
141
162
var contexts = new List < ShaderContext > ( ) ;
0 commit comments