45 lines
1.6 KiB
C#
45 lines
1.6 KiB
C#
using Oculus.Interaction;
|
|
using Unity.Cinemachine;
|
|
using UnityEngine;
|
|
using UnityEngine.InputSystem;
|
|
|
|
// Die Zoom-Funktion per Scrollrad musste erst händisch der Orbit-Kamera hinzugefügt werden. Dafür ist dieses Script zuständig.
|
|
|
|
public class CinemachinePositionComposerController : MonoBehaviour
|
|
{
|
|
[Header("Input Actions")]
|
|
public InputActionReference zoomAction; // Zuweisung einer Unity Input System Action.
|
|
|
|
public CinemachinePositionComposer positionComposer; // Zuweisung eines Position Composers der manipuliert werden soll.
|
|
|
|
private bool zoomBlocked = false; // Blocker für Zoom (wie schon in OrbitCameraMouseControl).
|
|
|
|
private void OnEnable()
|
|
{
|
|
if (zoomAction != null)
|
|
zoomAction.action.Enable();
|
|
}
|
|
|
|
|
|
|
|
void Update()
|
|
{
|
|
if (zoomAction != null && !zoomBlocked) // Wenn der Blocker nicht aktiv und die Action zugewiesen ist, wird in jedem Frame der Zustand des Scrollrads abgefragt
|
|
{ // und auf dieser Basis die CameraDistance im Position Composer verändert.
|
|
Vector2 zoomValue = zoomAction.action.ReadValue<Vector2>();
|
|
positionComposer.CameraDistance = positionComposer.CameraDistance - zoomValue.y * 0.25f;
|
|
}
|
|
|
|
}
|
|
|
|
public void SetBlocker(bool value) // mit dieser Funktion kann der Blocker durch andere Skripte gesetzt werden.
|
|
{
|
|
zoomBlocked = value;
|
|
}
|
|
|
|
public void SetLookahead(bool value) // Die Aktivierung und Deaktivierung des in Cinemachine möglichen Lookaheads wurde hier ebenfalls untergebracht.
|
|
{
|
|
positionComposer.Lookahead.Enabled = value;
|
|
}
|
|
}
|