public void HandleEvent(EventType eventType, int button, Vector2 mousePosition) { var selectableContainers = USHierarchy.ISelectableContainers(); var allObjectsUnderMouse = new List <UnityEngine.Object>(); var hasObjectsUnderMouse = false; objectContainerMap.Clear(); foreach (var selectableContainer in selectableContainers) { var objectsUnderMouse = new List <UnityEngine.Object>(); if (IsBoxSelecting && HasStartedDrag) { objectsUnderMouse = selectableContainer.GetSelectableObjectsUnderRect(SelectionArea, ScrollInfo.currentScroll.y); } else { objectsUnderMouse = selectableContainer.GetSelectableObjectUnderPos(mousePosition); } allObjectsUnderMouse.AddRange(objectsUnderMouse); if (objectsUnderMouse.Count > 0) { hasObjectsUnderMouse = true; } objectContainerMap[selectableContainer] = objectsUnderMouse; } switch (eventType) { case EventType.MouseDown: { HasProcessedInitialDrag = false; IsDragging = false; IsBoxSelecting = false; DragStartPosition = mousePosition; if (!hasObjectsUnderMouse && Event.current.button == 0) { IsBoxSelecting = true; } if (hasObjectsUnderMouse && Event.current.button == 0) { IsDragging = true; } if (IsDragging && Event.current.alt && Event.current.control) { IsDuplicating = true; } // if we have no objects under our mouse, then we are likely trying to clear our selection if (!hasObjectsUnderMouse && (!Event.current.control && !Event.current.command)) { foreach (var selectableContainer in selectableContainers) { selectableContainer.ResetSelection(); } } if (!Event.current.control && !Event.current.command) { Selection.activeGameObject = null; Selection.activeObject = null; Selection.activeTransform = null; Selection.objects = new UnityEngine.Object[] { }; } HasStartedDrag = false; SequenceWindow.Repaint(); } break; case EventType.MouseDrag: { if (!HasStartedDrag) { HasStartedDrag = true; } SequenceWindow.Repaint(); } break; case EventType.MouseUp: { HasProcessedInitialDrag = false; IsBoxSelecting = false; IsDragging = false; IsDuplicating = false; HasDuplicated = false; SequenceWindow.Repaint(); } break; } if (IsBoxSelecting && HasStartedDrag && eventType == EventType.MouseDrag) { foreach (var selectableContainer in selectableContainers) { var objectsUnderSelection = objectContainerMap[selectableContainer]; var difference = objectsUnderSelection.Where(selectedObject => !selectableContainer.SelectedObjects.Contains(selectedObject)).ToList(); if (difference.Count > 0 || (selectableContainer.SelectedObjects.Count != objectsUnderSelection.Count)) { EditorGUI.FocusTextInControl(""); selectableContainer.ResetSelection(); selectableContainer.OnSelectedObjects(objectsUnderSelection); } } } if ((!Event.current.control && !Event.current.command) && hasObjectsUnderMouse && !HasStartedDrag && (eventType == EventType.MouseUp || (eventType == EventType.MouseDown && button == 1))) { foreach (var selectableContainer in selectableContainers) { EditorGUI.FocusTextInControl(""); var objectsUnderSelection = objectContainerMap[selectableContainer]; selectableContainer.ResetSelection(); selectableContainer.OnSelectedObjects(objectsUnderSelection); } if (allObjectsUnderMouse.Count == 1) { var internalKeyframe = allObjectsUnderMouse[0] as USInternalKeyframe; if (internalKeyframe) { SequenceWindow.SetRunningTime(internalKeyframe.Time); } var observerKeyframe = allObjectsUnderMouse[0] as USObserverKeyframe; if (observerKeyframe) { Selection.activeObject = observerKeyframe; } var eventBase = allObjectsUnderMouse[0] as USEventBase; if (eventBase) { Selection.activeGameObject = eventBase.gameObject; Selection.activeTransform = eventBase.transform; } } } else if ((Event.current.control || Event.current.command) && hasObjectsUnderMouse && !HasStartedDrag && eventType == EventType.MouseUp) { foreach (var selectableContainer in selectableContainers) { var objectsUnderSelection = objectContainerMap[selectableContainer]; foreach (var selectedObject in objectsUnderSelection) { if (!selectableContainer.SelectedObjects.Contains(selectedObject)) { selectableContainer.OnSelectedObjects(new List <UnityEngine.Object> { selectedObject }); } else { selectableContainer.OnDeSelectedObjects(new List <UnityEngine.Object> { selectedObject }); } } } } else if (IsDragging && HasStartedDrag) { DragStartPosition = new Vector2(DragStartPosition.x, DragStartPosition.y); var mouseDelta = Event.current.mousePosition - DragStartPosition; if (!HasProcessedInitialDrag) { foreach (var selectableContainer in selectableContainers) { // if our under mouse isn't currently selected, clear our selection var objectsUnderSelection = objectContainerMap[selectableContainer]; if (objectsUnderSelection.Count == 1 && !selectableContainer.SelectedObjects.Contains(objectsUnderSelection[0]) && !Event.current.control && !Event.current.command) { selectableContainer.ResetSelection(); EditorGUI.FocusTextInControl(""); } selectableContainer.OnSelectedObjects(objectsUnderSelection); selectableContainer.StartDraggingObjects(); } HasProcessedInitialDrag = true; } if (IsDuplicating && !HasDuplicated) { foreach (var selectableContainer in selectableContainers) { selectableContainer.DuplicateSelection(); } HasDuplicated = true; } else { foreach (var selectableContainer in selectableContainers) { selectableContainer.ProcessDraggingObjects(mouseDelta, Snap, TimeToContentX(SnapAmount)); } } } else if (!HasStartedDrag && !hasObjectsUnderMouse && eventType == EventType.MouseUp) { foreach (var selectableContainer in selectableContainers) { selectableContainer.ResetSelection(); } var selectableArea = USHierarchy.VisibleArea; if (selectableArea.Contains(Event.current.mousePosition)) { EditorGUI.FocusTextInControl(""); } } }