浏览代码

#31 Graph inspector now lives inside graph editor window (also, it works again!)

/main
Peter Bay Bastian 7 年前
当前提交
485654b6
共有 11 个文件被更改,包括 172 次插入19 次删除
  1. 14
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Drawer/GraphEditorDrawer.cs
  2. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Drawer/MaterialNodeDrawer.cs
  3. 14
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/MaterialGraphView.cs
  4. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeInspectors/BasicNodeInspector.cs
  5. 24
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialGraphPresenter.cs
  6. 23
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Resources/Styles/MaterialGraph.uss
  7. 46
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/GraphInspectorPresenter.cs
  8. 3
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/GraphInspectorPresenter.cs.meta
  9. 60
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/GraphInspectorView.cs
  10. 3
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/GraphInspectorView.cs.meta

14
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Drawer/GraphEditorDrawer.cs


using UnityEditor.Experimental.UIElements.GraphView;
using UnityEditor.MaterialGraph.Drawing;
using UnityEditor.MaterialGraph.Drawing.Views;
using UnityEngine.Experimental.UIElements;
namespace UnityEditor.MaterialGraph.Drawing
{

private GraphView m_GraphView;
GraphView m_GraphView;
GraphInspectorView m_GraphInspectorView;
public GraphView graphView
{

m_GraphView.name = "GraphView";
m_TitleBarDrawer = new TitleBarDrawer();
m_TitleBarDrawer.name = "TitleBar";
m_GraphInspectorView = new GraphInspectorView();
Add(m_GraphView);
var contentContainer = new VisualElement() { m_GraphView, m_GraphInspectorView };
contentContainer.name = "content";
Add(contentContainer);
}
public override void OnDataChanged()

m_GraphInspectorView.presenter = m_Presenter.graphInspectorPresenter;
private MaterialGraphPresenter m_Presenter;
MaterialGraphPresenter m_Presenter;
public MaterialGraphPresenter presenter
{

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Drawer/MaterialNodeDrawer.cs


{
var controlPresenters = nodeData.elements.OfType<GraphControlPresenter>().ToList();
if (controlPresenters.ItemsReferenceEquals(m_CurrentControlPresenter) && nodeData.expanded)
if (controlPresenters.SequenceEqual(m_CurrentControlPresenter) && nodeData.expanded)
return;
m_ControlsContainer.Clear();

14
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/MaterialGraphView.cs


AddToSelection(drawer);
}
public void SetGlobalSelection()
{
var graphDataSource = GetPresenter<MaterialGraphPresenter>();
if (graphDataSource == null || graphDataSource.graphAsset == null)
return;
//Selection.activeObject = graphDataSource.graphAsset.GetScriptableObject();
}
if (graphDataSource == null || graphDataSource.graphAsset == null)
if (graphDataSource == null)
var selectedNodeGuids = selection.OfType<MaterialNodeDrawer>().Select(x => ((GraphNodePresenter) x.presenter).node.guid);
graphDataSource.graphAsset.drawingData.selection = selectedNodeGuids;
var selectedNodes = selection.OfType<MaterialNodeDrawer>().Select(x => (MaterialNodePresenter) x.presenter);
graphDataSource.UpdateSelection(selectedNodes);
}
public override void AddToSelection(ISelectable selectable)

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeInspectors/BasicNodeInspector.cs


if (scope == ModificationScope.Graph || scope == ModificationScope.Topological)
node.owner.ValidateGraph();
if (node.onModified != null)
if (scope > ModificationScope.Nothing && node.onModified != null)
node.onModified(node, scope);
}

24
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialGraphPresenter.cs


public IGraphAsset graphAsset { get; private set; }
[SerializeField]
private TitleBarPresenter m_TitleBar;
EditorWindow m_Container;
private EditorWindow m_Container;
TitleBarPresenter m_TitleBar;
public GraphInspectorPresenter graphInspectorPresenter
{
get { return m_GraphInspectorPresenter; }
set { m_GraphInspectorPresenter = value; }
}
[SerializeField]
GraphInspectorPresenter m_GraphInspectorPresenter;
protected MaterialGraphPresenter()
{

m_TitleBar = CreateInstance<TitleBarPresenter>();
m_TitleBar.Initialize(container);
m_GraphInspectorPresenter = CreateInstance<GraphInspectorPresenter>();
m_GraphInspectorPresenter.Initialize();
if (graphAsset == null)
return;

public override void AddElement(EdgePresenter edge)
{
Connect(edge.output as GraphAnchorPresenter, edge.input as GraphAnchorPresenter);
}
public void UpdateSelection(IEnumerable<MaterialNodePresenter> presenters)
{
if (graphAsset == null)
return;
graphAsset.drawingData.selection = presenters.Select(x => x.node.guid);
m_GraphInspectorPresenter.UpdateSelection(presenters.Select(x => x.node));
}
public override void AddElement(GraphElementPresenter element)

23
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Resources/Styles/MaterialGraph.uss


}
GraphEditorDrawer #GraphView {
GraphEditorDrawer #content {
flex: 1;
flex-direction: row;
}
GraphEditorDrawer #content #GraphView {
flex: 1;
}
GraphEditorDrawer #content GraphInspectorView {
width: 300;
padding-left: 10;
padding-right: 10;
padding-top: 10;
padding-bottom: 10;
}
GraphEditorDrawer #content GraphInspectorView IMGUIContainer {
flex: 1;
}

spacing:75.0;
thick-lines:10;
}
GraphInspectorView {
}

46
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/GraphInspectorPresenter.cs


using System.Collections.Generic;
using System.Linq;
using UnityEditor.Graphing.Util;
using UnityEngine;
using UnityEngine.Graphing;
using UnityEngine.MaterialGraph;
namespace UnityEditor.MaterialGraph.Drawing
{
public class GraphInspectorPresenter : ScriptableObject
{
[SerializeField]
List<AbstractNodeInspector> m_Inspectors;
public List<AbstractNodeInspector> inspectors
{
get { return m_Inspectors; }
set { m_Inspectors = value; }
}
ScriptableObjectFactory<INode, AbstractNodeInspector, BasicNodeInspector> m_InspectorFactory;
public void Initialize()
{
inspectors = new List<AbstractNodeInspector>();
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))
});
}
public void UpdateSelection(IEnumerable<INode> nodes)
{
m_Inspectors.Clear();
foreach (var node in nodes.OfType<SerializableNode>())
{
var inspector = m_InspectorFactory.Create(node);
inspector.Initialize(node);
m_Inspectors.Add(inspector);
}
}
}
}

3
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/GraphInspectorPresenter.cs.meta


fileFormatVersion: 2
guid: 215d826e4a644dc0bde2fa9ba68f4096
timeCreated: 1502956093

60
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/GraphInspectorView.cs


using System;
using UnityEditor.Experimental.UIElements.GraphView;
using UnityEngine;
using UnityEngine.Experimental.UIElements;
using Object = UnityEngine.Object;
namespace UnityEditor.MaterialGraph.Drawing.Views
{
public class GraphInspectorView : DataWatchContainer
{
[SerializeField]
GraphInspectorPresenter m_Presenter;
IMGUIContainer m_ImguiContainer;
public GraphInspectorView()
{
AddStyleSheetPath("Styles/MaterialGraph");
Add(m_ImguiContainer = new IMGUIContainer(OnGUIHandler));
}
void OnGUIHandler()
{
if (m_Presenter == null)
return;
foreach (var inspector in presenter.inspectors)
{
inspector.OnInspectorGUI();
}
}
public override void OnDataChanged()
{
if (presenter == null)
return;
Dirty(ChangeType.Repaint);
}
public GraphInspectorPresenter presenter
{
get { return m_Presenter; }
set
{
if (m_Presenter == value)
return;
RemoveWatch();
m_Presenter = value;
// m_ImguiContainer.executionContext = presenter.GetInstanceID();
OnDataChanged();
AddWatch();
}
}
protected override Object[] toWatch
{
get { return new Object[] {m_Presenter}; }
}
}
}

3
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/GraphInspectorView.cs.meta


fileFormatVersion: 2
guid: d80d2409e2484dbea449768bbdd267b9
timeCreated: 1502956197
正在加载...
取消
保存