44 lines
1.7 KiB
C#
44 lines
1.7 KiB
C#
using UnityEngine;
|
|
using UnityEngine.InputSystem;
|
|
using Unity.Cinemachine;
|
|
|
|
public class OrbitCameraMouseControl : MonoBehaviour
|
|
{
|
|
[Header("Input Actions")]
|
|
public InputActionReference aimAction; // erlaubt die Zuweisung einer Unity Input System Action. Der Name AimAction kommt von der Belegung auf der rechten Maustaste.
|
|
|
|
[Header("Cinemachine Components")]
|
|
public CinemachineInputAxisController inputAxisController; // hier wird der InputAxisController der Cinemachine Camera verlinkt, der manipuliert werden soll.
|
|
|
|
private bool aimingBlocked = false; // wird verwendet, um die Bewegung der Kamera zu verhindern, während die Maus über einem Menüelement hovert.
|
|
|
|
private void OnEnable()
|
|
{
|
|
if (aimAction != null)
|
|
aimAction.action.Enable();
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
if (aimAction != null)
|
|
aimAction.action.Disable();
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
bool isAiming = aimAction != null && aimAction.action.ReadValue<float>() > 0.5f && !aimingBlocked;
|
|
|
|
if (inputAxisController != null) // aimingBlocked wird durch hover States der Menü-Elemente gesetzt
|
|
{
|
|
inputAxisController.Controllers[0].Enabled = isAiming; // Die X und Y-Achse der der Orbit-Funktion werden freigeschaltet, solange die aimAction (hier RMT) gedrückt ist.
|
|
inputAxisController.Controllers[1].Enabled = isAiming;
|
|
inputAxisController.Controllers[2].Enabled = !aimingBlocked; // Die Scroll-Funktion ist freigeschaltet, solange die Maus nicht über einem Menüelement hovert.
|
|
}
|
|
}
|
|
|
|
public void SetBlocker(bool value) // mit dieser Funktion kann der Blocker durch andere Skripte gesetzt werden.
|
|
{
|
|
aimingBlocked = value;
|
|
}
|
|
}
|