|
|
|
|
|
|
|
|
|
|
namespace UnityEditor.Graphing.Drawing |
|
|
|
{ |
|
|
|
// TODO JOCE Derive from GraphViewEditorWindow
|
|
|
|
[NonSerialized] |
|
|
|
private Object m_Selected; |
|
|
|
|
|
|
|
[NonSerialized] |
|
|
|
private IGraphAsset m_InMemoryAsset; |
|
|
|
public abstract IGraphAsset inMemoryAsset { get; set; } |
|
|
|
public abstract Object selected { get; set; } |
|
|
|
private bool shouldRepaint |
|
|
|
private bool shouldRepaint |
|
|
|
return allowAlwaysRepaint && m_InMemoryAsset != null && m_InMemoryAsset.shouldRepaint; |
|
|
|
return allowAlwaysRepaint && inMemoryAsset != null && inMemoryAsset.shouldRepaint; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
void OnEnable() |
|
|
|
{ |
|
|
|
var source = CreateDataSource(); |
|
|
|
source.Initialize(m_InMemoryAsset, this); |
|
|
|
source.Initialize(inMemoryAsset, this); |
|
|
|
|
|
|
|
m_GraphEditorDrawer = new GraphEditorDrawer(CreateGraphView(), source); |
|
|
|
rootVisualContainer.AddChild(m_GraphEditorDrawer); |
|
|
|
|
|
|
|
|
|
|
public void PingAsset() |
|
|
|
{ |
|
|
|
if (m_Selected != null) |
|
|
|
EditorGUIUtility.PingObject(m_Selected); |
|
|
|
if (selected != null) |
|
|
|
EditorGUIUtility.PingObject(selected); |
|
|
|
if (m_Selected != null && m_InMemoryAsset != null) |
|
|
|
if (selected != null && inMemoryAsset != null) |
|
|
|
var path = AssetDatabase.GetAssetPath(m_Selected); |
|
|
|
if (string.IsNullOrEmpty(path) || m_InMemoryAsset == null) |
|
|
|
var path = AssetDatabase.GetAssetPath(selected); |
|
|
|
if (string.IsNullOrEmpty(path) || inMemoryAsset == null) |
|
|
|
var masterNode = ((MaterialGraphAsset) m_InMemoryAsset).materialGraph.masterNode; |
|
|
|
var masterNode = ((MaterialGraphAsset)inMemoryAsset).materialGraph.masterNode; |
|
|
|
if (masterNode == null) |
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
textures.Add(texture); |
|
|
|
} |
|
|
|
shaderImporter.SetNonModifiableTextures(textureNames.ToArray(), textures.ToArray()); |
|
|
|
File.WriteAllText(path, EditorJsonUtility.ToJson(m_InMemoryAsset.graph)); |
|
|
|
File.WriteAllText(path, EditorJsonUtility.ToJson(inMemoryAsset.graph)); |
|
|
|
shaderImporter.SaveAndReimport(); |
|
|
|
AssetDatabase.ImportAsset(path); |
|
|
|
|
|
|
|
|
|
|
if (!EditorUtility.IsPersistent (newSelection)) |
|
|
|
return; |
|
|
|
|
|
|
|
if (m_Selected == newSelection) |
|
|
|
if (selected == newSelection) |
|
|
|
if (m_Selected != null) |
|
|
|
if (selected != null) |
|
|
|
{ |
|
|
|
if (EditorUtility.DisplayDialog ("Save Old Graph?", "Save Old Graph?", "yes!", "no")) { |
|
|
|
UpdateAsset (); |
|
|
|
|
|
|
m_Selected = newSelection; |
|
|
|
selected = newSelection; |
|
|
|
|
|
|
|
var mGraph = CreateInstance<MaterialGraphAsset>(); |
|
|
|
var path = AssetDatabase.GetAssetPath(newSelection); |
|
|
|
|
|
|
m_InMemoryAsset = mGraph; |
|
|
|
var graph = m_InMemoryAsset.graph; |
|
|
|
inMemoryAsset = mGraph; |
|
|
|
var graph = inMemoryAsset.graph; |
|
|
|
source.Initialize (m_InMemoryAsset, this) ; |
|
|
|
source.Initialize (inMemoryAsset, this) ; |
|
|
|
m_GraphEditorDrawer.presenter = source; |
|
|
|
//m_GraphView.StretchToParentSize();
|
|
|
|
Repaint (); |
|
|
|