浏览代码

Use GUID instead of object reference so that we can properly restore object link after assembly reload.

/main
Tim Cooper 7 年前
当前提交
fba42d48
共有 4 个文件被更改,包括 49 次插入23 次删除
  1. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/SubGraph/AbstractSubGraphNode.cs
  2. 58
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/MaterialGraphEditWindow.cs
  3. 6
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/GraphEditorView.cs
  4. 6
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Importers/ShaderGraphImporterEditor.cs

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/SubGraph/AbstractSubGraphNode.cs


{
foreach (var slot in subGraphOutputNode.GetInputSlots<MaterialSlot>())
{
AddSlot(MaterialSlot.CreateMaterialSlot( slot.valueType,slot.id, slot.RawDisplayName(), slot.shaderOutputName, SlotType.Output, Vector4.zero));
AddSlot(MaterialSlot.CreateMaterialSlot(slot.valueType, slot.id, slot.RawDisplayName(), slot.shaderOutputName, SlotType.Output, Vector4.zero));
validNames.Add(slot.id);
}
}

58
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/MaterialGraphEditWindow.cs


public class MaterialGraphEditWindow : EditorWindow
{
[SerializeField]
Object m_Selected;
string m_Selected;
[SerializeField]
SerializableGraphObject m_GraphObject;

}
}
public Object selected
public string selectedGuid
{
get { return m_Selected; }
private set { m_Selected = value; }

if (materialGraph == null)
return;
if (graphEditorView == null)
graphEditorView = new GraphEditorView(materialGraph, selected) { persistenceKey = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(selected)) };
{
var asset = AssetDatabase.LoadAssetAtPath<Object>(AssetDatabase.GUIDToAssetPath(selectedGuid));
graphEditorView = new GraphEditorView(materialGraph, asset.name) {persistenceKey = AssetDatabase.AssetPathToGUID(AssetDatabase.GUIDToAssetPath(selectedGuid))};
}
graphEditorView.previewManager.HandleGraphChanges();
graphEditorView.previewManager.RenderPreviews();

public void PingAsset()
{
if (selected != null)
EditorGUIUtility.PingObject(selected);
if (selectedGuid != null)
{
var path = AssetDatabase.GUIDToAssetPath(selectedGuid);
var asset = AssetDatabase.LoadAssetAtPath<Object>(path);
EditorGUIUtility.PingObject(asset);
}
if (selected != null && graphObject != null)
if (selectedGuid != null && graphObject != null)
var path = AssetDatabase.GetAssetPath(selected);
var path = AssetDatabase.GUIDToAssetPath(selectedGuid);
{
}
if (m_GraphObject.graph.GetType() == typeof(MaterialGraph))
UpdateShaderGraphOnDisk(path);

if (m_GraphObject.graph.GetType() == typeof(MasterRemapGraph))
UpdateAbstractSubgraphOnDisk<MasterRemapGraph>(path);
var windows = Resources.FindObjectsOfTypeAll<MaterialGraphEditWindow>();
foreach (var materialGraphEditWindow in windows)
{
materialGraphEditWindow.Rebuild();
}
}
}

AssetDatabase.ImportAsset(path);
}
public void ChangeSelection(Object newSelection, Type graphType)
private void Rebuild()
{
if (graphObject != null && graphObject.graph != null)
{
var subNodes = graphObject.graph.GetNodes<AbstractSubGraphNode>();
foreach (var node in subNodes)
node.UpdateSlots();
}
}
public void ChangeSelection(string newSelectionGuid, Type graphType)
if (!EditorUtility.IsPersistent(newSelection))
var asset = AssetDatabase.LoadAssetAtPath<Object>(AssetDatabase.GUIDToAssetPath(newSelectionGuid));
if (asset == null)
return;
if (!EditorUtility.IsPersistent(asset))
if (selected == newSelection)
if (selectedGuid == newSelectionGuid)
selected = newSelection;
selectedGuid = newSelectionGuid;
var path = AssetDatabase.GetAssetPath(newSelection);
var path = AssetDatabase.GetAssetPath(asset);
var textGraph = File.ReadAllText(path, Encoding.UTF8);
graphObject = CreateInstance<SerializableGraphObject>();
graphObject.hideFlags = HideFlags.HideAndDontSave;

graphEditorView = new GraphEditorView(m_GraphObject.graph as AbstractMaterialGraph, selected) { persistenceKey = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(selected)) };
graphEditorView = new GraphEditorView(m_GraphObject.graph as AbstractMaterialGraph, asset.name) { persistenceKey = AssetDatabase.GUIDToAssetPath(selectedGuid) };
titleContent = new GUIContent(selected.name);
titleContent = new GUIContent(asset.name);
Repaint();
}

6
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/GraphEditorView.cs


get { return m_GraphInspectorView; }
}
public GraphEditorView(AbstractMaterialGraph graph, Object asset)
public GraphEditorView(AbstractMaterialGraph graph, string assetName)
{
m_Graph = graph;
AddStyleSheetPath("Styles/MaterialGraph");

var textureInfo = new List<PropertyCollector.TextureInfo>();
PreviewMode previewMode;
string shader = graph.GetShader(copyFromNode, GenerationMode.ForReals, asset.name, out textureInfo, out previewMode);
string shader = graph.GetShader(copyFromNode, GenerationMode.ForReals, assetName, out textureInfo, out previewMode);
GUIUtility.systemCopyBuffer = shader;
}
));

m_GraphView.AddManipulator(new GraphDropTarget(graph));
content.Add(m_GraphView);
m_GraphInspectorView = new GraphInspectorView(asset.name, previewManager, graph) { name = "inspector" };
m_GraphInspectorView = new GraphInspectorView(assetName, previewManager, graph) { name = "inspector" };
m_GraphView.onSelectionChanged += m_GraphInspectorView.UpdateSelection;
content.Add(m_GraphInspectorView);

6
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Importers/ShaderGraphImporterEditor.cs


internal static bool ShowGraphEditWindow(string path)
{
var asset = AssetDatabase.LoadAssetAtPath<Object>(path);
var guid = AssetDatabase.AssetPathToGUID(path);
var extension = Path.GetExtension(path);
Type graphType;
if (extension == ".ShaderGraph")

var foundWindow = false;
foreach (var w in Resources.FindObjectsOfTypeAll<MaterialGraphEditWindow>())
{
if (w.selected == asset)
if (w.selectedGuid == guid)
{
foundWindow = true;
w.Focus();

{
var window = ScriptableObject.CreateInstance<MaterialGraphEditWindow>();
window.Show();
window.ChangeSelection(asset, graphType);
window.ChangeSelection(guid, graphType);
}
return true;
}

正在加载...
取消
保存