浏览代码

Inspector now listens for changes to node relevant to the previewed node. It is now possible to pin the selected node, while another node is pinned (to avoid having to click 2 times). Constant re-paint is now only turned on if any relevant nodes require time.

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

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


[SerializeField] protected List<AbstractNodeInspector> m_Inspectors = new List<AbstractNodeInspector>();
protected IGraphAsset m_GraphAsset;
protected abstract void AddTypeMappings(Action<Type, Type> map);
public override void OnInspectorGUI()

protected virtual void UpdateInspectors()
{
var asset = target as IGraphAsset;
if (asset == null)
if (m_GraphAsset == null)
var selectedNodes = asset.drawingData.selection.Select(asset.graph.GetNodeFromGuid).ToList();
var selectedNodes = m_GraphAsset.drawingData.selection.Select(m_GraphAsset.graph.GetNodeFromGuid).ToList();
if (m_Inspectors.All(i => i.node != null) && selectedNodes.Select(n => n.guid).SequenceEqual(m_Inspectors.Select(i => i.nodeGuid)))
return;

public virtual void OnEnable()
{
m_GraphAsset = target as IGraphAsset;
m_DataMapper.Clear();
AddTypeMappings(m_DataMapper.AddMapping);
}

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


[CustomEditor(typeof(MaterialGraphAsset))]
public class MaterialGraphInspector : AbstractGraphInspector
{
private bool m_RequiresTime;
private AbstractMaterialNode previewNode
{
get { return m_PreviewNode; }
set
{
if (value == m_PreviewNode)
return;
ForEachChild(m_PreviewNode, (node) => node.onModified -= OnPreviewNodeModified);
m_PreviewNode = value;
m_NodePreviewPresenter.Initialize(value);
m_RequiresTime = false;
ForEachChild(m_PreviewNode,
(node) =>
{
node.onModified += OnPreviewNodeModified;
m_RequiresTime |= node is IRequiresTime;
});
}
}
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);
}
private AbstractMaterialNode m_SelectedNode;
[SerializeField]
private NodePreviewDrawData m_NodePreviewPresenter;

private UnityEngine.MaterialGraph.MaterialGraph m_MaterialGraph;
private void OnPreviewNodeModified(INode node, ModificationScope scope)
{
m_NodePreviewPresenter.modificationScope = scope;
Repaint();
}
if (m_GraphAsset != null)
m_MaterialGraph = m_GraphAsset.graph as UnityEngine.MaterialGraph.MaterialGraph;
}
protected override void AddTypeMappings(Action<Type, Type> map)

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

public override void OnPreviewSettings()
{
if (GUILayout.Button(m_NodePinned ? "Unpin" : "Pin", "preButton"))
if (m_Inspectors.Any() && !(m_NodePinned && m_SelectedNode == m_PreviewNode))
m_NodePinned = !m_NodePinned;
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;
return m_PreviewNode != null;
return m_RequiresTime;
}
public override GUIContent GetPreviewTitle()

正在加载...
取消
保存