浏览代码

ShaderGraph window now loads properly between Editor sessions #49

/main
Peter Bay Bastian 7 年前
当前提交
3fdee329
共有 2 个文件被更改,包括 36 次插入20 次删除
  1. 40
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/MaterialGraphEditWindow.cs
  2. 16
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Importers/ShaderGraphImporterEditor.cs

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


void Update()
{
if (graphObject == null && selectedGuid != null)
{
var guid = selectedGuid;
selectedGuid = null;
ChangeSelection(guid);
}
var materialGraph = graphObject.graph as AbstractMaterialGraph;
if (materialGraph == null)
return;

graphEditorView = new GraphEditorView(materialGraph, asset.name) {persistenceKey = AssetDatabase.AssetPathToGUID(AssetDatabase.GUIDToAssetPath(selectedGuid))};
graphEditorView = new GraphEditorView(materialGraph, asset.name) { persistenceKey = AssetDatabase.AssetPathToGUID(AssetDatabase.GUIDToAssetPath(selectedGuid)) };
}
graphEditorView.HandleGraphChanges();

Mathf.Min(bounds.yMin, center.y),
Mathf.Max(bounds.xMax, center.x),
Mathf.Max(bounds.yMax, center.y));
}
var middle = bounds.center;
bounds.center = Vector2.zero;

var uniqueIncomingEdges = externalOutputSlots.GroupBy(
edge => edge.outputSlot,
edge => edge,
(key, edges) => new {slotRef = key, edges = edges.ToList()});
(key, edges) => new { slotRef = key, edges = edges.ToList() });
var externalInputNeedingConnection = new List<KeyValuePair<IEdge, IShaderProperty>>();
foreach (var group in uniqueIncomingEdges)

var uniqueOutgoingEdges = externalInputSlots.GroupBy(
edge => edge.inputSlot,
edge => edge,
(key, edges) => new {slot = key, edges = edges.ToList()});
(key, edges) => new { slot = key, edges = edges.ToList() });
var externalOutputsNeedingConnection = new List<KeyValuePair<IEdge, IEdge>>();
foreach (var group in uniqueOutgoingEdges)

}
}
public void ChangeSelection(string newSelectionGuid, Type graphType)
public void ChangeSelection(string newSelectionGuid)
{
var asset = AssetDatabase.LoadAssetAtPath<Object>(AssetDatabase.GUIDToAssetPath(newSelectionGuid));
if (asset == null)

if (selectedGuid == newSelectionGuid)
return;
var path = AssetDatabase.GetAssetPath(asset);
var extension = Path.GetExtension(path);
Type graphType;
switch (extension)
{
case ".ShaderGraph":
graphType = typeof(MaterialGraph);
break;
case ".LayeredShaderGraph":
graphType = typeof(LayeredShaderGraph);
break;
case ".ShaderSubGraph":
graphType = typeof(SubGraph);
break;
case ".ShaderRemapGraph":
graphType = typeof(MasterRemapGraph);
break;
default:
return;
}
var path = AssetDatabase.GetAssetPath(asset);
var textGraph = File.ReadAllText(path, Encoding.UTF8);
graphObject = CreateInstance<SerializableGraphObject>();
graphObject.hideFlags = HideFlags.HideAndDontSave;

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


{
var guid = AssetDatabase.AssetPathToGUID(path);
var extension = Path.GetExtension(path);
Type graphType;
if (extension == ".ShaderGraph")
graphType = typeof(MaterialGraph);
else if (extension == ".LayeredShaderGraph")
graphType = typeof(LayeredShaderGraph);
else if (extension == ".ShaderSubGraph")
graphType = typeof(SubGraph);
else if (extension == ".ShaderRemapGraph")
graphType = typeof(MasterRemapGraph);
else
if (extension != ".ShaderGraph" && extension != ".LayeredShaderGraph" && extension != ".ShaderSubGraph" && extension != ".ShaderRemapGraph")
return false;
var foundWindow = false;

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

var path = AssetDatabase.GetAssetPath(instanceID);
return ShowGraphEditWindow(path);
}
}
正在加载...
取消
保存