浏览代码

Inline GetShaderText

/main
Peter Bay Bastian 7 年前
当前提交
e49ccdcc
共有 1 个文件被更改,包括 16 次插入19 次删除
  1. 35
      com.unity.shadergraph/Editor/Importers/ShaderGraphImporter.cs

35
com.unity.shadergraph/Editor/Importers/ShaderGraphImporter.cs


ShaderUtil.ClearShaderErrors(oldShader);
List<PropertyCollector.TextureInfo> configuredTextures;
var text = GetShaderText(ctx.assetPath, out configuredTextures);
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);
}
internal static string GetShaderText(string path, out List<PropertyCollector.TextureInfo> configuredTextures)
{
string path = ctx.assetPath;
string shaderString = null;
var shaderName = Path.GetFileNameWithoutExtension(path);
try

configuredTextures = new List<PropertyCollector.TextureInfo>();
// ignored
}
return shaderString ?? k_ErrorShader.Replace("Hidden/GraphErrorShader2", shaderName);
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());
ctx.AddObjectToAsset("MainAsset", shader);
ctx.SetMainObject(shader);
}
}

正在加载...
取消
保存