CMCameraManager.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using Cinemachine;
  5. using DG.Tweening;
  6. public class CMCameraManager : MonoSingleton<CMCameraManager>
  7. {
  8. /// <summary>
  9. /// 场景虚拟相机
  10. /// </summary>
  11. private List<CinemachineVirtualCamera> _cmList;
  12. private CinemachineStateDrivenCamera _csdc;
  13. private Camera _mainCamera;
  14. // Start is called before the first frame update
  15. void Start()
  16. {
  17. this._cmList = new List<CinemachineVirtualCamera>();
  18. //this._csdc = this.gameObject.transform.Find("CMStateDrivenCamera").GetComponent<CinemachineStateDrivenCamera>();
  19. CinemachineVirtualCamera[] cvcArray = this.gameObject.GetComponentsInChildren<CinemachineVirtualCamera>();
  20. foreach(var item in cvcArray)
  21. {
  22. _cmList.Add(item);
  23. }
  24. if (CameraManager.Instance.CameraManagerObj)
  25. {
  26. this._mainCamera = CameraManager.Instance.CameraManagerObj.transform.Find("Main Camera").GetComponent<Camera>();
  27. }
  28. else
  29. {
  30. this._mainCamera = Camera.main;
  31. }
  32. }
  33. // Update is called once per frame
  34. void Update()
  35. {
  36. }
  37. //public void ResetRole(Role role)
  38. //{
  39. // if(this._csdc)
  40. // {
  41. // this._csdc.gameObject.SetActive(false);
  42. // }
  43. // this._csdc = role.gameObject.transform.Find("CMStateDrivenCamera").GetComponent<CinemachineStateDrivenCamera>();
  44. // this._csdc.gameObject.SetActive(true);
  45. // //foreach (var item in this._cmList)
  46. // //{
  47. // // GameObject lookatPoint = role.mHitPos.gameObject;
  48. // // item.LookAt = lookatPoint.transform;
  49. // // if (item.GetComponent<CMFollow>())
  50. // // {
  51. // // GameObject followPoint = role.mHitPos.gameObject;
  52. // // item.Follow = followPoint.transform;
  53. // // }
  54. // // else if (!item.GetComponent<ChangeCamera>())
  55. // // {
  56. // // GameObject followPoint = role.mHitPos.gameObject;
  57. // // item.Follow = followPoint.transform;
  58. // // }
  59. // //}
  60. // //_csdc.LookAt = role.mHitPos.gameObject.transform;
  61. // //_csdc.Follow = role.mHitPos.gameObject.transform;
  62. // _csdc.m_AnimatedTarget = RPGPlayerController.Instance.Player.mBattleCameraAnim;
  63. //}
  64. public Camera GetMainCamera()
  65. {
  66. return this._mainCamera;
  67. }
  68. public void CameraShakeByLevel(int level)
  69. {
  70. switch(level)
  71. {
  72. case 1:
  73. this.CameraShakeLV1();
  74. break;
  75. case 2:
  76. this.CameraShakeLV2();
  77. break;
  78. case 3:
  79. this.CameraShakeLV3();
  80. break;
  81. }
  82. }
  83. private void CameraShakeLV1()
  84. {
  85. CinemachineVirtualCamera vc = this._csdc.LiveChild as CinemachineVirtualCamera;
  86. if (vc == null)
  87. {
  88. return;
  89. }
  90. CinemachineTransposer transposer = vc.GetCinemachineComponent<CinemachineTransposer>();
  91. //transposer.m_FollowOffset.y = 10;
  92. Animator anim = vc.GetComponent<Animator>();
  93. if (anim != null)
  94. {
  95. anim.Play("shake1");
  96. }
  97. }
  98. private void CameraShakeLV2()
  99. {
  100. CinemachineVirtualCamera vc = this._csdc.LiveChild as CinemachineVirtualCamera;
  101. if (vc == null)
  102. {
  103. return;
  104. }
  105. CinemachineTransposer transposer = vc.GetCinemachineComponent<CinemachineTransposer>();
  106. Animator anim = vc.GetComponent<Animator>();
  107. if (anim != null)
  108. {
  109. anim.Play("shake2");
  110. }
  111. }
  112. private void CameraShakeLV3()
  113. {
  114. CinemachineVirtualCamera vc = this._csdc.LiveChild as CinemachineVirtualCamera;
  115. if(vc == null)
  116. {
  117. return;
  118. }
  119. CinemachineTransposer transposer = vc.GetCinemachineComponent<CinemachineTransposer>();
  120. Animator anim = vc.GetComponent<Animator>();
  121. if (anim != null)
  122. {
  123. anim.Play("shake3");
  124. }
  125. }
  126. }