BossIntroCameraCfg.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. using UnityEngine;
  2. using System.Collections;
  3. using System;
  4. using UnityEngine.Rendering.PostProcessing;
  5. public class BossIntroCameraCfg : MonoBehaviour
  6. {
  7. [Serializable]
  8. public struct ShowBossCam
  9. {
  10. public Transform cam;
  11. public float duration;
  12. }
  13. public ShowBossCam[] Cams;
  14. public Vector3 bossInitPos;
  15. public float enableShakeTime;
  16. public Vector3 pos;
  17. public Vector3 rot;
  18. public float magnitude = 1; //振幅
  19. public float roughness = 1; //频率
  20. public float keepTime = 1;
  21. int curCamIdx = 0;
  22. private bool begined = false;
  23. private float beginTime = 0;
  24. private float showTime = 0;
  25. int timer = 0;
  26. GameObject bossIntroGo = null;
  27. Animator bossAnimator = null;
  28. PostProcessLayer ppLayer;
  29. private void Awake()
  30. {
  31. }
  32. private void Start()
  33. {
  34. bossIntroGo = GameObject.Find("bossintro");
  35. if(bossIntroGo != null)
  36. {
  37. bossAnimator = bossIntroGo.GetComponent<Animator>();
  38. if (bossAnimator != null)
  39. bossAnimator.enabled = true;
  40. }
  41. bossIntroGo.gameObject.SetActive(false);
  42. //ppLayer = this.GetComponentInChildren<PostProcessLayer>();
  43. //if (ppLayer != null)
  44. //{
  45. // ppLayer.enabled = false;
  46. //}
  47. }
  48. void Update()
  49. {
  50. if (!begined || Cams == null) return;
  51. float passedTime = Time.realtimeSinceStartup - beginTime;
  52. if (passedTime >= showTime)
  53. {
  54. if (curCamIdx < Cams.Length-1)
  55. {
  56. Cams[curCamIdx].cam.SetSafeActive(false);
  57. curCamIdx++;
  58. PlayCam();
  59. }
  60. }
  61. }
  62. public void Begin()
  63. {
  64. curCamIdx = 0;
  65. showTime = 0;
  66. beginTime = Time.realtimeSinceStartup;
  67. PlayCam();
  68. begined = true;
  69. bossIntroGo.gameObject.SetActive(true);
  70. if(enableShakeTime > 0)
  71. {
  72. timer = TimerManager.Instance.AddTimer((int)(enableShakeTime * 1000), 1, OnStartShake);
  73. }
  74. }
  75. public void Stop()
  76. {
  77. TimerManager.Instance.RemoveTimer(timer);
  78. begined = false;
  79. StopCam();
  80. bossIntroGo.gameObject.SetActive(false);
  81. //if (ppLayer != null)
  82. //{
  83. // ppLayer.enabled = false;
  84. //}
  85. }
  86. void OnStartShake(int seq)
  87. {
  88. AddCameraShake();
  89. if (Cams[curCamIdx].cam != null)
  90. {
  91. Cams[curCamIdx].cam.GetComponent<Animator>().enabled = false;
  92. }
  93. }
  94. void StopCam()
  95. {
  96. if (Cams != null)
  97. {
  98. for (int idx = 0; idx < Cams.Length; idx++)
  99. {
  100. Cams[idx].cam.gameObject.SetSafeActive(false);
  101. }
  102. }
  103. }
  104. void PlayCam()
  105. {
  106. ShowBossCam bossCam = Cams[curCamIdx];
  107. showTime += bossCam.duration;
  108. bossCam.cam.SetSafeActive(false);
  109. bossCam.cam.GetComponent<Animator>().enabled = true;
  110. bossCam.cam.SetSafeActive(true);
  111. }
  112. public void AddCameraShake()
  113. {
  114. CameraShakeInstance c = CameraShaker.Instance.ShakeOnce(magnitude, roughness, 0, keepTime);
  115. c.PositionInfluence = pos;
  116. c.RotationInfluence = rot;
  117. }
  118. }