浏览代码

Removed un-pin functionality, such that a node is always pinned (defaults to active master node). Also improved interface for AbstractGraphInspector.

/main
Peter Bay Bastian 8 年前
当前提交
ddc991d7
共有 2 个文件被更改,包括 40 次插入61 次删除
  1. 19
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/AbstractGraphInspector.cs
  2. 82
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/MaterialGraphInspector.cs

19
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/AbstractGraphInspector.cs


{
private readonly TypeMapper m_DataMapper = new TypeMapper(typeof(BasicNodeInspector));
[SerializeField] protected List<AbstractNodeInspector> m_Inspectors = new List<AbstractNodeInspector>();
protected List<INode> m_SelectedNodes;
protected List<AbstractNodeInspector> m_Inspectors = new List<AbstractNodeInspector>();
protected IGraphAsset m_GraphAsset;

{
UpdateInspectors();
UpdateSelection();
foreach (var inspector in m_Inspectors)
{

protected virtual void UpdateInspectors()
private void UpdateSelection()
if (m_Inspectors.All(i => i.node != null) && selectedNodes.Select(n => n.guid).SequenceEqual(m_Inspectors.Select(i => i.nodeGuid)))
if (m_SelectedNodes != null && m_Inspectors.All(i => i.node != null) && selectedNodes.SequenceEqual(m_SelectedNodes))
OnSelectionChanged(selectedNodes);
}
protected virtual void OnSelectionChanged(List<INode> selectedNodes)
{
m_SelectedNodes = selectedNodes;
foreach (var node in selectedNodes.OfType<SerializableNode>())
foreach (var node in m_SelectedNodes.OfType<SerializableNode>())
{
var inspector = CreateInspector(node);
inspector.Initialize(node);

m_GraphAsset = target as IGraphAsset;
m_DataMapper.Clear();
AddTypeMappings(m_DataMapper.AddMapping);
UpdateSelection();
}
}
}

82
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/MaterialGraphInspector.cs


using System;
using System.Collections.Generic;
using System.Linq;
using UnityEditor.Graphing.Drawing;
using UnityEngine;

{
private bool m_RequiresTime;
[SerializeField]
private AbstractMaterialNode m_PreviewNode;
private AbstractMaterialNode previewNode

}
}
private void ForEachChild(INode node, Action<INode> action)
private NodePreviewDrawData m_NodePreviewPresenter;
private UnityEngine.MaterialGraph.MaterialGraph materialGraph
if (node == null)
return;
var childNodes = ListPool<INode>.Get();
NodeUtils.DepthFirstCollectNodesFromNode(childNodes, node);
foreach (var childNode in childNodes)
{
action(childNode);
}
ListPool<INode>.Release(childNodes);
get { return m_GraphAsset.graph as UnityEngine.MaterialGraph.MaterialGraph; }
private AbstractMaterialNode m_SelectedNode;
[SerializeField]
private NodePreviewDrawData m_NodePreviewPresenter;
[SerializeField]
private bool m_NodePinned;
private UnityEngine.MaterialGraph.MaterialGraph m_MaterialGraph;
private void OnPreviewNodeModified(INode node, ModificationScope scope)
{
m_NodePreviewPresenter.modificationScope = scope;

public override void OnEnable()
{
m_NodePreviewPresenter = CreateInstance<NodePreviewDrawData>();
m_NodePreviewPresenter = CreateInstance<NodePreviewDrawData>();
if (m_GraphAsset != null)
m_MaterialGraph = m_GraphAsset.graph as UnityEngine.MaterialGraph.MaterialGraph;
previewNode = materialGraph.masterNode as AbstractMaterialNode;
}
protected override void AddTypeMappings(Action<Type, Type> map)

protected override void UpdateInspectors()
{
base.UpdateInspectors();
m_SelectedNode = m_Inspectors.Select(i => i.node).OfType<AbstractMaterialNode>().FirstOrDefault();
if (m_MaterialGraph == null || m_NodePinned)
return;
previewNode = m_SelectedNode ?? m_MaterialGraph.masterNode as AbstractMaterialNode;
}
public override bool HasPreviewGUI()
{
return m_PreviewNode != null;

if (Event.current.type == EventType.Repaint)
{
var size = Mathf.Min(r.width, r.height);
var previewDimension = new Vector2(size, size);
var previewPosition = new Vector2(r.x + r.width*0.5f - size*0.5f, r.y + r.height*0.5f - size*0.5f);
var image = m_NodePreviewPresenter.Render(previewDimension);
GUI.DrawTexture(new Rect(previewPosition, previewDimension), image);
var image = m_NodePreviewPresenter.Render(new Vector2(size, size));
GUI.DrawTexture(r, image, ScaleMode.ScaleToFit);
m_NodePreviewPresenter.modificationScope = ModificationScope.Node;
}
}

if (m_Inspectors.Any() && !(m_NodePinned && m_SelectedNode == m_PreviewNode))
{
if (GUILayout.Button("Pin selected", "preButton"))
{
previewNode = m_SelectedNode;
m_NodePinned = true;
}
}
else if (!m_NodePinned)
{
if (GUILayout.Button("Pin", "preButton"))
m_NodePinned = true;
}
if (m_NodePinned && GUILayout.Button("Unpin", "preButton"))
m_NodePinned = false;
GUI.enabled = m_SelectedNodes.Count == 1 && m_SelectedNodes.FirstOrDefault() != previewNode;
if (GUILayout.Button("Pin selected", "preButton"))
previewNode = m_SelectedNodes.FirstOrDefault() as AbstractMaterialNode;
GUI.enabled = true;
}
public override bool RequiresConstantRepaint()

public override GUIContent GetPreviewTitle()
{
return new GUIContent(m_PreviewNode.name);
}
private void ForEachChild(INode node, Action<INode> action)
{
if (node == null)
return;
var childNodes = ListPool<INode>.Get();
NodeUtils.DepthFirstCollectNodesFromNode(childNodes, node);
foreach (var childNode in childNodes)
{
action(childNode);
}
ListPool<INode>.Release(childNodes);
}
}
}
正在加载...
取消
保存