Last active
September 4, 2018 13:29
-
-
Save tsubaki/076df355e068297e8015d234d9dc0d0b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
using Cinemachine; | |
//[DocumentationSorting(DocumentationSortingAttribute.Level.UserRef)] | |
[AddComponentMenu("")] // Don't display in add component menu | |
[RequireComponent(typeof(CinemachinePipeline))] | |
[SaveDuringPlay] | |
public class CinemachinePan : CinemachineComponentBase | |
{ | |
public override bool IsValid | |
{ | |
get { return enabled && LookAtTarget != null; } | |
} | |
public override CinemachineCore.Stage Stage | |
{ | |
get { return CinemachineCore.Stage.Aim; } | |
} | |
[Range(-180, 180)] | |
public float xAngleOffset, yAngleOffset; | |
public override void MutateCameraState(ref CameraState curState, float deltaTime) | |
{ | |
if (IsValid && curState.HasLookAt) | |
{ | |
Vector3 dir = (curState.ReferenceLookAt - curState.CorrectedPosition); | |
var offsetRotation = Quaternion.AngleAxis(-xAngleOffset, Vector3.up) * Quaternion.AngleAxis(-yAngleOffset, Vector3.right) ; | |
dir.y = curState.PositionCorrection.y; | |
if (dir.magnitude > Epsilon) | |
{ | |
if (Vector3.Cross(dir.normalized, curState.ReferenceUp).magnitude < Epsilon) | |
curState.RawOrientation = Quaternion.FromToRotation(Vector3.forward, dir) * offsetRotation; | |
else | |
curState.RawOrientation = Quaternion.LookRotation(dir, curState.ReferenceUp) * offsetRotation; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment