浏览代码

Update to latest GraphView

** Requires update to Unity branch **

- New way to reference StyleSheets (no longer using attributes). This in the
  goal of moving GraphView to a GitHub submodule.
  - Styles sheets moved under Resources folder
- BaseTypeMapper renamed BaseTypeFactory
- Little change to edge drawing code.
- Changes to selection mechanism.
- NodeAnchors are no longer always removed/added on a DataChange (more changes
  to come to this soon).
- Dragger and NodeDragger change only the VisualElement on MouseMove. The
  presenter is now changes and notified of the change only upon MouseUp.
- Various minute changes to demo presenters.

Signed-off-by: joce <joce@unity3d.com>
/main
joce 8 年前
当前提交
f4fad3a8
共有 57 个文件被更改,包括 462 次插入160 次删除
  1. 5
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Drawer/GraphEditorDrawer.cs
  2. 2
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Drawer/TitleBarDrawer.cs
  3. 2
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/SerializableGraphView.cs
  4. 2
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Util/GraphTypeMapper.cs
  5. 4
      MaterialGraphProject/Assets/NewUI/Editor/DataWatchTests.meta
  6. 3
      MaterialGraphProject/Assets/NewUI/Editor/Demo/Elements/Comment.cs
  7. 6
      MaterialGraphProject/Assets/NewUI/Editor/Demo/Elements/Presenters/MiniMapPresenter.cs
  8. 6
      MaterialGraphProject/Assets/NewUI/Editor/Demo/Elements/Presenters/VerticalNodePresenter.cs
  9. 8
      MaterialGraphProject/Assets/NewUI/Editor/Demo/Views/NodesContentView.cs
  10. 17
      MaterialGraphProject/Assets/NewUI/Editor/Demo/Views/SimpleContentView.cs
  11. 13
      MaterialGraphProject/Assets/NewUI/Editor/Elements/Edge.cs
  12. 30
      MaterialGraphProject/Assets/NewUI/Editor/Elements/GraphElement.cs
  13. 51
      MaterialGraphProject/Assets/NewUI/Editor/Elements/Node.cs
  14. 10
      MaterialGraphProject/Assets/NewUI/Editor/Elements/NodeAnchor.cs
  15. 14
      MaterialGraphProject/Assets/NewUI/Editor/Elements/Presenters/GraphElementPresenter.cs
  16. 6
      MaterialGraphProject/Assets/NewUI/Editor/Elements/Presenters/NodeAnchorPresenter.cs
  17. 31
      MaterialGraphProject/Assets/NewUI/Editor/Elements/Presenters/NodePresenter.cs
  18. 33
      MaterialGraphProject/Assets/NewUI/Editor/GraphViewEditorWindow.cs
  19. 3
      MaterialGraphProject/Assets/NewUI/Editor/ISelectable.cs
  20. 26
      MaterialGraphProject/Assets/NewUI/Editor/Manipulators/ClickSelector.cs
  21. 16
      MaterialGraphProject/Assets/NewUI/Editor/Manipulators/Dragger.cs
  22. 14
      MaterialGraphProject/Assets/NewUI/Editor/Manipulators/EdgeConnector.cs
  23. 47
      MaterialGraphProject/Assets/NewUI/Editor/Manipulators/SelectionDragger.cs
  24. 11
      MaterialGraphProject/Assets/NewUI/Editor/Views/GraphView.cs
  25. 15
      MaterialGraphProject/Assets/NewUI/Editor/Views/Presenters/GraphViewPresenter.cs
  26. 6
      MaterialGraphProject/Assets/NewUI/Editor/BaseTypeFactory.cs
  27. 9
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/MaterialGraphView.cs
  28. 9
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Resources.meta
  29. 19
      MaterialGraphProject/Assets/NewUI/Editor/GraphViewTypeFactory.cs
  30. 9
      MaterialGraphProject/Assets/NewUI/Editor/Resources.meta
  31. 9
      MaterialGraphProject/Assets/NewUI/Editor/Tests.meta
  32. 9
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Resources.meta
  33. 9
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Resources/Styles.meta
  34. 9
      MaterialGraphProject/Assets/NewUI/Editor/Resources/Demo.meta
  35. 101
      MaterialGraphProject/Assets/NewUI/Editor/Tests/GraphElementMoveTests.cs
  36. 12
      MaterialGraphProject/Assets/NewUI/Editor/Tests/GraphElementMoveTests.cs.meta
  37. 9
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Resources/Styles.meta
  38. 9
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Styles.meta
  39. 19
      MaterialGraphProject/Assets/NewUI/Editor/GraphViewTypeMapper.cs
  40. 9
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Styles.meta
  41. 0
      /MaterialGraphProject/Assets/NewUI/Editor/BaseTypeFactory.cs.meta
  42. 0
      /MaterialGraphProject/Assets/NewUI/Editor/GraphViewTypeFactory.cs.meta
  43. 0
      /MaterialGraphProject/Assets/NewUI/Editor/BaseTypeFactory.cs
  44. 0
      /MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Resources/Styles
  45. 0
      /MaterialGraphProject/Assets/NewUI/Editor/Resources/Demo/SimpleContentView.uss.meta
  46. 0
      /MaterialGraphProject/Assets/NewUI/Editor/Resources/Demo/SimpleContentView.uss
  47. 0
      /MaterialGraphProject/Assets/NewUI/Editor/Resources/GraphView.uss
  48. 0
      /MaterialGraphProject/Assets/NewUI/Editor/Resources/GraphView.uss.meta
  49. 0
      /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Resources/Styles
  50. 0
      /MaterialGraphProject/Assets/NewUI/Editor/Tests/DataWatchTests.cs.meta
  51. 0
      /MaterialGraphProject/Assets/NewUI/Editor/Tests/DataWatchTests.cs

5
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Drawer/GraphEditorDrawer.cs


namespace UnityEditor.Graphing.Drawing
{
// TODO JOCE: Maybe this needs to dereive from something we already have?
[StyleSheet("Assets/GraphFramework/SerializableGraph/Editor/Drawing/Styles/GraphEditor.uss")]
// TODO JOCE: Maybe this needs to derive from something we already have?
public class GraphEditorDrawer : DataWatchContainer
{
private GraphView m_GraphView;

AddChild(m_GraphView);
this.presenter = presenter;
AddStyleSheetPath("Styles/GraphEditor");
}
public override void OnDataChanged()

2
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Drawer/TitleBarDrawer.cs


namespace UnityEditor.Graphing.Drawing
{
// TODO JOCE: we should not need a title bar drawer. It should just be a visual element in the nodedrawer.
[StyleSheet("Assets/GraphFramework/SerializableGraph/Editor/Drawing/Styles/TitleBar.uss")]
public class TitleBarDrawer : DataWatchContainer
{
TitleBarPresenter m_DataProvider;

m_RightContainer.AddChild(new TitleBarButtonDrawer(rightItemData));
this.dataProvider = dataProvider;
AddStyleSheetPath("Styles/TitleBar");
}
public override void OnDataChanged()

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


InsertChild(0, new GridBackground());
typeMapper[typeof(GraphNodePresenter)] = typeof(NodeDrawer);
typeFactory[typeof(GraphNodePresenter)] = typeof(NodeDrawer);
}
// TODO JOCE Remove the "new" here. Use the base class' impl

2
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Util/GraphTypeMapper.cs


namespace UnityEditor.Graphing.Util
{
public class GraphTypeMapper : BaseTypeMapper<INode, ScriptableObject>
public class GraphTypeMapper : BaseTypeFactory<INode, ScriptableObject>
{
public GraphTypeMapper(Type fallbackType) : base(fallbackType)
{

4
MaterialGraphProject/Assets/NewUI/Editor/DataWatchTests.meta


fileFormatVersion: 2
guid: f176aac3129a8fe4792cc998311df4f1
guid: c3c8f88b513170b4b96bd5db192b0ce9
timeCreated: 1480532459
timeCreated: 1485543350
licenseType: Pro
DefaultImporter:
userData:

3
MaterialGraphProject/Assets/NewUI/Editor/Demo/Elements/Comment.cs


// TODO: Temporary class to use IMGUI's TextArea instead of RMGUI.TextField (unavailable for now)
public class Comment : IMGUIElement
{
int m_MaxTitleLength;
bool m_ShowBackgroundColor;
// TODO: Get style from USS when switching to RMGUI.TextField

clipChildren = true;
elementTypeColor = new Color(0.8f, 0.8f, 0.8f, 0.5f);
backgroundColor = elementTypeColor;
m_MaxTitleLength = 64;
m_Container.positionTop = 0;

6
MaterialGraphProject/Assets/NewUI/Editor/Demo/Elements/Presenters/MiniMapPresenter.cs


{
base.OnEnable();
capabilities = Capabilities.Floating | Capabilities.Movable;
}
protected MiniMapPresenter()
{
protected MiniMapPresenter() {}
}
}

6
MaterialGraphProject/Assets/NewUI/Editor/Demo/Elements/Presenters/VerticalNodePresenter.cs


[Serializable]
class VerticalNodePresenter : NodePresenter
{
public override Orientation orientation
{
get { return Orientation.Vertical; }
}
m_Orientation = Orientation.Vertical;
}
}
}

8
MaterialGraphProject/Assets/NewUI/Editor/Demo/Views/NodesContentView.cs


return EventPropagation.Continue;
}));
typeMapper[typeof(CustomEdgePresenter)] = typeof(CustomEdge);
typeMapper[typeof(NodeAnchorPresenter)] = typeof(NodeAnchor);
typeMapper[typeof(NodePresenter)] = typeof(Node);
typeMapper[typeof(VerticalNodePresenter)] = typeof(Node);
typeFactory[typeof(CustomEdgePresenter)] = typeof(CustomEdge);
typeFactory[typeof(NodeAnchorPresenter)] = typeof(NodeAnchor);
typeFactory[typeof(NodePresenter)] = typeof(Node);
typeFactory[typeof(VerticalNodePresenter)] = typeof(Node);
}
public void CreateOperator()

17
MaterialGraphProject/Assets/NewUI/Editor/Demo/Views/SimpleContentView.cs


namespace RMGUI.GraphView.Demo
{
[StyleSheet("Assets/NewUI/Editor/Demo/Views/SimpleContentView.uss")]
public class SimpleContentView : GraphView
{
public SimpleContentView()

InsertChild(0, new GridBackground());
typeMapper[typeof(CirclePresenter)] = typeof(Circle);
typeMapper[typeof(InvisibleBorderContainerPresenter)] = typeof(InvisibleBorderContainer);
typeMapper[typeof(MiniMapPresenter)] = typeof(MiniMap);
typeMapper[typeof(SimpleElementPresenter)] = typeof(SimpleElement);
typeMapper[typeof(WWWImagePresenter)] = typeof(WWWImage);
typeMapper[typeof(IMGUIPresenter)] = typeof(IMGUIElement);
typeMapper[typeof(CommentPresenter)] = typeof(Comment);
typeFactory[typeof(CirclePresenter)] = typeof(Circle);
typeFactory[typeof(InvisibleBorderContainerPresenter)] = typeof(InvisibleBorderContainer);
typeFactory[typeof(MiniMapPresenter)] = typeof(MiniMap);
typeFactory[typeof(SimpleElementPresenter)] = typeof(SimpleElement);
typeFactory[typeof(WWWImagePresenter)] = typeof(WWWImage);
typeFactory[typeof(IMGUIPresenter)] = typeof(IMGUIElement);
typeFactory[typeof(CommentPresenter)] = typeof(Comment);
AddStyleSheetPath("Demo/SimpleContentView");
}
}
}

13
MaterialGraphProject/Assets/NewUI/Editor/Elements/Edge.cs


protected static void GetTangents(Orientation orientation, Vector2 from, Vector2 to, out Vector3[] points, out Vector3[] tangents)
{
bool invert = false;
if (from.x < to.x)
if ((orientation == Orientation.Horizontal && from.x < to.x))
invert = true;
}
points = new Vector3[] {to, from};

}
else
{
float inverse = (invert) ? 1.0f : -1.0f;
tangents[0] = to + new Vector2(y, inverse * ((from.x - to.x) * weight + minTangent)) * cleverness;
tangents[1] = from + new Vector2(-y, inverse * ((from.x - to.x) * -weight2 - minTangent)) * cleverness;
float tangentSize = to.y - from.y + 100.0f;
tangentSize = Mathf.Min((to - from).magnitude, tangentSize);
if (tangentSize < 0.0f) tangentSize = -tangentSize;
tangents[0] = to + new Vector2(0, tangentSize * -0.5f);
tangents[1] = from + new Vector2(0, tangentSize * 0.5f);
}
}

30
MaterialGraphProject/Assets/NewUI/Editor/Elements/GraphElement.cs


using System;
using UnityEngine;
using UnityEngine.RMGUI;
using UnityEngine.RMGUI.StyleSheets;

{
// set absolute position from presenter
position = newPos;
}
public virtual EventPropagation Select(VisualContainer selectionContainer, Event evt)
{
var selectable = this.GetFirstOfType<ISelectable>();
if (selectable == null || !selectable.IsSelectable())
{
return EventPropagation.Continue;
}
var graphView = selectionContainer as GraphView;
if (graphView != null && parent == graphView.contentViewContainer)
{
if (graphView.selection.Contains(selectable))
{
if (evt.control)
{
graphView.RemoveFromSelection(selectable);
return EventPropagation.Stop;
}
return EventPropagation.Continue;
}
if (!evt.control)
graphView.ClearSelection();
graphView.AddToSelection(selectable);
}
return EventPropagation.Continue;
}
}
}

51
MaterialGraphProject/Assets/NewUI/Editor/Elements/Node.cs


using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;

AddToClassList(nodePresenter.orientation == Orientation.Vertical ? "vertical" : "horizontal");
}
private void ProcessRemovedAnchors(IList<NodeAnchor> currentAnchors, VisualContainer anchorContainer, IList<NodeAnchorPresenter> currentPresenters)
{
foreach (var anchor in currentAnchors)
{
bool contains = false;
var inputPres = anchor.GetPresenter<NodeAnchorPresenter>();
foreach (var newPres in currentPresenters)
{
if (newPres == inputPres)
{
contains = true;
break;
}
}
if (!contains)
{
anchorContainer.RemoveChild(anchor);
}
}
}
private void ProcessAddedAnchors(IList<NodeAnchor> currentAnchors, VisualContainer anchorContainer, IList<NodeAnchorPresenter> currentPresenters)
{
foreach (var newPres in currentPresenters)
{
bool contains = false;
foreach (var currAnchor in currentAnchors)
{
if (newPres == currAnchor.GetPresenter<NodeAnchorPresenter>())
{
contains = true;
break;
}
}
if (!contains)
{
anchorContainer.AddChild(NodeAnchor.Create<EdgePresenter>(newPres));
}
}
}
public void RefreshAnchors()
{
var nodePresenter = GetPresenter<NodePresenter>();

#if true
ProcessRemovedAnchors(currentInputs, inputContainer, nodePresenter.inputAnchors);
ProcessRemovedAnchors(currentOutputs, outputContainer, nodePresenter.outputAnchors);
ProcessAddedAnchors(currentInputs, inputContainer, nodePresenter.inputAnchors);
ProcessAddedAnchors(currentOutputs, outputContainer, nodePresenter.outputAnchors);
#else
outputContainer.ClearChildren();
inputContainer.ClearChildren();

mainContainer.RemoveChild(rightContainer);
}
}
#endif
}
public override void OnDataChanged()

10
MaterialGraphProject/Assets/NewUI/Editor/Elements/NodeAnchor.cs


namespace RMGUI.GraphView
{
internal class NodeAnchor : GraphElement
public class NodeAnchor : GraphElement
private EdgeConnector m_EdgeConnector;
protected EdgeConnector m_EdgeConnector;
VisualElement m_ConnectorBox;
VisualElement m_ConnectorText;
protected VisualElement m_ConnectorBox;
protected VisualElement m_ConnectorText;
// TODO This is a workaround to avoid having a generic type for the anchor as generic types mess with USS.
public static NodeAnchor Create<TEdgePresenter>(NodeAnchorPresenter presenter) where TEdgePresenter : EdgePresenter

return anchor;
}
private NodeAnchor(NodeAnchorPresenter presenter)
protected NodeAnchor(NodeAnchorPresenter presenter)
{
// currently we don't want to be styled as .graphElement since we're contained in a Node
classList = ClassList.empty;

14
MaterialGraphProject/Assets/NewUI/Editor/Elements/Presenters/GraphElementPresenter.cs


using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
namespace RMGUI.GraphView

}
}
protected void OnEnable()
protected virtual void OnEnable()
{
capabilities = Capabilities.Normal | Capabilities.Movable | Capabilities.Selectable;
}

public virtual void CommitChanges()
{
}
public virtual IEnumerable<GraphElementPresenter> allChildren
{
get { return Enumerable.Empty<GraphElementPresenter>(); }
}
public virtual IEnumerable<GraphElementPresenter> allElements
{
get { yield return this; }
}
}
}

6
MaterialGraphProject/Assets/NewUI/Editor/Elements/Presenters/NodeAnchorPresenter.cs


}
[SerializeField]
private List<EdgePresenter> m_Connections;
protected List<EdgePresenter> m_Connections;
public void Connect(EdgePresenter edgePresenter)
public virtual void Connect(EdgePresenter edgePresenter)
{
if (edgePresenter == null)
{

}
}
public void Disconnect(EdgePresenter edgePresenter)
public virtual void Disconnect(EdgePresenter edgePresenter)
{
if (edgePresenter == null)
{

31
MaterialGraphProject/Assets/NewUI/Editor/Elements/Presenters/NodePresenter.cs


using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
namespace RMGUI.GraphView

{
[SerializeField]
private List<NodeAnchorPresenter> m_InputAnchors;
protected List<NodeAnchorPresenter> m_InputAnchors;
public List<NodeAnchorPresenter> inputAnchors
{
get { return m_InputAnchors ?? (m_InputAnchors = new List<NodeAnchorPresenter>()); }

private List<NodeAnchorPresenter> m_OutputAnchors;
protected List<NodeAnchorPresenter> m_OutputAnchors;
public List<NodeAnchorPresenter> outputAnchors
{
get { return m_OutputAnchors ?? (m_OutputAnchors = new List<NodeAnchorPresenter>()); }

set { m_expanded = value; }
}
protected Orientation m_Orientation;
get { return Orientation.Horizontal; }
get { return m_Orientation; }
}
// TODO make a simple creation function

protected NodePresenter()
{
m_expanded = true;
m_Orientation = Orientation.Horizontal;
public override IEnumerable<GraphElementPresenter> allChildren
{
get { return inputAnchors.Concat(outputAnchors).Cast<GraphElementPresenter>(); }
}
public override IEnumerable<GraphElementPresenter> allElements
{
get
{
yield return this;
foreach (var inpt in inputAnchors)
{
yield return inpt;
}
foreach (var outpt in outputAnchors)
{
yield return outpt;
}
}
}
}
}

33
MaterialGraphProject/Assets/NewUI/Editor/GraphViewEditorWindow.cs


using UnityEngine;
using UnityEngine;
using UnityEditor;
using UnityEngine.RMGUI;

{
public GraphView graphView { get; private set; }
GraphViewPresenter m_Presenter;
public GraphViewPresenter presenter { get; private set; }
public T GetPresenter<T>() where T : GraphViewPresenter
{
return presenter as T;
}
void OnEnable()
protected void OnEnable()
m_Presenter = BuildPresenters();
presenter = BuildPresenters();
graphView.presenter = m_Presenter;
graphView.presenter = presenter;
graphView.StretchToParentSize();
graphView.onEnter += OnEnterPanel;
graphView.onLeave += OnLeavePanel;

void OnDisable()
protected void OnDisable()
{
rootVisualContainer.RemoveChild(graphView);
}

void OnEnterPanel()
{
if (m_Presenter == null)
if (presenter == null)
m_Presenter = BuildPresenters();
graphView.presenter = m_Presenter;
presenter = BuildPresenters();
graphView.presenter = presenter;
handle = graphView.panel.dataWatch.AddWatch(graphView, m_Presenter, OnChanged);
handle = graphView.panel.dataWatch.AddWatch(graphView, presenter, OnChanged);
}
void OnLeavePanel()

void OnChanged()
{
// If data was destroyed, remove the watch and try to re-create it
if (m_Presenter == null && graphView.panel != null)
if (presenter == null && graphView.panel != null)
{
if (handle != null)
{

m_Presenter = BuildPresenters();
graphView.presenter = m_Presenter;
handle = graphView.panel.dataWatch.AddWatch(graphView, m_Presenter, OnChanged);
presenter = BuildPresenters();
graphView.presenter = presenter;
handle = graphView.panel.dataWatch.AddWatch(graphView, presenter, OnChanged);
}
}
}

3
MaterialGraphProject/Assets/NewUI/Editor/ISelectable.cs


using UnityEngine;
using UnityEngine.RMGUI;
namespace RMGUI.GraphView
{

bool Overlaps(Rect rectangle);
EventPropagation Select(VisualContainer selectionContainer, Event evt);
}
}

26
MaterialGraphProject/Assets/NewUI/Editor/Manipulators/ClickSelector.cs


phaseInterest = EventPhase.Capture;
activators.Add(new ManipActivator {button = MouseButton.LeftMouse});
activators.Add(new ManipActivator {button = MouseButton.RightMouse});
activators.Add(new ManipActivator {button = MouseButton.LeftMouse, modifiers = KeyModifiers.Ctrl});
activators.Add(new ManipActivator {button = MouseButton.LeftMouse, modifiers = KeyModifiers.Shift});
}
public override EventPropagation HandleEvent(Event evt, VisualElement finalTarget)

return EventPropagation.Continue;
}
var graphView = target as GraphView;
if (graphView == null)
{
throw new InvalidOperationException("Manipulator can only be added to a GraphView");
}
if (graphView.selection.Contains(selectable))
{
if (evt.control)
{
graphView.RemoveFromSelection(selectable);
return EventPropagation.Stop;
}
break;
}
var ve = selectable as VisualElement;
if (ve != null && ve.parent == graphView.contentViewContainer)
var ve = selectable as GraphElement;
if (ve != null)
if (!evt.control)
graphView.ClearSelection();
graphView.AddToSelection(selectable);
return ve.Select(target as VisualContainer, evt);
}
}
break;

16
MaterialGraphProject/Assets/NewUI/Editor/Manipulators/Dragger.cs


public Vector2 panSpeed { get; set; }
// hold the presenter... maybe.
public GraphElementPresenter m_presenter { get; set; }
public GraphElementPresenter presenter { get; set; }
public bool clampToParentEdges { get; set; }

var graphElement = target as GraphElement;
if (graphElement != null)
{
m_presenter = graphElement.presenter;
presenter = graphElement.presenter;
}
m_Start = evt.mousePosition;

break;
case EventType.MouseDrag:
if (this.HasCapture() && target.positionType == PositionType.Absolute)
if (this.HasCapture() && target.positionType == PositionType.Manual)
if (m_presenter != null)
if (presenter != null)
m_presenter.position = CalculatePosition(m_presenter.position.x + diff.x,
m_presenter.position.y + diff.y,
m_presenter.position.width, target.position.height);
presenter.position = CalculatePosition(presenter.position.x + diff.x,
presenter.position.y + diff.y,
presenter.position.width, target.position.height);
}
else
{

case EventType.MouseUp:
if (CanStopManipulation(evt))
{
m_presenter = null;
presenter = null;
this.ReleaseCapture();
return EventPropagation.Stop;
}

14
MaterialGraphProject/Assets/NewUI/Editor/Manipulators/EdgeConnector.cs


namespace RMGUI.GraphView
{
internal abstract class EdgeConnector : MouseManipulator
public abstract class EdgeConnector : MouseManipulator
internal class EdgeConnector<TEdgePresenter> : EdgeConnector where TEdgePresenter : EdgePresenter
public class EdgeConnector<TEdgePresenter> : EdgeConnector where TEdgePresenter : EdgePresenter
{
private List<NodeAnchorPresenter> m_CompatibleAnchors;
private TEdgePresenter m_EdgePresenterCandidate;

this.TakeCapture();
// get all available connectors
m_CompatibleAnchors = m_GraphView.allChildren
.OfType<NodeAnchor>()
.Select(na => na.GetPresenter<NodeAnchorPresenter>())
.Where(nap => nap.IsConnectable() &&
nap.orientation == startAnchor.orientation &&
nap.direction != startAnchor.direction &&
s_nodeAdapter.GetAdapter(nap.source, startAnchor.source) != null)
.ToList();
m_CompatibleAnchors = m_GraphViewPresenter.GetCompatibleAnchors(startAnchor, s_nodeAdapter);
foreach (var compatibleAnchor in m_CompatibleAnchors)
{

47
MaterialGraphProject/Assets/NewUI/Editor/Manipulators/SelectionDragger.cs


{
public class SelectionDragger : Dragger
{
// selectedElement is used to store a unique selection candidate for cases where user clicks on an item not to
// drag it but just to reset the selection -- we only know this after the manipulation has ended
GraphElement selectedElement { get; set; }
public SelectionDragger()
{
activators.Add(new ManipActivator {button = MouseButton.LeftMouse});

switch (evt.type)
{
case EventType.MouseDown:
selectedElement = null;
if (CanStartManipulation(evt))
{
// avoid starting a manipulation on a non movable object

return EventPropagation.Continue;
}
GraphElementPresenter presenter = ce.presenter;
if (presenter != null && ((ce.presenter.capabilities & Capabilities.Movable) != Capabilities.Movable))
selectedElement = ce;
GraphElementPresenter elementPresenter = ce.presenter;
if (elementPresenter != null && ((ce.presenter.capabilities & Capabilities.Movable) != Capabilities.Movable))
return EventPropagation.Continue;
this.TakeCapture();

if (ce == null || ce.presenter == null)
continue;
GraphElementPresenter presenter = ce.presenter;
if ((ce.presenter.capabilities & Capabilities.Movable) != Capabilities.Movable)
continue;

presenter.position = CalculatePosition(presenter.position.x + evt.delta.x * panSpeed.x / scale.x,
presenter.position.y + evt.delta.y * panSpeed.y / scale.y,
presenter.position.width, presenter.position.height);
ce.position = CalculatePosition(ce.position.x + evt.delta.x * panSpeed.x / scale.x,
ce.position.y + evt.delta.y * panSpeed.y / scale.y,
ce.position.width, ce.position.height);
selectedElement = null;
return EventPropagation.Stop;
}

if (CanStopManipulation(evt))
{
foreach (var presenter in graphView.selection.OfType<GraphElement>()
.Select(ge => ge.presenter)
.Where(pr => pr != null))
if (selectedElement != null && !evt.control)
{
// Since we didn't drag after all, update selection with current element only
graphView.ClearSelection();
graphView.AddToSelection(selectedElement);
}
else
presenter.CommitChanges();
foreach (ISelectable s in graphView.selection)
{
GraphElement ce = s as GraphElement;
if (ce == null || ce.presenter == null)
continue;
GraphElementPresenter elementPresenter = ce.presenter;
if ((ce.presenter.capabilities & Capabilities.Movable) != Capabilities.Movable)
continue;
elementPresenter.position = ce.position;
elementPresenter.CommitChanges();
}
}
this.ReleaseCapture();
return EventPropagation.Stop;

11
MaterialGraphProject/Assets/NewUI/Editor/Views/GraphView.cs


namespace RMGUI.GraphView
{
[StyleSheet("Assets/NewUI/Editor/Views/GraphView.uss")]
public abstract class GraphView : DataWatchContainer, ISelection
{
private GraphViewPresenter m_Presenter;

}
}
protected GraphViewTypeMapper typeMapper { get; set; }
protected GraphViewTypeFactory typeFactory { get; set; }
public VisualContainer contentViewContainer{ get; private set; }

// make it absolute and 0 sized so it acts as a transform to move children to and fro
AddChild(contentViewContainer);
typeMapper = new GraphViewTypeMapper();
typeMapper[typeof(EdgePresenter)] = typeof(Edge);
typeFactory = new GraphViewTypeFactory();
typeFactory[typeof(EdgePresenter)] = typeof(Edge);
AddStyleSheetPath("GraphView");
}
public override void OnDataChanged()

private void InstantiateElement(GraphElementPresenter elementPresenter)
{
// call factory
GraphElement newElem = typeMapper.Create(elementPresenter);
GraphElement newElem = typeFactory.Create(elementPresenter);
if (newElem == null)
{

15
MaterialGraphProject/Assets/NewUI/Editor/Views/Presenters/GraphViewPresenter.cs


[SerializeField]
private List<GraphElementPresenter> m_TempElements = new List<GraphElementPresenter>();
public IEnumerable<GraphElementPresenter> allChildren
{
get { return m_Elements.SelectMany(e => e.allElements); }
}
public virtual void AddElement(GraphElementPresenter element)
{
m_Elements.Add(element);

public void ClearTempElements()
{
m_TempElements.Clear();
}
public virtual List<NodeAnchorPresenter> GetCompatibleAnchors(NodeAnchorPresenter startAnchor, NodeAdapter nodeAdapter)
{
return allChildren.OfType<NodeAnchorPresenter>()
.Where(nap => nap.IsConnectable() &&
nap.orientation == startAnchor.orientation &&
nap.direction != startAnchor.direction &&
nodeAdapter.GetAdapter(nap.source, startAnchor.source) != null)
.ToList();
}
}
}

6
MaterialGraphProject/Assets/NewUI/Editor/BaseTypeFactory.cs


namespace RMGUI.GraphView
{
public abstract class BaseTypeMapper<TKey, TValue>
public abstract class BaseTypeFactory<TKey, TValue>
{
private readonly Dictionary<Type, Type> m_Mappings = new Dictionary<Type, Type>();
private readonly Type m_FallbackType;

static BaseTypeMapper()
static BaseTypeFactory()
{
k_KeyType = typeof(TKey);
k_ValueType = typeof(TValue);

return InternalCreate(valueType);
}
protected BaseTypeMapper(Type fallbackType)
protected BaseTypeFactory(Type fallbackType)
{
m_FallbackType = fallbackType;
}

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


namespace UnityEditor.MaterialGraph.Drawing
{
[StyleSheet("Assets/UnityShaderEditor/Editor/Drawing/Styles/MaterialGraph.uss")]
public class MaterialGraphView : SerializableGraphView
{
public MaterialGraphView()

typeMapper[typeof(MaterialNodePresenter)] = typeof(MaterialNodeDrawer);
typeMapper[typeof(GraphAnchorPresenter)] = typeof(NodeAnchor);
typeMapper[typeof(EdgePresenter)] = typeof(Edge);
typeFactory[typeof(MaterialNodePresenter)] = typeof(MaterialNodeDrawer);
typeFactory[typeof(GraphAnchorPresenter)] = typeof(NodeAnchor);
typeFactory[typeof(EdgePresenter)] = typeof(Edge);
AddStyleSheetPath("Styles/MaterialGraph");
}
public virtual bool CanAddToNodeMenu(Type type)

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


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

19
MaterialGraphProject/Assets/NewUI/Editor/GraphViewTypeFactory.cs


namespace RMGUI.GraphView
{
public class GraphViewTypeFactory : BaseTypeFactory<GraphElementPresenter, GraphElement>
{
public GraphViewTypeFactory() : base(typeof(FallbackGraphElement))
{
}
public override GraphElement Create(GraphElementPresenter key)
{
GraphElement elem = base.Create(key);
if (elem != null)
{
elem.presenter = key;
}
return elem;
}
}
}

9
MaterialGraphProject/Assets/NewUI/Editor/Resources.meta


fileFormatVersion: 2
guid: 6d40cd199cd12fc49a0df68ddc6df571
folderAsset: yes
timeCreated: 1485535607
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

9
MaterialGraphProject/Assets/NewUI/Editor/Tests.meta


fileFormatVersion: 2
guid: b2560520f376cff4fafb59cc64b17240
folderAsset: yes
timeCreated: 1484754870
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

9
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Resources.meta


fileFormatVersion: 2
guid: c34a1714ab2ee6c47b8fb9a14777df23
folderAsset: yes
timeCreated: 1485544540
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

9
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Resources/Styles.meta


fileFormatVersion: 2
guid: 4ace90b2f1bf85d4cac2ba68f410be5a
folderAsset: yes
timeCreated: 1485544760
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

9
MaterialGraphProject/Assets/NewUI/Editor/Resources/Demo.meta


fileFormatVersion: 2
guid: d2d03d7c155093f448c2199943c167e4
folderAsset: yes
timeCreated: 1485535607
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

101
MaterialGraphProject/Assets/NewUI/Editor/Tests/GraphElementMoveTests.cs


using System.Collections;
using System.Linq;
using NUnit.Framework;
using RMGUI.GraphView;
using RMGUI.GraphView.Demo;
using UnityEditor;
using UnityEngine;
using UnityEngine.TestTools;
[UnityPlatform(TestPlatform.EditMode)]
public class GraphElementMoveTests
{
class TestViewPresenter : GraphViewPresenter
{
protected new void OnEnable()
{
base.OnEnable();
var movableElementPresenter = CreateInstance<SimpleElementPresenter>();
movableElementPresenter.position = new Rect(10, 30, 50, 50);
movableElementPresenter.title = "Movable element";
AddElement(movableElementPresenter);
var miniMapPresenter = CreateInstance<MiniMapPresenter>();
miniMapPresenter.position = new Rect(100, 100, 100, 100);
miniMapPresenter.maxWidth = 100;
miniMapPresenter.maxHeight = 100;
AddElement(miniMapPresenter);
}
protected TestViewPresenter() { }
}
class TestViewWindow : GraphViewEditorWindow
{
public static void ShowWindow()
{
GetWindow<TestViewWindow>();
}
protected override GraphView BuildView()
{
return new SimpleContentView();
}
protected override GraphViewPresenter BuildPresenters()
{
return CreateInstance<TestViewPresenter>();
}
}
[UnityTest]
public IEnumerator MovableElementCanBeDragged()
{
TestViewWindow window = EditorWindow.GetWindow<TestViewWindow>();
// Move the movable element.
window.SendEvent(new Event {type = EventType.MouseDown, mousePosition = new Vector2(15, 50)});
yield return null;
window.SendEvent(new Event {type = EventType.MouseDrag, delta = new Vector2(10, -10)});
yield return null;
window.SendEvent(new Event {type = EventType.MouseUp, mousePosition = new Vector2(25, 40)});
yield return null;
var winPres = window.GetPresenter<TestViewPresenter>();
var elemPres = winPres.elements.OfType<SimpleElementPresenter>().First();
Assert.AreEqual(20, elemPres.position.x);
Assert.AreEqual(20, elemPres.position.y);
window.Close();
yield return null;
}
[UnityTest]
public IEnumerator MiniMapElementCanBeDragged()
{
TestViewWindow window = EditorWindow.GetWindow<TestViewWindow>();
// Move the minimap element.
window.SendEvent(new Event {type = EventType.MouseDown, mousePosition = new Vector2(110, 130)});
yield return null;
window.SendEvent(new Event {type = EventType.MouseDrag, mousePosition = new Vector2(120, 120)});
yield return null;
window.SendEvent(new Event {type = EventType.MouseUp, mousePosition = new Vector2(120, 120)});
yield return null;
var winPres = window.GetPresenter<TestViewPresenter>();
var miniMapPres = winPres.elements.OfType<MiniMapPresenter>().First();
Assert.AreEqual(110, miniMapPres.position.x);
Assert.AreEqual(90, miniMapPres.position.y);
window.Close();
yield return null;
}
}

12
MaterialGraphProject/Assets/NewUI/Editor/Tests/GraphElementMoveTests.cs.meta


fileFormatVersion: 2
guid: 9dca2d640002b5f42a912502d74ba735
timeCreated: 1484754870
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

9
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Resources/Styles.meta


fileFormatVersion: 2
guid: 5f393962fcae179489132b01f969bb6e
folderAsset: yes
timeCreated: 1485544760
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

9
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Styles.meta


fileFormatVersion: 2
guid: 0bfdedf8c1122ce43a248236ef367ab3
folderAsset: yes
timeCreated: 1476713799
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

19
MaterialGraphProject/Assets/NewUI/Editor/GraphViewTypeMapper.cs


namespace RMGUI.GraphView
{
public class GraphViewTypeMapper : BaseTypeMapper<GraphElementPresenter, GraphElement>
{
public GraphViewTypeMapper() : base(typeof(FallbackGraphElement))
{
}
public override GraphElement Create(GraphElementPresenter key)
{
GraphElement elem = base.Create(key);
if (elem != null)
{
elem.presenter = key;
}
return elem;
}
}
}

9
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Styles.meta


fileFormatVersion: 2
guid: 55206ee1a8b96e84bb8a8a0bc7c58bd0
folderAsset: yes
timeCreated: 1475748087
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

/MaterialGraphProject/Assets/NewUI/Editor/BaseTypeMapper.cs.meta → /MaterialGraphProject/Assets/NewUI/Editor/BaseTypeFactory.cs.meta

/MaterialGraphProject/Assets/NewUI/Editor/GraphViewTypeMapper.cs.meta → /MaterialGraphProject/Assets/NewUI/Editor/GraphViewTypeFactory.cs.meta

/MaterialGraphProject/Assets/NewUI/Editor/BaseTypeMapper.cs → /MaterialGraphProject/Assets/NewUI/Editor/BaseTypeFactory.cs

/MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Styles → /MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Resources/Styles

/MaterialGraphProject/Assets/NewUI/Editor/Demo/Views/SimpleContentView.uss.meta → /MaterialGraphProject/Assets/NewUI/Editor/Resources/Demo/SimpleContentView.uss.meta

/MaterialGraphProject/Assets/NewUI/Editor/Demo/Views/SimpleContentView.uss → /MaterialGraphProject/Assets/NewUI/Editor/Resources/Demo/SimpleContentView.uss

/MaterialGraphProject/Assets/NewUI/Editor/Views/GraphView.uss → /MaterialGraphProject/Assets/NewUI/Editor/Resources/GraphView.uss

/MaterialGraphProject/Assets/NewUI/Editor/Views/GraphView.uss.meta → /MaterialGraphProject/Assets/NewUI/Editor/Resources/GraphView.uss.meta

/MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Styles → /MaterialGraphProject/Assets/UnityShaderEditor/Editor/Resources/Styles

/MaterialGraphProject/Assets/NewUI/Editor/DataWatchTests/DataWatchTests.cs.meta → /MaterialGraphProject/Assets/NewUI/Editor/Tests/DataWatchTests.cs.meta

/MaterialGraphProject/Assets/NewUI/Editor/DataWatchTests/DataWatchTests.cs → /MaterialGraphProject/Assets/NewUI/Editor/Tests/DataWatchTests.cs

正在加载...
取消
保存