浏览代码

Serialize preview mesh in graph asset instead of through GraphInspectorView persistent data

/main
Jens Holm 7 年前
当前提交
e5a6f66e
共有 2 个文件被更改,包括 12 次插入31 次删除
  1. 9
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/AbstractMaterialGraph.cs
  2. 34
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/GraphInspectorView.cs

9
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/AbstractMaterialGraph.cs


[NonSerialized]
List<Guid> m_RemovedProperties = new List<Guid>();
[SerializeField]
SerializableMesh m_PreviewMesh;
public Mesh previewMesh
{
get { return m_PreviewMesh.mesh; }
set { m_PreviewMesh.mesh = value; }
}
public IEnumerable<IShaderProperty> properties
{
get { return m_Properties; }

34
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/GraphInspectorView.cs


namespace UnityEditor.ShaderGraph.Drawing.Inspector
{
[Serializable]
class PersistentMesh
{
[SerializeField]
Mesh m_Mesh;
public Mesh mesh
{
get { return m_Mesh; }
set { m_Mesh = value; }
}
}
public class GraphInspectorView : VisualElement, IDisposable
{
int m_SelectionHash;

List<INode> m_SelectedNodes;
PersistentMesh m_PersistentMasterNodePreviewMesh;
persistenceKey = "GraphInspector";
m_Graph = graph;
m_SelectedNodes = new List<INode>();

m_PreviewRenderHandle = previewManager.masterRenderData;
m_PreviewRenderHandle.onPreviewChanged += OnPreviewChanged;
m_PreviewMeshPicker.SetValueAndNotify(m_Graph.previewMesh);
foreach (var property in m_Graph.properties)
m_PropertyItems.Add(new ShaderPropertyView(m_Graph, property));

if (changeEvent.newValue == null)
{
m_PreviewRenderHandle.mesh = null;
m_PersistentMasterNodePreviewMesh.mesh = null;
}
Mesh changedMesh = changeEvent.newValue as Mesh;

m_PreviewRenderHandle.mesh = changedMesh;
m_PersistentMasterNodePreviewMesh.mesh = changedMesh;
SavePersistentData();
}
public override void OnPersistentDataReady()
{
base.OnPersistentDataReady();
string key = GetFullHierarchicalPersistenceKey();
m_PersistentMasterNodePreviewMesh = GetOrCreatePersistentData<PersistentMesh>(m_PersistentMasterNodePreviewMesh, key);
m_PreviewMeshPicker.SetValueAndNotify(m_PersistentMasterNodePreviewMesh.mesh);
m_Graph.previewMesh = changedMesh;
}
public void UpdateSelection(IEnumerable<INode> nodes)

正在加载...
取消
保存