mirror of
https://github.com/Siccity/xNode.git
synced 2026-02-06 07:14:56 +08:00
Added 'remove node'
This commit is contained in:
parent
42bb9a927a
commit
eec282f4bc
Binary file not shown.
@ -4,7 +4,7 @@ using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace XNode.Examples.RuntimeMathNodes {
|
||||
public class NodeDrag : MonoBehaviour, IPointerDownHandler, IDragHandler, IEndDragHandler {
|
||||
public class NodeDrag : MonoBehaviour, IPointerClickHandler, IBeginDragHandler, IDragHandler, IEndDragHandler {
|
||||
private Vector3 offset;
|
||||
private UGUIMathBaseNode node;
|
||||
|
||||
@ -16,7 +16,7 @@ namespace XNode.Examples.RuntimeMathNodes {
|
||||
node.transform.localPosition = node.graph.scrollRect.content.InverseTransformPoint(eventData.position) - offset;
|
||||
}
|
||||
|
||||
public void OnPointerDown(PointerEventData eventData) {
|
||||
public void OnBeginDrag(PointerEventData eventData) {
|
||||
Vector2 pointer = node.graph.scrollRect.content.InverseTransformPoint(eventData.position);
|
||||
Vector2 pos = node.transform.localPosition;
|
||||
offset = pointer - pos;
|
||||
@ -28,5 +28,13 @@ namespace XNode.Examples.RuntimeMathNodes {
|
||||
pos.y = -pos.y;
|
||||
node.node.position = pos;
|
||||
}
|
||||
|
||||
public void OnPointerClick(PointerEventData eventData) {
|
||||
if (eventData.button != PointerEventData.InputButton.Right)
|
||||
return;
|
||||
|
||||
node.graph.nodeContextMenu.selectedNode = node.node;
|
||||
node.graph.nodeContextMenu.OpenAt(eventData.position);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -16,7 +16,8 @@ namespace XNode.Examples.RuntimeMathNodes {
|
||||
public XNode.Examples.RuntimeMathNodes.UGUIDisplayValue runtimeDisplayValuePrefab;
|
||||
public XNode.Examples.RuntimeMathNodes.Connection runtimeConnectionPrefab;
|
||||
[Header("References")]
|
||||
public UGUIContextMenu contextMenu;
|
||||
public UGUIContextMenu graphContextMenu;
|
||||
public UGUIContextMenu nodeContextMenu;
|
||||
public UGUITooltip tooltip;
|
||||
|
||||
public ScrollRect scrollRect { get; private set; }
|
||||
@ -26,8 +27,8 @@ namespace XNode.Examples.RuntimeMathNodes {
|
||||
// Create a clone so we don't modify the original asset
|
||||
graph = graph.Copy() as MathGraph;
|
||||
scrollRect = GetComponentInChildren<ScrollRect>();
|
||||
contextMenu.onClickSpawn -= SpawnNode;
|
||||
contextMenu.onClickSpawn += SpawnNode;
|
||||
graphContextMenu.onClickSpawn -= SpawnNode;
|
||||
graphContextMenu.onClickSpawn += SpawnNode;
|
||||
}
|
||||
|
||||
private void Start() {
|
||||
@ -88,7 +89,7 @@ namespace XNode.Examples.RuntimeMathNodes {
|
||||
if (eventData.button != PointerEventData.InputButton.Right)
|
||||
return;
|
||||
|
||||
contextMenu.OpenAt(eventData.position);
|
||||
graphContextMenu.OpenAt(eventData.position);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -9,7 +9,7 @@ namespace XNode.Examples.RuntimeMathNodes {
|
||||
|
||||
public Action<Type, Vector2> onClickSpawn;
|
||||
public CanvasGroup group;
|
||||
|
||||
[HideInInspector] public Node selectedNode;
|
||||
private Vector2 pos;
|
||||
|
||||
private void Start() {
|
||||
@ -47,6 +47,13 @@ namespace XNode.Examples.RuntimeMathNodes {
|
||||
onClickSpawn(nodeType, pos);
|
||||
}
|
||||
|
||||
public void RemoveNode() {
|
||||
RuntimeMathGraph runtimeMathGraph = GetComponentInParent<RuntimeMathGraph>();
|
||||
runtimeMathGraph.graph.RemoveNode(selectedNode);
|
||||
runtimeMathGraph.Refresh();
|
||||
Close();
|
||||
}
|
||||
|
||||
public void OnPointerExit(PointerEventData eventData) {
|
||||
Close();
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user