|
|
|
|
|
|
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(); |
|
|
|
} |
|
|
|