| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- using UnityEngine;
- using System.Collections;
- using System;
- using UnityEngine.Rendering.PostProcessing;
- public class BossIntroCameraCfg : MonoBehaviour
- {
- [Serializable]
- public struct ShowBossCam
- {
- public Transform cam;
- public float duration;
- }
- public ShowBossCam[] Cams;
- public Vector3 bossInitPos;
- public float enableShakeTime;
- public Vector3 pos;
- public Vector3 rot;
- public float magnitude = 1; //振幅
- public float roughness = 1; //频率
- public float keepTime = 1;
- int curCamIdx = 0;
- private bool begined = false;
- private float beginTime = 0;
- private float showTime = 0;
- int timer = 0;
- GameObject bossIntroGo = null;
- Animator bossAnimator = null;
- PostProcessLayer ppLayer;
-
- private void Awake()
- {
- }
- private void Start()
- {
- bossIntroGo = GameObject.Find("bossintro");
- if(bossIntroGo != null)
- {
- bossAnimator = bossIntroGo.GetComponent<Animator>();
- if (bossAnimator != null)
- bossAnimator.enabled = true;
- }
- bossIntroGo.gameObject.SetActive(false);
- //ppLayer = this.GetComponentInChildren<PostProcessLayer>();
- //if (ppLayer != null)
- //{
- // ppLayer.enabled = false;
- //}
- }
- void Update()
- {
- if (!begined || Cams == null) return;
- float passedTime = Time.realtimeSinceStartup - beginTime;
- if (passedTime >= showTime)
- {
- if (curCamIdx < Cams.Length-1)
- {
- Cams[curCamIdx].cam.SetSafeActive(false);
- curCamIdx++;
- PlayCam();
- }
- }
- }
- public void Begin()
- {
- curCamIdx = 0;
- showTime = 0;
- beginTime = Time.realtimeSinceStartup;
- PlayCam();
- begined = true;
- bossIntroGo.gameObject.SetActive(true);
- if(enableShakeTime > 0)
- {
- timer = TimerManager.Instance.AddTimer((int)(enableShakeTime * 1000), 1, OnStartShake);
- }
- }
- public void Stop()
- {
- TimerManager.Instance.RemoveTimer(timer);
- begined = false;
- StopCam();
- bossIntroGo.gameObject.SetActive(false);
- //if (ppLayer != null)
- //{
- // ppLayer.enabled = false;
- //}
- }
- void OnStartShake(int seq)
- {
- AddCameraShake();
- if (Cams[curCamIdx].cam != null)
- {
- Cams[curCamIdx].cam.GetComponent<Animator>().enabled = false;
- }
- }
- void StopCam()
- {
- if (Cams != null)
- {
- for (int idx = 0; idx < Cams.Length; idx++)
- {
- Cams[idx].cam.gameObject.SetSafeActive(false);
- }
- }
- }
- void PlayCam()
- {
- ShowBossCam bossCam = Cams[curCamIdx];
- showTime += bossCam.duration;
- bossCam.cam.SetSafeActive(false);
- bossCam.cam.GetComponent<Animator>().enabled = true;
- bossCam.cam.SetSafeActive(true);
- }
- public void AddCameraShake()
- {
- CameraShakeInstance c = CameraShaker.Instance.ShakeOnce(magnitude, roughness, 0, keepTime);
- c.PositionInfluence = pos;
- c.RotationInfluence = rot;
- }
- }
|