Skip to content

Commit 0b0f83e

Browse files
committed
Added checks for correct path
1 parent b62b417 commit 0b0f83e

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

Editor/ShaderGenerator.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ public static void GenerateShader(string path, ModularShader shader, bool hideVa
3131
/// <param name="hideVariants">Hide variants from the shader selector on the material, showing only the shader with all variants disabled from the menu</param>
3232
public static void GenerateShader(string path, ModularShader shader, Action<StringBuilder, ShaderContext> postGeneration, bool hideVariants = false)
3333
{
34+
35+
path = GetPathRelativeToProject(path);
36+
3437
var modules = FindAllModules(shader);
3538

3639
// Countermeasure for unity dogshit scriptedImporter assets reimport/update system
@@ -95,6 +98,20 @@ public static void GenerateShader(string path, ModularShader shader, Action<Stri
9598
AssetDatabase.Refresh();
9699
}
97100

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+
98115
/// <summary>
99116
/// Generates a shader for selected materials
100117
/// </summary>
@@ -104,6 +121,8 @@ public static void GenerateShader(string path, ModularShader shader, Action<Stri
104121
/// <param name="postGeneration">Actions to performs post generation and before cleanup </param>
105122
public static void GenerateMinimalShader(string path, ModularShader shader, IEnumerable<Material> materials, Action<StringBuilder, ShaderContext> postGeneration = null)
106123
{
124+
path = GetPathRelativeToProject(path);
125+
107126
var modules = FindAllModules(shader);
108127
var possibleVariants = GetMinimalVariants(modules, materials);
109128
var contexts = new List<ShaderContext>();
@@ -136,6 +155,8 @@ public static void GenerateMinimalShader(string path, ModularShader shader, IEnu
136155
/// <param name="postGeneration">Actions to performs post generation and before cleanup </param>
137156
public static List<ShaderContext> EnqueueShadersToGenerate(string path, ModularShader shader, IEnumerable<Material> materials, Action<StringBuilder, ShaderContext> postGeneration = null)
138157
{
158+
path = GetPathRelativeToProject(path);
159+
139160
var modules = FindAllModules(shader);
140161
var possibleVariants = GetMinimalVariants(modules, materials);
141162
var contexts = new List<ShaderContext>();

0 commit comments

Comments
 (0)