void UpdateSimple() { if (input == null || !input.focused || !input.enabled) { return; } bool leftAltPressed = input.GetButton(InputButtonNames.LeftAlt); bool leftShiftPressed = input.GetButton(InputButtonNames.LeftShift); bool leftControlPressed = input.GetButton(InputButtonNames.LeftControl); bool fire1Pressed = input.GetButton(InputButtonNames.Button1); if (fire1Pressed) { if (ModelPreviewCancel()) { fire1Pressed = false; lastHitButtonPressed = Time.time + 0.5f; } } bool fire2Clicked = input.GetButtonDown(InputButtonNames.Button2); if (!leftShiftPressed && !leftAltPressed && !leftControlPressed) { if (Time.time - lastHitButtonPressed > player.hitDelay) { if (fire1Pressed) { DoHit(player.hitDamage); } } if (fire2Clicked) { DoBuild(curPos, transform.forward, crosshairHitInfo.voxelCenter); } } if (input.GetButtonDown(InputButtonNames.Build)) { env.SetBuildMode(!env.buildMode); if (env.buildMode) { #if UNITY_EDITOR env.ShowMessage("<color=green>Entered <color=yellow>Build Mode</color>. Press <color=white>B</color> to cancel, <color=white>V</color> to enter the Constructor.</color>"); #else env.ShowMessage("<color=green>Entered <color=yellow>Build Mode</color>. Press <color=white>B</color> to cancel.</color>"); #endif } else { env.ShowMessage("<color=green>Back to <color=yellow>Normal Mode</color>.</color>"); } } }
void LateUpdate() { VoxelPlayInputController input = env.input; if (input == null || inventoryPlaceholder == null) { return; } if (input.anyKey) { if (env.enableConsole && Input.GetKeyDown(KeyCode.F1)) { ToggleConsoleVisibility(!console.activeSelf); } else if (env.enableDebugWindow && Input.GetKeyDown(KeyCode.F2)) { ToggleDebugWindow(!debug.activeSelf); } else if (Input.GetKeyDown(KeyCode.Escape)) { ToggleConsoleVisibility(false); ToggleInventoryVisibility(false); } else if (env.enableInventory && input.GetButtonDown(InputButtonNames.Inventory)) { leftShiftPressed = false; if (!inventoryPlaceholder.activeSelf) { ToggleInventoryVisibility(true); } else if (Input.GetKey(KeyCode.LeftShift)) { InventoryPreviousPage(); } else { InventoryNextPage(); } } else if (Input.GetKeyDown(KeyCode.UpArrow) && IsVisible) { inputField.text = lastCommand; inputField.MoveTextEnd(false); } else if (Input.GetKeyDown(KeyCode.F8)) { ToggleFPS(); } else if (inventoryPlaceholder.activeSelf) { if (Input.GetKeyDown(KeyCode.Alpha1)) { SelectItemFromVisibleInventorySlot(0); } else if (Input.GetKeyDown(KeyCode.Alpha2)) { SelectItemFromVisibleInventorySlot(1); } else if (Input.GetKeyDown(KeyCode.Alpha3)) { SelectItemFromVisibleInventorySlot(2); } else if (Input.GetKeyDown(KeyCode.Alpha4)) { SelectItemFromVisibleInventorySlot(3); } else if (Input.GetKeyDown(KeyCode.Alpha5)) { SelectItemFromVisibleInventorySlot(4); } else if (Input.GetKeyDown(KeyCode.Alpha6)) { SelectItemFromVisibleInventorySlot(5); } else if (Input.GetKeyDown(KeyCode.Alpha7)) { SelectItemFromVisibleInventorySlot(6); } else if (Input.GetKeyDown(KeyCode.Alpha8)) { SelectItemFromVisibleInventorySlot(7); } else if (Input.GetKeyDown(KeyCode.Alpha9)) { SelectItemFromVisibleInventorySlot(8); } else if (Input.GetKeyDown(KeyCode.Alpha0)) { SelectItemFromVisibleInventorySlot(9); } } } if (inventoryPlaceholder.activeSelf) { CheckInventoryControlKeyHints(true); } if (debug.activeSelf) { UpdateDebugInfo(); } if (fpsText.enabled) { UpdateFPSCounter(); } }
void UpdateWithCharacterController() { CheckFootfalls(); RotateView(); if (orbitMode) { isFlying = true; } // the jump state needs to read here to make sure it is not missed if (!m_Jump && !isFlying) { m_Jump = input.GetButtonDown(InputButtonNames.Jump); } if (!m_PreviouslyGrounded && m_CharacterController.isGrounded) { StartCoroutine(m_JumpBob.DoBobCycle()); PlayLandingSound(); m_MoveDir.y = 0f; m_Jumping = false; } if (!m_CharacterController.isGrounded && !m_Jumping && m_PreviouslyGrounded) { m_MoveDir.y = 0f; } m_PreviouslyGrounded = m_CharacterController.isGrounded; // Process click events if (input.focused && input.enabled) { bool leftAltPressed = input.GetButton(InputButtonNames.LeftAlt); bool leftShiftPressed = input.GetButton(InputButtonNames.LeftShift); bool leftControlPressed = input.GetButton(InputButtonNames.LeftControl); bool fire1Pressed = input.GetButton(InputButtonNames.Button1); if (fire1Pressed) { if (ModelPreviewCancel()) { fire1Pressed = false; lastHitButtonPressed = Time.time + 0.5f; } } bool fire2Clicked = input.GetButtonDown(InputButtonNames.Button2); if (!leftShiftPressed && !leftAltPressed && !leftControlPressed) { if (Time.time - lastHitButtonPressed > player.hitDelay) { if (fire1Pressed) { DoHit(player.hitDamage); } } if (fire2Clicked) { DoHit(0); } } if (crosshairOnBlock && input.GetButtonDown(InputButtonNames.MiddleButton)) { player.SetSelectedItem(crosshairHitInfo.voxel.type); } if (input.GetButtonDown(InputButtonNames.Build)) { env.SetBuildMode(!env.buildMode); if (env.buildMode) { #if UNITY_EDITOR env.ShowMessage("<color=green>Entered <color=yellow>Build Mode</color>. Press <color=white>B</color> to cancel, <color=white>V</color> to enter the Constructor.</color>"); #else env.ShowMessage("<color=green>Entered <color=yellow>Build Mode</color>. Press <color=white>B</color> to cancel.</color>"); #endif } else { env.ShowMessage("<color=green>Back to <color=yellow>Normal Mode</color>.</color>"); } } if (fire2Clicked && !leftAltPressed && !leftShiftPressed) { DoBuild(m_Camera.transform.position, m_Camera.transform.forward, voxelHighlightBuilder != null ? voxelHighlightBuilder.transform.position : Misc.vector3zero); } // Toggles Flight mode if (input.GetButtonDown(InputButtonNames.Fly)) { isFlying = !isFlying; if (isFlying) { m_Jumping = false; env.ShowMessage("<color=green>Flying <color=yellow>ON</color></color>"); } else { env.ShowMessage("<color=green>Flying <color=yellow>OFF</color></color>"); } } if (isGrounded && !isCrouched && input.GetButtonDown(InputButtonNames.LeftControl)) { isCrouched = true; } else if (isGrounded && isCrouched && input.GetButtonUp(InputButtonNames.LeftControl)) { isCrouched = false; } else if (isGrounded && input.GetButtonDown(InputButtonNames.Crouch)) { isCrouched = !isCrouched; if (isCrouched) { env.ShowMessage("<color=green>Crouching <color=yellow>ON</color></color>"); } else { env.ShowMessage("<color=green>Crouching <color=yellow>OFF</color></color>"); } } else if (input.GetButtonDown(InputButtonNames.Light)) { ToggleCharacterLight(); } else if (input.GetButtonDown(InputButtonNames.ThrowItem)) { ThrowCurrentItem(m_Camera.transform.position, m_Camera.transform.forward); } } // Check water CheckWaterStatus(); // Check crouch status if (!isInWater) { if (isCrouched && crouch.localPosition.y == 0) { crouch.transform.localPosition = new Vector3(0, -1f, 0); m_CharacterController.stepOffset = 0.4f; } else if (!isCrouched && crouch.localPosition.y != 0) { crouch.transform.localPosition = Misc.vector3zero; m_CharacterController.stepOffset = 1f; } } #if UNITY_EDITOR UpdateConstructor(); #endif }