浏览代码

#35 Pull AbstractGraphInspector into AbstractMaterialGraphInspector

/main
Peter Bay Bastian 7 年前
当前提交
ecb231e6
共有 4 个文件被更改,包括 63 次插入109 次删除
  1. 78
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/AbstractMaterialGraphInspector.cs
  2. 10
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Resources.meta
  3. 72
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/AbstractGraphInspector.cs
  4. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/AbstractGraphInspector.cs.meta

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


namespace UnityEditor.MaterialGraph.Drawing
{
public abstract class AbstractMaterialGraphInspector : AbstractGraphInspector
public abstract class AbstractMaterialGraphInspector : Editor
private bool m_RequiresTime;
ScriptableObjectFactory<INode, AbstractNodeInspector, BasicNodeInspector> m_InspectorFactory;
List<INode> m_SelectedNodes = new List<INode>();
protected IEnumerable<INode> selectedNodes
{
get { return m_SelectedNodes; }
}
List<AbstractNodeInspector> m_Inspectors = new List<AbstractNodeInspector>();
protected IGraphAsset graphAsset
{
get { return target as IGraphAsset; }
}
bool m_RequiresTime;
private NodePreviewPresenter m_NodePreviewPresenter;
NodePreviewPresenter m_NodePreviewPresenter;
private AbstractMaterialNode m_PreviewNode;
AbstractMaterialNode m_PreviewNode;
protected AbstractMaterialNode previewNode
{

}
}
protected AbstractMaterialGraphInspector() : base(typeMappings)
protected AbstractMaterialGraphInspector()
m_InspectorFactory = new ScriptableObjectFactory<INode, AbstractNodeInspector, BasicNodeInspector>(new[]
{
new TypeMapping(typeof(AbstractSurfaceMasterNode), typeof(SurfaceMasterNodeInspector)),
new TypeMapping(typeof(PropertyNode), typeof(PropertyNodeInspector)),
new TypeMapping(typeof(SubGraphInputNode), typeof(SubgraphInputNodeInspector)),
new TypeMapping(typeof(SubGraphOutputNode), typeof(SubgraphOutputNodeInspector))
});
private static IEnumerable<TypeMapping> typeMappings
public override void OnInspectorGUI()
get
UpdateSelection();
foreach (var inspector in m_Inspectors)
yield return new TypeMapping(typeof(AbstractSurfaceMasterNode), typeof(SurfaceMasterNodeInspector));
yield return new TypeMapping(typeof(PropertyNode), typeof(PropertyNodeInspector));
yield return new TypeMapping(typeof(SubGraphInputNode), typeof(SubgraphInputNodeInspector));
yield return new TypeMapping(typeof(SubGraphOutputNode), typeof(SubgraphOutputNodeInspector));
inspector.OnInspectorGUI();
}
}
void UpdateSelection()
{
if (graphAsset == null)
return;
using (var nodes = ListPool<INode>.GetDisposable())
{
nodes.value.AddRange(graphAsset.drawingData.selection.Select(graphAsset.graph.GetNodeFromGuid));
if (m_SelectedNodes == null || m_Inspectors.Any(i => i.node == null) || !nodes.value.SequenceEqual(m_SelectedNodes))
OnSelectionChanged(nodes.value);
}
}
protected virtual void OnSelectionChanged(IEnumerable<INode> selectedNodes)
{
m_SelectedNodes.Clear();
m_SelectedNodes.AddRange(selectedNodes);
m_Inspectors.Clear();
foreach (var node in m_SelectedNodes.OfType<SerializableNode>())
{
var inspector = m_InspectorFactory.Create(node);
inspector.Initialize(node);
m_Inspectors.Add(inspector);
private void OnPreviewNodeModified(INode node, ModificationScope scope)
void OnPreviewNodeModified(INode node, ModificationScope scope)
public override void OnEnable()
public virtual void OnEnable()
base.OnEnable();
UpdateSelection();
previewNode = null;
}

return m_Title;
}
private void ForEachChild(INode node, Action<INode> action)
void ForEachChild(INode node, Action<INode> action)
{
if (node == null)
return;

10
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Resources.meta


fileFormatVersion: 2
guid: abb5ef211431d3a40807d20387f72d57
folderAsset: yes
timeCreated: 1485544540
licenseType: Pro
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

72
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/AbstractGraphInspector.cs


using System.Collections.Generic;
using System.Linq;
using UnityEditor.Graphing.Util;
using UnityEngine.Graphing;
namespace UnityEditor.Graphing.Drawing
{
public abstract class AbstractGraphInspector : Editor
{
private ScriptableObjectFactory<INode, AbstractNodeInspector, BasicNodeInspector> m_InspectorFactory;
private List<INode> m_SelectedNodes = new List<INode>();
protected IEnumerable<INode> selectedNodes
{
get { return m_SelectedNodes; }
}
private List<AbstractNodeInspector> m_Inspectors = new List<AbstractNodeInspector>();
protected IGraphAsset graphAsset
{
get { return target as IGraphAsset; }
}
protected AbstractGraphInspector(IEnumerable<TypeMapping> typeMappings)
{
m_InspectorFactory = new ScriptableObjectFactory<INode, AbstractNodeInspector, BasicNodeInspector>(typeMappings);
}
public override void OnInspectorGUI()
{
UpdateSelection();
foreach (var inspector in m_Inspectors)
{
inspector.OnInspectorGUI();
}
}
private void UpdateSelection()
{
if (graphAsset == null)
return;
using (var nodes = ListPool<INode>.GetDisposable())
{
nodes.value.AddRange(graphAsset.drawingData.selection.Select(graphAsset.graph.GetNodeFromGuid));
if (m_SelectedNodes == null || m_Inspectors.Any(i => i.node == null) || !nodes.value.SequenceEqual(m_SelectedNodes))
OnSelectionChanged(nodes.value);
}
}
protected virtual void OnSelectionChanged(IEnumerable<INode> selectedNodes)
{
m_SelectedNodes.Clear();
m_SelectedNodes.AddRange(selectedNodes);
m_Inspectors.Clear();
foreach (var node in m_SelectedNodes.OfType<SerializableNode>())
{
var inspector = m_InspectorFactory.Create(node);
inspector.Initialize(node);
m_Inspectors.Add(inspector);
}
}
public virtual void OnEnable()
{
UpdateSelection();
}
}
}

12
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/AbstractGraphInspector.cs.meta


fileFormatVersion: 2
guid: 0e3ca0203324c4b0791cb3c1a53eeecb
timeCreated: 1482322349
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存