浏览代码

Started the functionality for opening shader code in user set, text editor

/main
Peter Bay Bastian 7 年前
当前提交
10d61e23
共有 2 个文件被更改,包括 95 次插入0 次删除
  1. 87
      ShaderGraph/com.unity.shadergraph/Editor/Drawing/MaterialGraphEditWindow.cs
  2. 8
      ShaderGraph/com.unity.shadergraph/Editor/Drawing/Views/GraphEditorView.cs

87
ShaderGraph/com.unity.shadergraph/Editor/Drawing/MaterialGraphEditWindow.cs


using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;

using UnityEditor.Graphing;
using UnityEditorInternal;
using Debug = UnityEngine.Debug;
using Object = UnityEngine.Object;
using Edge = UnityEditor.Experimental.UIElements.GraphView.Edge;
#if UNITY_2018_1

m_GraphEditorView.saveRequested += UpdateAsset;
m_GraphEditorView.convertToSubgraphRequested += ToSubGraph;
m_GraphEditorView.showInProjectRequested += PingAsset;
m_GraphEditorView.showGeneratedCode += ShowGeneratedCode;
this.GetRootVisualContainer().Add(graphEditorView);
}
}

materialGraphEditWindow.Rebuild();
}
}
}
public void ShowGeneratedCode()
{
var asset = AssetDatabase.LoadAssetAtPath<Object>(AssetDatabase.GUIDToAssetPath(selectedGuid));
Debug.Log(asset.name);
string path = String.Format("Temp/GeneratedFromGraph-{0}.shader", asset.name);
//Debug.Log(path);
WriteStringToFile(path);
/*
if (!WriteStringToFile(compiledShader, path, kNotAtomic, kFileFlagDontIndex | kFileFlagTemporary))
return;
path = PathToAbsolutePath(path);
if (!OpenScriptFile(path, 0))
WarningStringWithoutStacktrace("Unable to open " + path + ": Check external editor in preferences");
*/
//core::string path = Format("Temp/GeneratedFromSurface-%s.shader", shader->GetOutputFilename().c_str());
}
private void WriteStringToFile(string path)
{
List<PropertyCollector.TextureInfo> textureInfo;
var graphView = graphEditorView.graphView;
foreach (AbstractMaterialNode node in graphView.graph.GetNodes<AbstractMaterialNode>())
{
var masterNode = node as IMasterNode;
if (masterNode != null)
{
Debug.Log(path);
var shader = masterNode.GetShader(GenerationMode.ForReals, node.name, out textureInfo);
Debug.Log(shader);
//GUIUtility.systemCopyBuffer = shader;
File.WriteAllText(path, shader);
Debug.Log(ScriptEditorUtility.GetExternalScriptEditor());
string file = Path.GetFullPath(path);
ProcessStartInfo pi = new ProcessStartInfo(file);
pi.Arguments = Path.GetFileName(file);
pi.UseShellExecute = true;
pi.WorkingDirectory = Path.GetDirectoryName(file);
pi.FileName = ScriptEditorUtility.GetExternalScriptEditor();
pi.Verb = "OPEN";
Process.Start(pi);
}
}
// var nodes = graphView.selection.OfType<MaterialNodeView>().Where(x => (x.node is AbstractMaterialNode));
// Debug.Log(nodes.Length);
// foreach (var node in nodes)
// {
// var masterNode = node as IMasterNode;
// if (masterNode != null)
// {
// Debug.Log(path);
// var shader = masterNode.GetShader(GenerationMode.ForReals, node.name, out textureInfo);
// Debug.Log(shader);
// //GUIUtility.systemCopyBuffer = shader;
// File.WriteAllText(path, shader);
// //}
// }
//File tmpFile = new File;
// else if (atomicMode == kNotAtomic)
// {
// DeleteFile(path);
// tmpFilePath = path;
// }
}
public void ToSubGraph()

8
ShaderGraph/com.unity.shadergraph/Editor/Drawing/Views/GraphEditorView.cs


public Action showInProjectRequested { get; set; }
public Action showGeneratedCode { get; set; }
public MaterialGraphView graphView
{
get { return m_GraphView; }

{
if (showInProjectRequested != null)
showInProjectRequested();
}
GUILayout.Space(6);
if (GUILayout.Button("Show Generated Code", EditorStyles.toolbarButton))
{
if (showGeneratedCode != null)
showGeneratedCode();
}
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();

正在加载...
取消
保存