|
|
|
|
|
|
|
|
|
|
List<PropertyCollector.TextureInfo> configuredTextures; |
|
|
|
string path = ctx.assetPath; |
|
|
|
string shaderString = null; |
|
|
|
var text = GetShaderText(path, out configuredTextures, sourceAssetDependencyPaths); |
|
|
|
var shader = ShaderUtil.CreateShaderAsset(text); |
|
|
|
|
|
|
|
EditorMaterialUtility.SetShaderDefaults( |
|
|
|
shader, |
|
|
|
configuredTextures.Where(x => x.modifiable).Select(x => x.name).ToArray(), |
|
|
|
configuredTextures.Where(x => x.modifiable).Select(x => EditorUtility.InstanceIDToObject(x.textureId) as Texture).ToArray()); |
|
|
|
EditorMaterialUtility.SetShaderNonModifiableDefaults( |
|
|
|
shader, |
|
|
|
configuredTextures.Where(x => !x.modifiable).Select(x => x.name).ToArray(), |
|
|
|
configuredTextures.Where(x => !x.modifiable).Select(x => EditorUtility.InstanceIDToObject(x.textureId) as Texture).ToArray()); |
|
|
|
|
|
|
|
ctx.AddObjectToAsset("MainAsset", shader); |
|
|
|
ctx.SetMainObject(shader); |
|
|
|
|
|
|
|
foreach (var sourceAssetDependencyPath in sourceAssetDependencyPaths.Distinct()) |
|
|
|
ctx.DependsOnSourceAsset(sourceAssetDependencyPath); |
|
|
|
} |
|
|
|
|
|
|
|
internal static string GetShaderText(string path, out List<PropertyCollector.TextureInfo> configuredTextures, List<string> sourceAssetDependencyPaths) |
|
|
|
{ |
|
|
|
string shaderString = null; |
|
|
|
var shaderName = Path.GetFileNameWithoutExtension(path); |
|
|
|
try |
|
|
|
{ |
|
|
|
|
|
|
shaderName = graph.path + "/" + shaderName; |
|
|
|
shaderString = graph.GetShader(shaderName, GenerationMode.ForReals, out configuredTextures, sourceAssetDependencyPaths); |
|
|
|
|
|
|
|
foreach (var node in graph.GetNodes<AbstractMaterialNode>()) |
|
|
|
node.GetSourceAssetDependencies(sourceAssetDependencyPaths); |
|
|
|
if (sourceAssetDependencyPaths != null) |
|
|
|
{ |
|
|
|
foreach (var node in graph.GetNodes<AbstractMaterialNode>()) |
|
|
|
node.GetSourceAssetDependencies(sourceAssetDependencyPaths); |
|
|
|
} |
|
|
|
} |
|
|
|
catch (Exception) |
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
var text = shaderString ?? k_ErrorShader.Replace("Hidden/GraphErrorShader2", shaderName); |
|
|
|
var shader = ShaderUtil.CreateShaderAsset(text); |
|
|
|
|
|
|
|
EditorMaterialUtility.SetShaderDefaults( |
|
|
|
shader, |
|
|
|
configuredTextures.Where(x => x.modifiable).Select(x => x.name).ToArray(), |
|
|
|
configuredTextures.Where(x => x.modifiable).Select(x => EditorUtility.InstanceIDToObject(x.textureId) as Texture).ToArray()); |
|
|
|
EditorMaterialUtility.SetShaderNonModifiableDefaults( |
|
|
|
shader, |
|
|
|
configuredTextures.Where(x => !x.modifiable).Select(x => x.name).ToArray(), |
|
|
|
configuredTextures.Where(x => !x.modifiable).Select(x => EditorUtility.InstanceIDToObject(x.textureId) as Texture).ToArray()); |
|
|
|
return shaderString ?? k_ErrorShader.Replace("Hidden/GraphErrorShader2", shaderName); |
|
|
|
} |
|
|
|
ctx.AddObjectToAsset("MainAsset", shader); |
|
|
|
ctx.SetMainObject(shader); |
|
|
|
|
|
|
|
foreach (var sourceAssetDependencyPath in sourceAssetDependencyPaths.Distinct()) |
|
|
|
ctx.DependsOnSourceAsset(sourceAssetDependencyPath); |
|
|
|
internal static string GetShaderText(string path, out List<PropertyCollector.TextureInfo> configuredTextures) |
|
|
|
{ |
|
|
|
return GetShaderText(path, out configuredTextures, null); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|