您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 

33 行
1.1 KiB

using System.Collections.Generic;
using UnityEditor.Experimental.AssetImporters;
using UnityEditor.ShaderGraph;
using UnityEngine;
using System.IO;
using System.Linq;
using System.Text;
[ScriptedImporter(1, "ShaderSubGraph")]
public class ShaderSubGraphImporter : ScriptedImporter
{
public override void OnImportAsset(AssetImportContext ctx)
{
var textGraph = File.ReadAllText(ctx.assetPath, Encoding.UTF8);
var graph = JsonUtility.FromJson<SubGraph>(textGraph);
if (graph == null)
return;
var sourceAssetDependencyPaths = new List<string>();
foreach (var node in graph.GetNodes<AbstractMaterialNode>())
node.GetSourceAssetDependencies(sourceAssetDependencyPaths);
var graphAsset = ScriptableObject.CreateInstance<MaterialSubGraphAsset>();
graphAsset.subGraph = graph;
ctx.AddObjectToAsset("MainAsset", graphAsset);
ctx.SetMainObject(graphAsset);
foreach (var sourceAssetDependencyPath in sourceAssetDependencyPaths.Distinct())
ctx.DependsOnSourceAsset(sourceAssetDependencyPath);
}
}