private void Update() { if (CursorHelper.lockState == CursorLockMode.None) { return; } PlayerCamCtrlSettings settings = m_settings.PlayerCamCtrl[LocalPlayerIndex]; float cursorX = m_inputManager.GetAxisRaw(InputAction.CursorX, LocalPlayerIndex, false, false); float cursorY = m_inputManager.GetAxisRaw(InputAction.CursorY, LocalPlayerIndex, false, false); if (m_gameState.IsActionsMenuOpened(LocalPlayerIndex) || m_gameState.IsMenuOpened(LocalPlayerIndex) || m_gameState.IsPaused || m_gameState.IsPauseStateChanging || m_camPixelRect.size == Vector2.zero || m_boxSelector.IsActive) { if (m_prevMouseOffset != Vector3.zero) { CursorIconFromMouseOffset(Vector3.zero); m_prevMouseOffset = Vector3.zero; } if (m_isVirtualMouseEnabled) { m_clampCursorPadding = 1; VirtualMousePosition += new Vector2(cursorX, cursorY) * settings.CursorSensitivity; m_clampCursorPadding = 0; } AnimatePivotPoint(settings.MoveSensitivity / 2, settings.MoveSensitivity / 8); return; } Vector3 mouseOffset = GetVirtualMouseOffset(); if (IsInputEnabled && !m_lockInputDuringPivotAnimation) { float deltaY = m_inputManager.GetAxisRaw(InputAction.MoveForward, LocalPlayerIndex, true, false); float deltaX = m_inputManager.GetAxisRaw(InputAction.MoveSide, LocalPlayerIndex, true, false); bool rotateCamCW = m_inputManager.GetButton(InputAction.LT, LocalPlayerIndex, true, false); bool rotateCamCCW = m_inputManager.GetButton(InputAction.RT, LocalPlayerIndex, true, false); bool aPressed = m_inputManager.GetButton(InputAction.A, LocalPlayerIndex); bool pivotPreciseMode = aPressed | m_inputManager.GetButton(InputAction.RightStickButton, LocalPlayerIndex, true, false); bool cursorPreciseMode = aPressed | m_inputManager.GetButton(InputAction.LeftStickButton, LocalPlayerIndex, true, false); if (m_inputManager.IsAnyButtonDown(LocalPlayerIndex, false, false)) { m_lockMouseToWorld = false; } if (m_inputManager.GetButtonUp(InputAction.LT, LocalPlayerIndex, true, false) || m_inputManager.GetButtonUp(InputAction.RT, LocalPlayerIndex, true, false)) { if (!rotateCamCW && !rotateCamCCW) { m_cursorIcon.sprite = m_spritePointer; } } if (m_inputManager.GetButtonUp(InputAction.MMB, LocalPlayerIndex)) { m_cursorIcon.sprite = m_spritePointer; } else if (m_inputManager.GetButton(InputAction.MMB, LocalPlayerIndex)) { m_lockMouseToWorld = false; MoveVirtualMouseToCenterOfScreen(); m_camAngle += Time.deltaTime * cursorX * m_settings.PlayerCamCtrl[LocalPlayerIndex].RotateSensitivity; SetCameraPosition(); if (cursorX != 0) { m_cursorIcon.sprite = cursorX > 0 ? m_spriteRotateCW : m_spriteRotateCCW; } else { m_cursorIcon.sprite = m_spritePointer; } cursorX = 0; cursorY = 0; } else { if (rotateCamCW && !rotateCamCCW) { m_cursorIcon.sprite = m_spriteRotateCW; MoveVirtualMouseToCenterOfScreen(); m_camAngle += Time.deltaTime * settings.RotateSensitivity; SetCameraPosition(); } else if (rotateCamCCW && !rotateCamCW) { m_cursorIcon.sprite = m_spriteRotateCCW; MoveVirtualMouseToCenterOfScreen(); m_camAngle -= Time.deltaTime * settings.RotateSensitivity; SetCameraPosition(); } if (cursorX != 0 && cursorY != 0) { float cursorSens = settings.CursorSensitivity; if (cursorPreciseMode || pivotPreciseMode) { cursorSens /= 5.0f; } else { cursorSens *= VirtualMouseSensitivityScale; } if (m_isVirtualMouseEnabled) { VirtualMousePosition += new Vector2(cursorX, cursorY) * cursorSens; } m_lockMouseToWorld = false; } } Vector3 deltaOffset = new Vector3(deltaX, deltaY, 0); Vector3 offset = Vector2.zero; if (deltaOffset != Vector3.zero) { offset = deltaOffset; mouseOffset = Vector2.zero; } else { if (!m_lockMouseToWorld) { offset = mouseOffset; } } MovePivot(settings, pivotPreciseMode, cursorPreciseMode, offset); if (m_prevMouseOffset != mouseOffset) { CursorIconFromMouseOffset(mouseOffset); m_prevMouseOffset = mouseOffset; } } AnimatePivotPoint(settings.MoveSensitivity / 2, settings.MoveSensitivity / 8); if (m_lockMouseToWorld) { Vector2 targetMousePos = m_camera.WorldToScreenPoint(m_lockMousePosWorld); if (m_animateMousePosition) { SetVirtualMousePosition(Vector2.Lerp(VirtualMousePosition, targetMousePos, Time.deltaTime * 20)); CursorIconFromMouseOffset(mouseOffset); } else { SetVirtualMousePosition(targetMousePos); CursorIconFromMouseOffset(mouseOffset); } } Debug.DrawLine(Pivot, Pivot + Vector3.up, Color.red); }
private void Update() { if (m_gameState.IsActionsMenuOpened(m_viewport.LocalPlayerIndex)) { return; } if (m_gameState.IsMenuOpened(m_viewport.LocalPlayerIndex)) { return; } if (m_gameState.IsPaused || m_gameState.IsPauseStateChanging) { return; } Transform camTransform = m_viewport.Camera.transform; if (camTransform.position != m_prevCamPos || camTransform.rotation != m_prevCamRot) { m_prevCamPos = camTransform.position; m_prevCamRot = camTransform.rotation; float angle = camTransform.eulerAngles.y; m_rtMapBounds.rotation = Quaternion.Euler(new Vector3(0, 0, angle)); ProjectCamera(m_rtMapBounds.rotation); } if (m_input.GetButtonDown(InputAction.Start, m_viewport.LocalPlayerIndex, false, false)) { m_gotFocus = !m_gotFocus; if (m_gotFocus) { m_eventSystem.SetSelectedGameObjectOnLateUpdate(m_selectableMinimap.gameObject); } else { m_cameraController.CenterVirtualMouse(); m_eventSystem.SetSelectedGameObjectOnLateUpdate(null); } } if (m_input.GetButtonDown(InputAction.LMB, m_viewport.LocalPlayerIndex, false, false)) { Vector2 pt; if (RectTransformUtility.ScreenPointToLocalPointInRectangle((RectTransform)m_rtMapBounds.parent, m_cameraController.VirtualMousePosition, null, out pt)) { float normalizedDistance = pt.magnitude / m_rootRadius; if (normalizedDistance <= 1) { m_mouseManipulation = true; m_virtualMousePostion = m_cameraController.VirtualMousePosition; Move(camTransform, true, 0, 0, 0, 0); } } } else if (m_input.GetButtonUp(InputAction.LMB, m_viewport.LocalPlayerIndex, false, false)) { m_mouseManipulation = false; } if (m_gotFocus || m_input.GetButton(InputAction.LB, m_viewport.LocalPlayerIndex, false, false) && IsCursorInMinimapBounds()) { if (m_input.GetButtonDown(InputAction.B, m_viewport.LocalPlayerIndex, false, false)) { m_gotFocus = false; m_cameraController.CenterVirtualMouse(); m_eventSystem.SetSelectedGameObjectOnLateUpdate(null); } else if (m_input.GetButtonDown(InputAction.LB, m_viewport.LocalPlayerIndex, false, false)) { m_virtualMousePostion = m_cameraController.VirtualMousePosition; Move(camTransform, true, 0, 0, 0, 0); } else { bool aPressed = m_input.GetButton(InputAction.A, m_viewport.LocalPlayerIndex, false, false); bool pivotPreciseMode = aPressed | m_input.GetButton(InputAction.RightStickButton, m_viewport.LocalPlayerIndex, false, false); float pivotMultiplier = 1; if (!pivotPreciseMode) { pivotMultiplier = 5; } float deltaY = m_input.GetAxisRaw(InputAction.MoveForward, m_viewport.LocalPlayerIndex, false, false) * Time.deltaTime * m_camCtrlSettings.MoveSensitivity * pivotMultiplier; float deltaX = m_input.GetAxisRaw(InputAction.MoveSide, m_viewport.LocalPlayerIndex, false, false) * Time.deltaTime * m_camCtrlSettings.MoveSensitivity * pivotMultiplier; bool cursorPreciseMode = aPressed | m_input.GetButton(InputAction.LeftStickButton, m_viewport.LocalPlayerIndex, false, false); float cursorMultiplier = 4; if (!cursorPreciseMode) { cursorMultiplier = 12; } float cursorY = m_input.GetAxisRaw(InputAction.CursorY, m_viewport.LocalPlayerIndex, false, false) * Time.deltaTime * m_camCtrlSettings.CursorSensitivity * cursorMultiplier; float cursorX = m_input.GetAxisRaw(InputAction.CursorX, m_viewport.LocalPlayerIndex, false, false) * Time.deltaTime * m_camCtrlSettings.CursorSensitivity * cursorMultiplier; Move(camTransform, false, deltaY, deltaX, cursorY, cursorX); } } if (m_mouseManipulation) { if (m_input.GetButton(InputAction.LMB, m_viewport.LocalPlayerIndex, false, false)) { float cursorMultiplier = 12; float cursorY = m_input.GetAxisRaw(InputAction.CursorY, m_viewport.LocalPlayerIndex, false, false) * Time.deltaTime * m_camCtrlSettings.CursorSensitivity * cursorMultiplier; float cursorX = m_input.GetAxisRaw(InputAction.CursorX, m_viewport.LocalPlayerIndex, false, false) * Time.deltaTime * m_camCtrlSettings.CursorSensitivity * cursorMultiplier; Move(camTransform, false, cursorY, cursorX, 0, 0); } } }