add o3n
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.TextCore.Text;
|
||||
|
||||
public class Rotate3DObject : MonoBehaviour
|
||||
{
|
||||
#region Input Actions
|
||||
[SerializeField]
|
||||
private InputActionAsset _actions;
|
||||
|
||||
public InputActionAsset actions
|
||||
{
|
||||
get => _actions;
|
||||
set => _actions = value;
|
||||
}
|
||||
|
||||
protected InputAction leftClickPressedInputAction { get; set; }
|
||||
|
||||
protected InputAction mouseLookInputAction { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Variables
|
||||
|
||||
private bool _rotateAllowed;
|
||||
|
||||
private Camera _camera;
|
||||
|
||||
[SerializeField] private float _speed;
|
||||
|
||||
[SerializeField] private bool _inverted;
|
||||
|
||||
#endregion
|
||||
|
||||
private void Start()
|
||||
{
|
||||
Cursor.lockState = CursorLockMode.Locked;
|
||||
InitializeInputSystem();
|
||||
_camera = Camera.main;
|
||||
}
|
||||
|
||||
private void InitializeInputSystem()
|
||||
{
|
||||
leftClickPressedInputAction = GameManager.Instance.Input.UIAction.RightClick;
|
||||
if (leftClickPressedInputAction != null)
|
||||
{
|
||||
leftClickPressedInputAction.started += OnLeftClickPressed;
|
||||
leftClickPressedInputAction.performed += OnLeftClickPressed;
|
||||
leftClickPressedInputAction.canceled += OnLeftClickPressed;
|
||||
}
|
||||
|
||||
mouseLookInputAction = GameManager.Instance.Input.UIAction.MouseLook;
|
||||
|
||||
actions.Enable();
|
||||
}
|
||||
|
||||
protected virtual void OnLeftClickPressed(InputAction.CallbackContext context)
|
||||
{
|
||||
if (context.started || context.performed)
|
||||
{
|
||||
_rotateAllowed = true;
|
||||
}
|
||||
else if (context.canceled)
|
||||
_rotateAllowed = false;
|
||||
|
||||
}
|
||||
|
||||
protected virtual Vector2 GetMouseLookInput()
|
||||
{
|
||||
if (mouseLookInputAction != null)
|
||||
return mouseLookInputAction.ReadValue<Vector2>();
|
||||
|
||||
return Vector2.zero;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (!_rotateAllowed)
|
||||
return;
|
||||
|
||||
float MouseDelta = GetMouseLookInput().x;
|
||||
|
||||
MouseDelta *= _speed * Time.deltaTime;
|
||||
transform.eulerAngles += new Vector3(0, MouseDelta, 0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d6822b2af48bf4348a8969ecedafc11a
|
||||
Reference in New Issue
Block a user