浏览代码

Implemented node collapsing

/main
Peter Bay Bastian 8 年前
当前提交
f1abf833
共有 9 个文件被更改,包括 137 次插入19 次删除
  1. 21
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DrawData/HeaderDrawData.cs
  2. 13
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DrawData/NodeDrawData.cs
  3. 19
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Drawer/HeaderDrawer.cs
  4. 37
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Drawer/NodeDrawer.cs
  5. 1
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/SerializableGraphView.cs
  6. 7
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Implementation/SerializableNode.cs
  7. 1
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/DrawData/MaterialNodeDrawData.cs
  8. 15
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Styles/MaterialGraph.uss
  9. 42
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Manipulators/NodeExpander.cs

21
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DrawData/HeaderDrawData.cs


using UnityEngine.Graphing;
using System;
using UnityEngine.Graphing;
namespace UnityEditor.Graphing.Drawing
{

{}
public INode node { get; private set; }
private INode node;
public string title
{
get { return node.name; }
}
public bool expanded
{
get { return node.drawState.expanded; }
set
{
var state = node.drawState;
state.expanded = value;
node.drawState = state;
}
}
public void Initialize(INode inNode)
{

13
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DrawData/NodeDrawData.cs


public INode node { get; private set; }
[SerializeField] public bool expanded = true;
protected List<GraphElementData> m_Children = new List<GraphElementData>();
public IEnumerable<GraphElementData> elements

public virtual void OnModified(ModificationScope scope)
{}
{
expanded = node.drawState.expanded;
}
public void CommitChanges()
{

return;
name = inNode.name;
expanded = node.drawState.expanded;
var headerData = CreateInstance<HeaderDrawData>();
headerData.Initialize(inNode);
m_Children.Add(headerData);
var m_HeaderData = CreateInstance<HeaderDrawData>();
m_HeaderData.Initialize(inNode);
m_Children.Add(m_HeaderData);
foreach (var input in node.GetSlots<ISlot>())
{

19
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Drawer/HeaderDrawer.cs


public class HeaderDrawer : GraphElement
{
private VisualElement m_Title;
private VisualElement m_ExpandButton;
private NodeExpander m_NodeExpander = new NodeExpander();
public HeaderDrawer()
public HeaderDrawer(HeaderDrawData data)
m_ExpandButton = new VisualElement()
{
name = "expandButton",
content = new GUIContent("")
};
m_ExpandButton.AddManipulator(m_NodeExpander);
AddChild(m_ExpandButton);
m_Title = new VisualElement()
{
name = "title",

AddChild(m_Title);
dataProvider = data;
}
public override void OnDataChanged()

return;
}
m_Title.content.text = headerData.node.name;
m_Title.content.text = headerData.title;
m_ExpandButton.content.text = headerData.expanded ? "-" : "+";
m_NodeExpander.data = headerData;
}
}
}

37
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Drawer/NodeDrawer.cs


public class NodeDrawer : GraphElement
{
HeaderDrawer m_HeaderDrawer;
HeaderDrawData m_HeaderData;
VisualContainer m_SlotContainer;
List<AnchorDrawData> m_currentAnchors;
VisualContainer m_ControlsContainer;

private void AddContainers()
{
m_HeaderDrawer = new HeaderDrawer()
{
name = "header"
};
AddChild(m_HeaderDrawer);
// Add slots (with input & output sub-containers) container
m_SlotContainer = new VisualContainer
{

m_currentControlDrawData = new List<ControlDrawData>();
}
private void AddHeader(NodeDrawData nodeData)
{
var headerData = nodeData.elements.OfType<HeaderDrawData>().FirstOrDefault();
if (headerData == m_HeaderData || headerData == null)
{
// TODO: Fix data watcher
m_HeaderDrawer.OnDataChanged();
return;
}
if (m_HeaderData != null)
RemoveChild(m_HeaderDrawer);
m_HeaderDrawer = new HeaderDrawer(headerData);
InsertChild(0, m_HeaderDrawer);
m_HeaderData = headerData;
}
private void AddSlots(NodeDrawData nodeData)
{
var anchors = nodeData.elements.OfType<AnchorDrawData>().ToList();

outputsContainer.AddChild(new NodeAnchor(anchor));
}
}
// content.text = nodeData.name;
}
private void AddControls(NodeDrawData nodeData)

if (controlDrawData.Count == 0)
return;
if (!nodeData.expanded)
{
m_ControlsContainer.ClearChildren();
m_currentControlDrawData.Clear();
return;
}
if (controlDrawData.ItemsReferenceEquals(m_currentControlDrawData))
{
for (int i = 0; i < controlDrawData.Count; i++)

return;
}
m_HeaderDrawer.dataProvider = nodeData.elements.OfType<HeaderDrawData>().FirstOrDefault();
AddHeader(nodeData);
AddSlots(nodeData);
AddControls(nodeData);
}

1
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/SerializableGraphView.cs


AddDecorator(new GridBackground());
dataMapper[typeof(NodeDrawData)] = typeof(NodeDrawer);
dataMapper[typeof(HeaderDrawData)] = typeof(HeaderDrawer);
}
private EventPropagation DeleteSelection()

7
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Implementation/SerializableNode.cs


public DrawingData drawState
{
get { return m_DrawData; }
set { m_DrawData = value; }
set
{
m_DrawData = value;
if (onModified != null)
onModified(this, ModificationScope.Node);
}
}
public virtual bool hasError { get; protected set; }

1
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/DrawData/MaterialNodeDrawData.cs


public override void OnModified(ModificationScope scope)
{
base.OnModified(scope);
// TODO: Propagate callback rather than setting property
if (nodePreviewDrawData != null)
nodePreviewDrawData.modificationScope = scope;
}

15
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Styles/MaterialGraph.uss


flex-direction: column;
}
HeaderDrawer {
flex-direction: row;
}
MaterialNodeDrawer #header #title {
HeaderDrawer #title {
text-alignment: middle-center;
}
HeaderDrawer #expandButton {
text-color: #FFFFFF;
position-type: absolute;
position-top: 0;
position-left: 5;
background-color: #000;
width: 10;
text-alignment: middle-center;
}

42
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Manipulators/NodeExpander.cs


using System;
using RMGUI.GraphView;
using UnityEngine;
using UnityEngine.Graphing;
using UnityEngine.RMGUI;
namespace UnityEditor.Graphing.Drawing
{
public class NodeExpander : MouseManipulator
{
public HeaderDrawData data;
private VisualElement initialTarget;
public override EventPropagation HandleEvent(Event evt, VisualElement finalTarget)
{
switch (evt.type)
{
case EventType.MouseDown:
if (CanStartManipulation(evt))
{
this.TakeCapture();
initialTarget = finalTarget;
}
break;
case EventType.MouseUp:
if (CanStopManipulation(evt))
{
this.ReleaseCapture();
var withinInitialTarget = initialTarget != null && initialTarget.ContainsPoint(evt.mousePosition);
if (true || withinInitialTarget)
{
data.expanded = !data.expanded;
}
}
break;
}
return this.HasCapture() ? EventPropagation.Stop : EventPropagation.Continue;
}
}
}
正在加载...
取消
保存