|
|
|
|
|
|
|
|
|
|
namespace UnityEditor.ShaderGraph.Drawing |
|
|
|
{ |
|
|
|
public sealed class MaterialGraphView : GraphView, IDropTarget |
|
|
|
public sealed class MaterialGraphView : GraphView |
|
|
|
{ |
|
|
|
public MaterialGraphView() |
|
|
|
{ |
|
|
|
|
|
|
unserializeAndPaste = UnserializeAndPasteImplementation; |
|
|
|
deleteSelection = DeleteSelectionImplementation; |
|
|
|
RegisterCallback<DragUpdatedEvent>(OnDragUpdatedEvent); |
|
|
|
RegisterCallback<DragPerformEvent>(OnDragPerformEvent); |
|
|
|
} |
|
|
|
|
|
|
|
protected override bool canCopySelection |
|
|
|
|
|
|
selection.Clear(); |
|
|
|
} |
|
|
|
|
|
|
|
public bool CanAcceptDrop(List<ISelectable> selection) |
|
|
|
#region Drag and drop
|
|
|
|
|
|
|
|
static void OnDragUpdatedEvent(DragUpdatedEvent e) |
|
|
|
return selection.OfType<BlackboardField>().Any(); |
|
|
|
var selection = DragAndDrop.GetGenericData("DragSelection") as List<ISelectable>; |
|
|
|
|
|
|
|
if (selection != null && (selection.OfType<BlackboardField>().Any() )) |
|
|
|
{ |
|
|
|
DragAndDrop.visualMode = e.ctrlKey ? DragAndDropVisualMode.Copy : DragAndDropVisualMode.Move; |
|
|
|
} |
|
|
|
#if UNITY_2018_1
|
|
|
|
public EventPropagation DragUpdated(IMGUIEvent evt, IEnumerable<ISelectable> selection, IDropTarget dropTarget) |
|
|
|
void OnDragPerformEvent(DragPerformEvent e) |
|
|
|
return EventPropagation.Continue; |
|
|
|
} |
|
|
|
var selection = DragAndDrop.GetGenericData("DragSelection") as List<ISelectable>; |
|
|
|
if (selection == null) |
|
|
|
return; |
|
|
|
public EventPropagation DragPerform(IMGUIEvent evt, IEnumerable<ISelectable> selection, IDropTarget dropTarget) |
|
|
|
{ |
|
|
|
return EventPropagation.Continue; |
|
|
|
} |
|
|
|
IEnumerable<BlackboardField> fields = selection.OfType<BlackboardField>(); |
|
|
|
if (!fields.Any()) |
|
|
|
return; |
|
|
|
|
|
|
|
Vector2 localPos = (e.currentTarget as VisualElement).ChangeCoordinatesTo(contentViewContainer, e.localMousePosition); |
|
|
|
|
|
|
|
foreach (BlackboardField field in fields) |
|
|
|
{ |
|
|
|
IShaderProperty property = field.userData as IShaderProperty; |
|
|
|
if (property == null) |
|
|
|
continue; |
|
|
|
public EventPropagation DragExited() |
|
|
|
{ |
|
|
|
return EventPropagation.Continue; |
|
|
|
} |
|
|
|
#else
|
|
|
|
public bool DragUpdated(DragUpdatedEvent evt, IEnumerable<ISelectable> selection, IDropTarget dropTarget) |
|
|
|
{ |
|
|
|
return true; |
|
|
|
} |
|
|
|
var node = new PropertyNode(); |
|
|
|
public bool DragPerform(DragPerformEvent evt, IEnumerable<ISelectable> selection, IDropTarget dropTarget) |
|
|
|
{ |
|
|
|
return true; |
|
|
|
} |
|
|
|
var drawState = node.drawState; |
|
|
|
var position = drawState.position; |
|
|
|
position.x = localPos.x; |
|
|
|
position.y = localPos.y; |
|
|
|
drawState.position = position; |
|
|
|
node.drawState = drawState; |
|
|
|
bool IDropTarget.DragExited() |
|
|
|
{ |
|
|
|
return true; |
|
|
|
graph.owner.RegisterCompleteObjectUndo("Added Property"); |
|
|
|
graph.AddNode(node); |
|
|
|
node.propertyGuid = property.guid; |
|
|
|
} |
|
|
|
#endif
|
|
|
|
#endregion
|
|
|
|
} |
|
|
|
|
|
|
|
public static class GraphViewExtensions |
|
|
|
|
|
|
var remappedNodes = remappedNodesDisposable.value; |
|
|
|
var remappedEdges = remappedEdgesDisposable.value; |
|
|
|
graphView.graph.PasteGraph(copyGraph, remappedNodes, remappedEdges); |
|
|
|
|
|
|
|
|
|
|
|
if (graphView.graph.guid != copyGraph.sourceGraphGuid) |
|
|
|
{ |
|
|
|
// Compute the mean of the copied nodes.
|
|
|
|