private void OnEvent(Event e, Vector2 size) { if (e.type == EventType.MouseDown && e.button <= 1) { OnClick(e.control, e.button == 0); e.Use(); return; } if (e.type == EventType.MouseUp) { if (DragMode != null && e.button == 0) { DragMode.OnDragEnd(this, Canvas.MouseInWorld); DragMode = null; e.Use(); return; } if (e.button == 1) { e.Use(); if (!ignoreRightUp) { OnMenu(); } ignoreRightUp = false; return; } } if (e.type == EventType.MouseDrag) { if (DragMode != null && e.button == 0) { DragMode.OnDrag(this, Canvas.MouseInWorld); e.Use(); return; } if (e.button == 2 || (e.button == 1 && Selecteds.Count == 0)) { //移动View Canvas.Pan(-e.delta); e.Use(); ignoreRightUp = true; return; } if (e.button == 0) { Rect rect = new Rect(Vector2.zero, size); if (rect.Contains(e.mousePosition)) { if (Selecteds.Count > 0 && !ReadOnly) { DragMode = new ViewNormalMoveMode(this, Canvas.PointInWorld); } else { DragMode = new ViewAreaSelectMode(this, Canvas.PointInWorld); } } } } if (e.type == EventType.KeyDown) { if (e.keyCode == KeyCode.Delete && !ReadOnly) { if (Selecteds.Count > 0) { if (DeleteSelectedNode()) { e.Use(); } } return; } bool control = (e.control || (Application.platform == RuntimePlatform.OSXEditor && e.command)) && !e.alt; if (control && e.keyCode == KeyCode.D && !ReadOnly) { if (Duplicate()) { e.Use(); return; } } if (control && e.keyCode == KeyCode.C) { CopyNodes(); e.Use(); return; } if (control && e.keyCode == KeyCode.V && !ReadOnly) { PasteFromClipboard(); e.Use(); return; } if (control && e.keyCode == KeyCode.A) { Selecteds.Clear(); foreach (var node in Graph.Nodes) { Selecteds.Add(node); } e.Use(); return; } } }