using System.Collections; using System.Collections.Generic; using UnityEngine; using Cinemachine; using DG.Tweening; public class CMCameraManager : MonoSingleton { /// /// 场景虚拟相机 /// private List _cmList; private CinemachineStateDrivenCamera _csdc; private Camera _mainCamera; // Start is called before the first frame update void Start() { this._cmList = new List(); //this._csdc = this.gameObject.transform.Find("CMStateDrivenCamera").GetComponent(); CinemachineVirtualCamera[] cvcArray = this.gameObject.GetComponentsInChildren(); foreach(var item in cvcArray) { _cmList.Add(item); } if (CameraManager.Instance.CameraManagerObj) { this._mainCamera = CameraManager.Instance.CameraManagerObj.transform.Find("Main Camera").GetComponent(); } 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(); // this._csdc.gameObject.SetActive(true); // //foreach (var item in this._cmList) // //{ // // GameObject lookatPoint = role.mHitPos.gameObject; // // item.LookAt = lookatPoint.transform; // // if (item.GetComponent()) // // { // // GameObject followPoint = role.mHitPos.gameObject; // // item.Follow = followPoint.transform; // // } // // else if (!item.GetComponent()) // // { // // 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(); //transposer.m_FollowOffset.y = 10; Animator anim = vc.GetComponent(); if (anim != null) { anim.Play("shake1"); } } private void CameraShakeLV2() { CinemachineVirtualCamera vc = this._csdc.LiveChild as CinemachineVirtualCamera; if (vc == null) { return; } CinemachineTransposer transposer = vc.GetCinemachineComponent(); Animator anim = vc.GetComponent(); if (anim != null) { anim.Play("shake2"); } } private void CameraShakeLV3() { CinemachineVirtualCamera vc = this._csdc.LiveChild as CinemachineVirtualCamera; if(vc == null) { return; } CinemachineTransposer transposer = vc.GetCinemachineComponent(); Animator anim = vc.GetComponent(); if (anim != null) { anim.Play("shake3"); } } }