private static void HandleMouse(GameObject target, bool isVisible, bool isLocked, Rect visRect, Rect lockRect) { Event evt = Event.current; bool toggleActive = visRect.Contains(evt.mousePosition); bool toggleLock = lockRect.Contains(evt.mousePosition); bool stateChanged = (toggleActive || toggleLock); bool doMouse = false; switch (evt.type) { case EventType.MouseDown: // Checking is frame fresh so mouse state is only tested once per frame // instead of every time a hierarchy item is drawn bool isMouseDown = false; if (isFrameFresh && stateChanged) { isMouseDown = !isMousePressed; isMousePressed = true; isFrameFresh = false; } if (stateChanged && isMouseDown) { doMouse = true; if (toggleActive) isVisible = !isVisible; if (toggleLock) isLocked = !isLocked; propagateState = new PropagateState(toggleActive, (toggleActive) ? isVisible : isLocked); evt.Use(); } break; case EventType.MouseDrag: doMouse = isMousePressed; break; case EventType.DragPerform: case EventType.DragExited: case EventType.DragUpdated: case EventType.MouseUp: ResetVars(); break; } if (doMouse && stateChanged) { if (propagateState.isVisibility) SetVisible(target, propagateState.propagateValue); else SetLockObject(target, propagateState.propagateValue); EditorApplication.RepaintHierarchyWindow(); } }
private static void HandleMouse(GameObject target, bool isVisible, bool isLocked, Rect visRect, Rect lockRect) { Event evt = Event.current; bool toggleActive = visRect.Contains(evt.mousePosition); bool toggleLock = lockRect.Contains(evt.mousePosition); bool stateChanged = (toggleActive || toggleLock); bool doMouse = false; switch (evt.type) { case EventType.MouseDown: // Checking is frame fresh so mouse state is only tested once per frame // instead of every time a hierarchy item is drawn bool isMouseDown = false; if (isFrameFresh && stateChanged) { isMouseDown = !isMousePressed; isMousePressed = true; isFrameFresh = false; } if (stateChanged && isMouseDown) { doMouse = true; if (toggleActive) { isVisible = !isVisible; } if (toggleLock) { isLocked = !isLocked; } propagateState = new PropagateState(toggleActive, (toggleActive) ? isVisible : isLocked); evt.Use(); } break; case EventType.MouseDrag: doMouse = isMousePressed; break; case EventType.DragPerform: case EventType.DragExited: case EventType.DragUpdated: case EventType.MouseUp: ResetVars(); break; } if (doMouse && stateChanged) { if (propagateState.isVisibility) { SetVisible(target, propagateState.propagateValue); } else { SetLockObject(target, propagateState.propagateValue); } EditorApplication.RepaintHierarchyWindow(); } }