浏览代码

Add dependency interface and importer implementation

/main
Peter Bay Bastian 7 年前
当前提交
fce56481
共有 3 个文件被更改,包括 21 次插入1 次删除
  1. 3
      com.unity.shadergraph/Editor/Data/Nodes/AbstractMaterialNode.cs
  2. 9
      com.unity.shadergraph/Editor/Importers/ShaderGraphImporter.cs
  3. 10
      com.unity.shadergraph/Editor/Importers/ShaderSubGraphImporter.cs

3
com.unity.shadergraph/Editor/Data/Nodes/AbstractMaterialNode.cs


var slot = FindSlot<MaterialSlot>(slotId);
return slot != null && owner.GetEdges(slot.slotReference).Any();
}
public virtual void GetSourceAssetDependencies(List<string> paths)
{}
}
}

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


using UnityEditor.Experimental.AssetImporters;
using UnityEditor.ShaderGraph.Drawing;
[ScriptedImporter(14, ShaderGraphImporter.ShaderGraphExtension)]
[ScriptedImporter(14, ShaderGraphExtension)]
public class ShaderGraphImporter : ScriptedImporter
{
public const string ShaderGraphExtension = "shadergraph";

List<PropertyCollector.TextureInfo> configuredTextures;
string path = ctx.assetPath;
string shaderString = null;
var sourceAssetDependencyPaths = new List<string>();
var shaderName = Path.GetFileNameWithoutExtension(path);
try
{

if (!string.IsNullOrEmpty(graph.path))
shaderName = graph.path + "/" + shaderName;
shaderString = graph.GetShader(shaderName, GenerationMode.ForReals, out configuredTextures);
foreach (var node in graph.GetNodes<AbstractMaterialNode>())
node.GetSourceAssetDependencies(sourceAssetDependencyPaths);
}
catch (Exception)
{

ctx.AddObjectToAsset("MainAsset", shader);
ctx.SetMainObject(shader);
foreach (var sourceAssetDependencyPath in sourceAssetDependencyPaths.Distinct())
ctx.DependsOnSourceAsset(sourceAssetDependencyPath);
}
}

10
com.unity.shadergraph/Editor/Importers/ShaderSubGraphImporter.cs


using System.Collections.Generic;
using System.Linq;
using System.Text;
[ScriptedImporter(1, "ShaderSubGraph")]

if (graph == null)
return;
var sourceAssetDependencyPaths = new List<string>();
foreach (var node in graph.GetNodes<AbstractMaterialNode>())
node.GetSourceAssetDependencies(sourceAssetDependencyPaths);
foreach (var sourceAssetDependencyPath in sourceAssetDependencyPaths.Distinct())
ctx.DependsOnSourceAsset(sourceAssetDependencyPath);
}
}
正在加载...
取消
保存