Advertisement
apieceoffruit

CinmemachineSmartCamera

May 26th, 2021
1,078
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.99 KB | None | 0 0
  1.   public class CinemachineSmartCamera : SmartCamera
  2.     {
  3.         public CinemachineVirtualCamera VirtualCamera;
  4.  
  5.         [ContextMenu("Activate")]
  6.         public override void Activate()
  7.         {
  8.             VirtualCamera.MoveToTopOfPrioritySubqueue();
  9.             base.Activate();
  10.         }
  11.  
  12.         public override void ClearWatchTarget()=>ClearVCamTarget();
  13.  
  14.         public override void Watch(Transform target)
  15.         {
  16.             LookAt(target);
  17.             VirtualCamera.LookAt = target;
  18.             TargetFound?.Invoke(target);
  19.         }
  20.  
  21.         public override Transform LookTarget => VirtualCamera.LookAt;
  22.         public string DisplayName = "";
  23.  
  24.         public override void LookAt(Transform target)
  25.         {
  26.             //VirtualCamera.PreviousStateIsValid = false;
  27.             if (target != null)
  28.             {
  29.                 var t = VirtualCamera.transform;
  30.                 var dir = (target.position - t.position).normalized;
  31.                 t.forward = dir;
  32.             }
  33.             VirtualCamera.LookAt = target;
  34.         }
  35.  
  36.         #region Plumbing
  37.  
  38.         public bool BeingLookedThrough => Brain != null && Brain.ActiveVirtualCamera != null &&
  39.                                           (CinemachineVirtualCamera)Brain.ActiveVirtualCamera == VirtualCamera;
  40.  
  41.         void ClearVCamTarget()
  42.         {
  43.             if(VirtualCamera.LookAt != null)
  44.                 TargetLost?.Invoke(VirtualCamera.LookAt);
  45.             VirtualCamera.LookAt = null;
  46.             VirtualCamera.PreviousStateIsValid = false;
  47.            
  48.         }
  49.  
  50.         public override bool IsLive => BeingLookedThrough;
  51.  
  52.         protected override Transform CameraRoot => VirtualCamera.transform;
  53.  
  54.         private CinemachineBrain Brain => CinemachineCore.Instance.FindPotentialTargetBrain(VirtualCamera);
  55.  
  56.         public override string ToString() => Name;
  57.  
  58.         public override string GetDisplayName()
  59.         {
  60.             return DisplayName;
  61.         }
  62.  
  63.         #endregion
  64.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement