-
-
Save bzgeb/0c11d0bd29ce86da7ad0162ca47c099d to your computer and use it in GitHub Desktop.
Fixed cursor state issue in StarterAssetsInputs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
#if ENABLE_INPUT_SYSTEM && STARTER_ASSETS_PACKAGES_CHECKED | |
using UnityEngine.InputSystem; | |
#endif | |
namespace StarterAssets | |
{ | |
public class StarterAssetsInputs : MonoBehaviour | |
{ | |
[Header("Character Input Values")] | |
public Vector2 move; | |
public Vector2 look; | |
public bool jump; | |
public bool sprint; | |
[Header("Movement Settings")] | |
public bool analogMovement; | |
#if !UNITY_IOS && !UNITY_ANDROID | |
[Header("Mouse Cursor Settings")] | |
[SerializeField] bool cursorLocked = true; | |
public bool CursorLocked | |
{ | |
get => cursorLocked; | |
set | |
{ | |
cursorLocked = value; | |
Cursor.lockState = cursorLocked ? CursorLockMode.Locked : CursorLockMode.None; | |
} | |
} | |
public bool cursorInputForLook = true; | |
#endif | |
#if ENABLE_INPUT_SYSTEM && STARTER_ASSETS_PACKAGES_CHECKED | |
public void OnMove(InputValue value) | |
{ | |
MoveInput(value.Get<Vector2>()); | |
} | |
public void OnLook(InputValue value) | |
{ | |
if (cursorInputForLook) | |
{ | |
LookInput(value.Get<Vector2>()); | |
} | |
} | |
public void OnJump(InputValue value) | |
{ | |
JumpInput(value.isPressed); | |
} | |
public void OnSprint(InputValue value) | |
{ | |
SprintInput(value.isPressed); | |
} | |
#else | |
// old input sys if we do decide to have it (most likely wont)... | |
#endif | |
public void MoveInput(Vector2 newMoveDirection) | |
{ | |
move = newMoveDirection; | |
} | |
public void LookInput(Vector2 newLookDirection) | |
{ | |
look = newLookDirection; | |
} | |
public void JumpInput(bool newJumpState) | |
{ | |
jump = newJumpState; | |
} | |
public void SprintInput(bool newSprintState) | |
{ | |
sprint = newSprintState; | |
} | |
#if !UNITY_IOS && !UNITY_ANDROID | |
private void OnApplicationFocus(bool hasFocus) | |
{ | |
Cursor.lockState = cursorLocked ? CursorLockMode.Locked : CursorLockMode.None; | |
} | |
#endif | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks!
It works!