study/first_study/Library/PackageCache/com.unity.shadergraph@3686fafd4720/Editor/AssetCallbacks/CreateShaderSubGraph.cs
jh04010421 739d49f1a0 Unity | 2026.01.20
수업 실습 파일
2026-01-20 11:01:57 +09:00

36 lines
1.4 KiB
C#

using System.IO;
using UnityEditor.ProjectWindowCallback;
using UnityEngine;
using UnityEngine.Rendering;
namespace UnityEditor.ShaderGraph
{
class CreateShaderSubGraph : EndNameEditAction
{
[MenuItem("Assets/Create/Shader Graph/Sub Graph", priority = CoreUtils.Sections.section1 + CoreUtils.Priorities.assetsCreateShaderMenuPriority + 1)]
public static void CreateMaterialSubGraph()
{
ProjectWindowUtil.StartNameEditingIfProjectWindowExists(0, CreateInstance<CreateShaderSubGraph>(),
string.Format("New Shader Sub Graph.{0}", ShaderSubGraphImporter.Extension), ShaderSubGraphImporter.GetIcon(), null);
}
public override void Action(int instanceId, string pathName, string resourceFile)
{
var graph = new GraphData { isSubGraph = true };
var outputNode = new SubGraphOutputNode();
graph.AddNode(outputNode);
graph.outputNode = outputNode;
outputNode.AddSlot(ConcreteSlotValueType.Vector4);
graph.path = "Sub Graphs";
FileUtilities.WriteShaderGraphToDisk(pathName, graph);
AssetDatabase.Refresh();
if (ShaderGraphPreferences.GetOrPromptOpenNewGraphOnCreation())
{
var obj = AssetDatabase.LoadAssetAtPath<SubGraphAsset>(pathName);
AssetDatabase.OpenAsset(obj);
}
}
}
}