123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using Cinemachine;
- using DG.Tweening;
- public class CMCameraManager : MonoSingleton<CMCameraManager>
- {
- /// <summary>
- /// 场景虚拟相机
- /// </summary>
- private List<CinemachineVirtualCamera> _cmList;
- private CinemachineStateDrivenCamera _csdc;
- private Camera _mainCamera;
- // Start is called before the first frame update
- void Start()
- {
- this._cmList = new List<CinemachineVirtualCamera>();
- //this._csdc = this.gameObject.transform.Find("CMStateDrivenCamera").GetComponent<CinemachineStateDrivenCamera>();
- CinemachineVirtualCamera[] cvcArray = this.gameObject.GetComponentsInChildren<CinemachineVirtualCamera>();
- foreach(var item in cvcArray)
- {
- _cmList.Add(item);
- }
- if (CameraManager.Instance.CameraManagerObj)
- {
- this._mainCamera = CameraManager.Instance.CameraManagerObj.transform.Find("Main Camera").GetComponent<Camera>();
- }
- else
- {
- this._mainCamera = Camera.main;
- }
- }
- // Update is called once per frame
- void Update()
- {
-
- }
- //public void ResetRole(Role role)
- //{
- // if(this._csdc)
- // {
- // this._csdc.gameObject.SetActive(false);
- // }
- // this._csdc = role.gameObject.transform.Find("CMStateDrivenCamera").GetComponent<CinemachineStateDrivenCamera>();
- // this._csdc.gameObject.SetActive(true);
- // //foreach (var item in this._cmList)
- // //{
- // // GameObject lookatPoint = role.mHitPos.gameObject;
- // // item.LookAt = lookatPoint.transform;
- // // if (item.GetComponent<CMFollow>())
- // // {
- // // GameObject followPoint = role.mHitPos.gameObject;
- // // item.Follow = followPoint.transform;
- // // }
- // // else if (!item.GetComponent<ChangeCamera>())
- // // {
- // // GameObject followPoint = role.mHitPos.gameObject;
- // // item.Follow = followPoint.transform;
- // // }
- // //}
- // //_csdc.LookAt = role.mHitPos.gameObject.transform;
- // //_csdc.Follow = role.mHitPos.gameObject.transform;
- // _csdc.m_AnimatedTarget = RPGPlayerController.Instance.Player.mBattleCameraAnim;
- //}
- public Camera GetMainCamera()
- {
- return this._mainCamera;
- }
- public void CameraShakeByLevel(int level)
- {
- switch(level)
- {
- case 1:
- this.CameraShakeLV1();
- break;
- case 2:
- this.CameraShakeLV2();
- break;
- case 3:
- this.CameraShakeLV3();
- break;
- }
- }
- private void CameraShakeLV1()
- {
- CinemachineVirtualCamera vc = this._csdc.LiveChild as CinemachineVirtualCamera;
- if (vc == null)
- {
- return;
- }
- CinemachineTransposer transposer = vc.GetCinemachineComponent<CinemachineTransposer>();
- //transposer.m_FollowOffset.y = 10;
- Animator anim = vc.GetComponent<Animator>();
- if (anim != null)
- {
- anim.Play("shake1");
- }
- }
- private void CameraShakeLV2()
- {
- CinemachineVirtualCamera vc = this._csdc.LiveChild as CinemachineVirtualCamera;
- if (vc == null)
- {
- return;
- }
- CinemachineTransposer transposer = vc.GetCinemachineComponent<CinemachineTransposer>();
- Animator anim = vc.GetComponent<Animator>();
- if (anim != null)
- {
- anim.Play("shake2");
- }
- }
- private void CameraShakeLV3()
- {
- CinemachineVirtualCamera vc = this._csdc.LiveChild as CinemachineVirtualCamera;
- if(vc == null)
- {
- return;
- }
- CinemachineTransposer transposer = vc.GetCinemachineComponent<CinemachineTransposer>();
- Animator anim = vc.GetComponent<Animator>();
- if (anim != null)
- {
- anim.Play("shake3");
- }
- }
- }
|