浏览代码

Graph edit window now survives serialization.

/main
Tim Cooper 8 年前
当前提交
eac70c08
共有 4 个文件被更改,包括 43 次插入28 次删除
  1. 40
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/AbstractGraphEditWindow.cs
  2. 5
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/GraphEditWindow.cs
  3. 23
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/MaterialGraphEditWindow.cs
  4. 3
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Graphs/MaterialGraphAsset.cs

40
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/AbstractGraphEditWindow.cs


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

5
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/GraphEditWindow.cs


using UnityEngine;
using UnityEngine.Graphing;
namespace UnityEditor.Graphing.Drawing

public override IGraphAsset inMemoryAsset { get; set; }
public override Object selected { get; set; }
public GraphEditWindow(string path)
{

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


using System;
using UnityEngine;
using UnityEngine.Graphing;
using UnityEngine.MaterialGraph;
using Object = UnityEngine.Object;
[MenuItem("Window/Material Editor")]
public static void OpenMenu()
[SerializeField]
private Object m_Selected;
[SerializeField]
private MaterialGraphAsset m_InMemoryAsset;
public override IGraphAsset inMemoryAsset
{
get { return m_InMemoryAsset; }
set { m_InMemoryAsset = value as MaterialGraphAsset; }
}
public override Object selected
GetWindow<MaterialGraphEditWindow>();
get { return m_Selected; }
set { m_Selected = value; }
}
public override AbstractGraphPresenter CreateDataSource()

3
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Graphs/MaterialGraphAsset.cs


using System.Collections.Generic;
using System.IO;
using System.Linq;
#if UNITY_EDITOR
using System.Reflection;
using UnityEditor;

正在加载...
取消
保存