浏览代码

[MaterialGraph]Allow connection code back in + delete edges

/main
Tim Cooper 8 年前
当前提交
36e3583e
共有 6 个文件被更改,包括 51 次插入26 次删除
  1. 21
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/MaterialGraphDataSource.cs
  2. 16
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/MaterialGraphView.cs
  3. 15
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/MaterialNodeAnchorData.cs
  4. 6
      MaterialGraphProject/Assets/NewUI/Editor/Demo/Views/Data/NodalViewData.cs
  5. 10
      MaterialGraphProject/Assets/NewUI/Editor/Manipulators/ContentDragger.cs
  6. 9
      MaterialGraphProject/Assets/NewUI/Editor/Manipulators/EdgeConnector.cs

21
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/MaterialGraphDataSource.cs


drawableNodes.Add(nodeData);
}
var drawableEdges = new List<EdgeData>();
var drawableEdges = new List<MaterialEdgeData>();
foreach (var addedNode in drawableNodes)
{
var baseNode = addedNode.node;

var targetAnchors = targetNode.elements.OfType<MaterialNodeAnchorData>();
var targetAnchor = targetAnchors.FirstOrDefault(x => x.slot == toSlot);
var edgeData = ScriptableObject.CreateInstance<EdgeData>();
var edgeData = ScriptableObject.CreateInstance<MaterialEdgeData>();
edgeData.Initialize (edge);
edgeData.left = sourceAnchor;
edgeData.right = targetAnchor;
drawableEdges.Add(edgeData);

UpdateData();
}
public void RemoveNodes(IEnumerable<MaterialNodeData> nodes)
public void RemoveElements(IEnumerable<MaterialNodeData> nodes, IEnumerable<MaterialEdgeData> edges)
var toDelete = nodes.Select(x => x.node).ToList();
graphAsset.graph.RemoveElements(toDelete, new List<IEdge> (){});
graphAsset.graph.RemoveElements(nodes.Select(x => x.node), edges.Select(x => x.edge));
graphAsset.graph.ValidateGraph();
UpdateData ();
}

public void AddElement(GraphElementData element)
{
var edge = element as EdgeData;
if (edge.candidate == false)
{
var left = edge.left as MaterialNodeAnchorData;
var right = edge.right as MaterialNodeAnchorData;
if (left && right)
graphAsset.graph.Connect (left.slot.slotReference, right.slot.slotReference);
UpdateData ();
return;
}
m_Elements.Add(element);
}

16
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/MaterialGraphView.cs


dictionary[Event.KeyboardEvent("delete")] = DeleteSelection;
contentViewContainer.AddManipulator(new ShortcutHandler(dictionary));
AddManipulator(new ContentZoomer());
AddManipulator(new ContentDragger());
AddManipulator(new RectangleSelector());

dataMapper[typeof(MaterialNodeData)] = typeof(MaterialGraphNode);
dataMapper[typeof(NodeAnchorData)] = typeof(NodeAnchor);
dataMapper[typeof(EdgeData)] = typeof(RMGUI.GraphView.Edge);
}
private EventPropagation DeleteSelection()

return EventPropagation.Stop;
// TODO We will want to move this up to GraphView
var elementsToRemove = new List<MaterialNodeData>();
foreach (var selectedElement in selection.OfType<MaterialGraphNode>())
{
var nodeData = selectedElement.dataProvider as MaterialNodeData;
if (nodeData != null)
elementsToRemove.Add(nodeData);
}
nodalViewData.RemoveNodes(elementsToRemove);
nodalViewData.RemoveElements(
selection.OfType<MaterialGraphNode>().Select(x => x.dataProvider as MaterialNodeData),
selection.OfType<RMGUI.GraphView.Edge>().Select(x => x.dataProvider as MaterialEdgeData)
);
return EventPropagation.Stop;
}

15
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/MaterialNodeAnchorData.cs


namespace UnityEditor.Graphing.Drawing
{
[Serializable]
public class MaterialEdgeData : EdgeData
{
protected MaterialEdgeData()
{}
public UnityEngine.Graphing.IEdge edge { get; private set; }
public void Initialize(UnityEngine.Graphing.IEdge inEdge)
{
edge = inEdge;
}
}
[Serializable]
public class MaterialNodeAnchorData : NodeAnchorData
{

6
MaterialGraphProject/Assets/NewUI/Editor/Demo/Views/Data/NodalViewData.cs


return true;
}
internal static bool Adapt(this NodeAdapter value, PortSource<Vector4> a, PortSource<Vector4> b)
{
// run adapt code for vec4 to vec4 connections
return true;
}
internal static bool Adapt(this NodeAdapter value, PortSource<Color> a, PortSource<Color> b)
{
// run adapt code for Color to Color connections

10
MaterialGraphProject/Assets/NewUI/Editor/Manipulators/ContentDragger.cs


private Vector2 m_Start;
public Vector2 panSpeed { get; set; }
public MouseButton activateButton { get; set; }
activateButton = MouseButton.MiddleMouse;
panSpeed = new Vector2(1, 1);
clampToParentEdges = false;
}

switch (evt.type)
{
case EventType.MouseDown:
if (evt.button == (int) activateButton)
if (evt.button == (int) MouseButton.MiddleMouse
|| evt.button == (int) MouseButton.LeftMouse && evt.modifiers == EventModifiers.Alt)
{
this.TakeCapture();

break;
case EventType.MouseUp:
if (this.HasCapture() && evt.button == (int) activateButton)
if (this.HasCapture()
&& (evt.button == (int) MouseButton.MiddleMouse
|| evt.button == (int) MouseButton.MiddleMouse))
{
this.ReleaseCapture();
return EventPropagation.Stop;

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


// Not a candidate anymore, let's see if we're actually going to add it to parent
m_EdgeDataCandidate.candidate = false;
if (m_EdgeDataCandidate.right == null)
m_DataSource.RemoveElement(m_EdgeDataCandidate);
if (m_EdgeDataCandidate.right != null)
m_DataSource.RemoveElement(m_EdgeDataCandidate);
}
else
{
m_DataSource.AddElement(m_EdgeDataCandidate);
m_EdgeDataCandidate.left.connected = true;
m_EdgeDataCandidate.right.connected = true;
}

正在加载...
取消
保存