using Obvious.Soap; using UnityEngine; namespace UFS3 { public class PlayerInput : MonoBehaviour { public BoolVariable IsInventoryEnabled; public Vector2Variable MovementDirection; public ScriptableEventNoParam OnJumpButtonPressed; public ScriptableEventNoParam OnJumpButtonReleased; public ScriptableEventNoParam OnInventoryButtonPressed; public ScriptableEventNoParam OnMainMenuButtonPressed; public ScriptableEventNoParam OnCameraChangeButtonPressed; public Vector2Variable MouseInput; public BoolVariable IsRunPressed; public BoolVariable IsFlashLightPress; public BoolVariable isPhonePressed; public ScriptableEventBool OnLeftMouseButtonPressed; public ScriptableEventBool OnRightMouseButtonPressed; public BoolVariable IsLeftMouseButtonPressed; public BoolVariable IsRightMouseButtonPressed; public ScriptableEventInt OnSlotItemPressed; public FloatVariable OnDragSettingButtonScroll; public BoolVariable IsDebugModeEnabled; public BoolVariable IsCursorControlEnabled; public BoolVariable isQButtonPressed; public BoolVariable isZoomButtonPressed; public BoolVariable isChangeDayTimeButtonPressed; public BoolVariable isDayTimeWindowEnabled; public BoolVariable isFeedbackFormEnabled; public BoolVariable isChatButtonPressed; public BoolVariable isChatCancelButtonPressed; public BoolVariable IsChatboxActive; public BoolVariable ReverseLook; private void OnEnable() { IsCursorControlEnabled.OnValueChanged += IsCursorControlEnabledOnOnValueChanged; IsDebugModeEnabled.OnValueChanged += IsDebugModeEnabledOnOnValueChanged; IsInventoryEnabled.OnValueChanged += IsInventoryEnabledOnOnValueChanged; isFeedbackFormEnabled.OnValueChanged += IsFeedbackFormEnabledOnOnValueChanged; } private void IsFeedbackFormEnabledOnOnValueChanged(bool obj) { ResetInput(); } private void OnDisable() { IsCursorControlEnabled.OnValueChanged -= IsCursorControlEnabledOnOnValueChanged; IsDebugModeEnabled.OnValueChanged -= IsDebugModeEnabledOnOnValueChanged; IsInventoryEnabled.OnValueChanged -= IsInventoryEnabledOnOnValueChanged; isFeedbackFormEnabled.OnValueChanged -= IsFeedbackFormEnabledOnOnValueChanged; } private void IsInventoryEnabledOnOnValueChanged(bool obj) { ResetInput(); } private void IsDebugModeEnabledOnOnValueChanged(bool obj) { ResetInput(); } private void IsCursorControlEnabledOnOnValueChanged(bool value) { if (!IsInventoryEnabled.Value) { if (value) { Cursor.lockState = CursorLockMode.Confined; Cursor.lockState = CursorLockMode.None; Cursor.visible = true; ResetInput(); } else { Cursor.lockState = CursorLockMode.Locked; Cursor.visible = false; } } } private void ResetInput() { IsLeftMouseButtonPressed.Value = false; IsRightMouseButtonPressed.Value = false; MouseInput.Value = Vector2.zero; MovementDirection.Value = Vector2.zero; IsRunPressed.Value = false; } private void Update() { HandlePlayerInput(); MenuInput(); } private void MenuInput() { if (!isDayTimeWindowEnabled.Value && !isFeedbackFormEnabled.Value && !IsChatboxActive.Value) { if (Input.GetKeyUp(KeyCode.I)) { OnInventoryButtonPressed.Raise(); } if (Input.GetKeyUp(KeyCode.Escape)) { OnMainMenuButtonPressed.Raise(); } } } private void HandlePlayerInput() { IsCursorControlEnabled.Value = Input.GetKey(KeyCode.LeftControl); isChatCancelButtonPressed.Value = Input.GetKeyUp(KeyCode.Escape); if (IsInventoryEnabled.Value || IsCursorControlEnabled.Value || IsDebugModeEnabled.Value || isDayTimeWindowEnabled.Value || isFeedbackFormEnabled.Value || IsChatboxActive.Value) { ResetInput(); return; } Vector2 vector = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical")); MovementDirection.Value = Vector2.ClampMagnitude(vector, 1f); IsRunPressed.Value = Input.GetKey(KeyCode.LeftShift); MouseInput.Value = new Vector2(Input.GetAxisRaw("Mouse X"), Input.GetAxisRaw("Mouse Y")); if (ReverseLook.Value) { MouseInput.Value = new Vector2(MouseInput.Value.x, 0f - MouseInput.Value.y); } isZoomButtonPressed.Value = Input.GetKey(KeyCode.Z); if (Input.GetButtonDown("Jump")) { OnJumpButtonPressed.Raise(); } else if (Input.GetButtonUp("Jump")) { OnJumpButtonReleased.Raise(); } OnDragSettingButtonScroll.Value = Input.mouseScrollDelta.y; if (Input.GetMouseButtonDown(0)) { OnLeftMouseButtonPressed.Raise(param: true); } if (Input.GetMouseButtonUp(0)) { OnLeftMouseButtonPressed.Raise(param: false); } isChangeDayTimeButtonPressed.Value = Input.GetKeyDown(KeyCode.T); if (Input.GetMouseButtonDown(0)) { IsLeftMouseButtonPressed.Value = true; } if (Input.GetMouseButtonUp(0)) { IsLeftMouseButtonPressed.Value = false; } isPhonePressed.Value = Input.GetKeyDown(KeyCode.M); IsFlashLightPress.Value = Input.GetKeyDown(KeyCode.F); if (Input.GetMouseButtonDown(1)) { OnRightMouseButtonPressed.Raise(param: true); IsRightMouseButtonPressed.Value = true; } isQButtonPressed.Value = Input.GetKey(KeyCode.Q); if (Input.GetMouseButtonUp(1)) { OnRightMouseButtonPressed.Raise(param: false); IsRightMouseButtonPressed.Value = false; } if (Input.GetKeyDown(KeyCode.Alpha1)) { OnSlotItemPressed.Raise(1); } if (Input.GetKeyDown(KeyCode.Alpha2)) { OnSlotItemPressed.Raise(2); } isChatButtonPressed.Value = Input.GetKeyDown(KeyCode.Tab); if (Input.GetKeyDown(KeyCode.C)) { OnCameraChangeButtonPressed.Raise(); } } } }