Skip to content

Commit

Permalink
paste nodes next to the mouse position
Browse files Browse the repository at this point in the history
  • Loading branch information
z3y committed Sep 20, 2024
1 parent 8ebb08c commit c66a956
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
20 changes: 15 additions & 5 deletions Editor/ShaderGraphView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ public class ShaderGraphView : GraphView
public VisualElement additionalNodeElements;
public int uniqueID = 0;

public Vector2 lastMousePos;
public Vector2 copyMousePos;


public Material PreviewMaterial = new(Shader.Find("Unlit/Color"))
{
hideFlags = HideFlags.HideAndDontSave
Expand Down Expand Up @@ -48,6 +52,7 @@ public ShaderGraphView(ShaderGraphWindow editorWindow, string assetPath)
this.AddManipulator(new ContentDragger());
this.AddManipulator(new SelectionDragger());
this.AddManipulator(new RectangleSelector());
RegisterCallback<MouseMoveEvent>(OnMouseMoveEvent);
this.AddManipulator(CreateGroupContextualMenu());

// background
Expand Down Expand Up @@ -123,6 +128,11 @@ void LoopDetection(GraphViewChange change)
}
}

void OnMouseMoveEvent(MouseMoveEvent evt)
{
lastMousePos = contentViewContainer.WorldToLocal(evt.mousePosition);
}

bool LoopDetection(string startGUID, Edge edge)
{
var connectedNode = (ShaderNode)edge.input.node;
Expand Down Expand Up @@ -171,7 +181,7 @@ public string SerializeGraphElementsImpl(IEnumerable<GraphElement> elements)
}
}


copyMousePos = lastMousePos;
//_lastCopyGraph = JsonUtility.ToJson(data, false);
return JsonUtility.ToJson(data, false);
}
Expand All @@ -181,11 +191,11 @@ public void UnserializeAndPasteImpl(string operationName, string jsonData)
//RecordUndo();

var data = JsonUtility.FromJson<SerializableGraph>(jsonData);
//var data = _lastCopyGraph;

//Vector2 mousePosition = new Vector2(-200, -200);
//ShaderGraphImporter.DeserializeNodesToGraph(data, this, mousePosition);
var graphElements = data.PasteElementsAndOverwiteGuids(this, new Vector2(100, -100));
var offset = lastMousePos - copyMousePos;
//TransformMousePositionToLocalSpace(ref offset, true);

var graphElements = data.PasteElementsAndOverwiteGuids(this, offset);

ClearSelection();

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "com.z3y.graphlit",
"version": "1.0.7",
"version": "1.0.8",
"unity": "2022.3",
"displayName": "Graphlit",
"hideInEditor": false,
Expand Down

0 comments on commit c66a956

Please sign in to comment.