您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
58 行
1.8 KiB
58 行
1.8 KiB
using System.IO;
|
|
using UnityEditor;
|
|
using UnityEditor.Callbacks;
|
|
using UnityEditor.Experimental.AssetImporters;
|
|
using UnityEditor.ShaderGraph.Drawing;
|
|
using UnityEngine;
|
|
|
|
namespace UnityEditor.ShaderGraph
|
|
{
|
|
|
|
[CustomEditor(typeof(ShaderGraphImporter))]
|
|
public class ShaderGraphImporterEditor : ScriptedImporterEditor
|
|
{
|
|
public override void OnInspectorGUI()
|
|
{
|
|
if (GUILayout.Button("Open Shader Editor"))
|
|
{
|
|
AssetImporter importer = target as AssetImporter;
|
|
Debug.Assert(importer != null, "importer != null");
|
|
ShowGraphEditWindow(importer.assetPath);
|
|
}
|
|
}
|
|
|
|
internal static bool ShowGraphEditWindow(string path)
|
|
{
|
|
var guid = AssetDatabase.AssetPathToGUID(path);
|
|
var extension = Path.GetExtension(path);
|
|
if (extension != ".ShaderGraph" && extension != ".LayeredShaderGraph" && extension != ".ShaderSubGraph" && extension != ".ShaderRemapGraph")
|
|
return false;
|
|
|
|
var foundWindow = false;
|
|
foreach (var w in Resources.FindObjectsOfTypeAll<MaterialGraphEditWindow>())
|
|
{
|
|
if (w.selectedGuid == guid)
|
|
{
|
|
foundWindow = true;
|
|
w.Focus();
|
|
}
|
|
}
|
|
|
|
if (!foundWindow)
|
|
{
|
|
var window = CreateInstance<MaterialGraphEditWindow>();
|
|
window.Show();
|
|
window.Initialize(guid);
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
[OnOpenAsset(0)]
|
|
public static bool OnOpenAsset(int instanceID, int line)
|
|
{
|
|
var path = AssetDatabase.GetAssetPath(instanceID);
|
|
return ShowGraphEditWindow(path);
|
|
}
|
|
}
|
|
}
|