93 lines
2.8 KiB
C#
93 lines
2.8 KiB
C#
using Cinemachine;
|
|
using EasyInject.Attributes;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.Playables;
|
|
[GameObjectBean]
|
|
public class CameraManage:MonoBehaviour
|
|
{
|
|
[Autowired]
|
|
private AutoRotationButton autoRotation;
|
|
[SerializeField]
|
|
private CinemachineVirtualCamera followVirtualCamera;
|
|
private float startTime = 0;
|
|
[SerializeField]
|
|
private bool _isPlaying = true;
|
|
private PlayableDirector _playableDirector;
|
|
public bool IsPlaying { get { return _isPlaying; } set {
|
|
_isPlaying = value;
|
|
} }
|
|
private void Start()
|
|
{
|
|
_playableDirector = GetComponent<PlayableDirector>();
|
|
}
|
|
private void Update()
|
|
{
|
|
//if (CinemachineCore.Instance.IsLive(followVirtualCamera))
|
|
//{
|
|
// Camera.main.cullingMask = LayerMask.GetMask("storage", LayerMask.LayerToName(followVirtualCamera.Follow.gameObject.layer));
|
|
//}
|
|
|
|
|
|
if (!_isPlaying)
|
|
{
|
|
return;
|
|
}
|
|
//如果时间线正在播放
|
|
//任意键按下
|
|
//if (Input.anyKeyDown)
|
|
//{
|
|
// playable.Pause();
|
|
// startTime = Time.time + 3;
|
|
//}
|
|
//if (Time.time - startTime > 0)
|
|
//{
|
|
// playable.Play();
|
|
//}
|
|
}
|
|
|
|
|
|
private CinemachineVirtualCameraBase[] cinemachineVirtuals;
|
|
|
|
/// <summary>
|
|
/// 获取最高的优先级相机
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public ICinemachineCamera GetMaxPriorityCamera()
|
|
{
|
|
if (cinemachineVirtuals == null)
|
|
{
|
|
cinemachineVirtuals = GameObject.FindObjectsByType<CinemachineVirtualCameraBase>(FindObjectsSortMode.InstanceID);
|
|
}
|
|
var list = new List<CinemachineVirtualCameraBase>(cinemachineVirtuals);
|
|
list.Sort((a,b) => b.Priority-a.Priority);
|
|
return list[0];
|
|
}
|
|
/// <summary>
|
|
/// 镜头切换
|
|
/// </summary>
|
|
private void ShotCut(Transform follow,Transform lookAt,Vector3 offset)
|
|
{
|
|
|
|
followVirtualCamera.Follow = follow;
|
|
followVirtualCamera.LookAt = lookAt;
|
|
//关闭旋转
|
|
autoRotation.ClickRotationBtn(false);
|
|
CinemachineTransposer transposer= followVirtualCamera.GetCinemachineComponent<CinemachineTransposer>();
|
|
transposer.m_FollowOffset.x = offset.x;
|
|
transposer.m_FollowOffset.y = offset.y;
|
|
transposer.m_FollowOffset.z = offset.z;
|
|
// Camera.main.cullingMask = LayerMask.GetMask("storage", LayerMask.LayerToName(follow.gameObject.layer));
|
|
|
|
ICinemachineCamera maxCamera = GetMaxPriorityCamera();
|
|
followVirtualCamera.Priority = maxCamera.Priority + 2;
|
|
maxCamera.Priority -= 1;
|
|
|
|
}
|
|
public void ShotCut(IFollowHelp follow)
|
|
{
|
|
ShotCut(follow.Follow,follow.FookAt,follow.Offset);
|
|
}
|
|
|
|
}
|