102 lines
2.5 KiB
C#
102 lines
2.5 KiB
C#
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
|
|
namespace LE_LevelEditor.LEInput
|
|
{
|
|
public class LE_InputDeviceMouse : LE_InputDeviceBase
|
|
{
|
|
private const float MOUSE_WHEEL_SENSITIVITY = 20f;
|
|
|
|
private const float MOVE_SPEED_SHIFT_FACTOR = 4f;
|
|
|
|
private const float MOVE_SPEED_CTRL_FACTOR = 0.2f;
|
|
|
|
private Vector3 m_mouseLookStart = Vector3.zero;
|
|
|
|
private Vector3 m_lastMousePosition = Vector3.zero;
|
|
|
|
private float m_lastTouchTime = -100f;
|
|
|
|
public LE_InputDeviceMouse(LE_IInputHandler p_inputHandler)
|
|
: base(p_inputHandler)
|
|
{
|
|
m_lastMousePosition = Input.mousePosition;
|
|
}
|
|
|
|
public override void Update()
|
|
{
|
|
if (!FisheryEditor.Instance.allowKeyboardInput)
|
|
{
|
|
return;
|
|
}
|
|
bool flag = Input.GetKey(KeyCode.LeftAlt) || Input.GetKey(KeyCode.RightAlt) || Input.GetKey(KeyCode.AltGr);
|
|
if (Input.touchCount != 0)
|
|
{
|
|
m_lastTouchTime = Time.realtimeSinceStartup;
|
|
m_lastMousePosition = Input.mousePosition;
|
|
return;
|
|
}
|
|
if (Time.realtimeSinceStartup - m_lastTouchTime <= 1f)
|
|
{
|
|
m_lastMousePosition = Input.mousePosition;
|
|
return;
|
|
}
|
|
if (m_lastMousePosition != Input.mousePosition)
|
|
{
|
|
m_inputHandler.SetCursorPosition(Input.mousePosition);
|
|
}
|
|
m_inputHandler.SetIsCursorAction(Input.GetMouseButton(0) && !flag);
|
|
if (Input.GetMouseButton(1) || (flag && Input.GetMouseButton(0)))
|
|
{
|
|
if (m_mouseLookStart.sqrMagnitude == 0f)
|
|
{
|
|
m_mouseLookStart = Input.mousePosition;
|
|
}
|
|
else if ((m_mouseLookStart - Input.mousePosition).magnitude > 0.0001f)
|
|
{
|
|
if (flag)
|
|
{
|
|
m_inputHandler.RotateCameraAroundPivot(Input.mousePosition, m_mouseLookStart);
|
|
}
|
|
else
|
|
{
|
|
m_inputHandler.RotateCamera(Input.mousePosition, m_mouseLookStart);
|
|
}
|
|
m_mouseLookStart = Input.mousePosition;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
m_mouseLookStart = Vector3.zero;
|
|
}
|
|
if (!(EventSystem.current != null) || EventSystem.current.IsPointerOverGameObject())
|
|
{
|
|
return;
|
|
}
|
|
float axis = Input.GetAxis("Mouse ScrollWheel");
|
|
if (axis == 0f)
|
|
{
|
|
return;
|
|
}
|
|
Vector3 p_toScreenCoords = Vector3.forward * axis * 20f;
|
|
if (p_toScreenCoords.sqrMagnitude != 0f)
|
|
{
|
|
if (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl))
|
|
{
|
|
p_toScreenCoords *= 0.2f;
|
|
}
|
|
else if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))
|
|
{
|
|
p_toScreenCoords *= 4f;
|
|
}
|
|
m_inputHandler.MoveCamera(Vector3.zero, p_toScreenCoords);
|
|
}
|
|
m_inputHandler.MoveCamera(Vector3.zero, p_toScreenCoords);
|
|
}
|
|
|
|
public override void Destroy()
|
|
{
|
|
}
|
|
}
|
|
}
|