| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using DG.Tweening;
- public class ArrowCamera : MonoBehaviour
- {
- public Arrow arrow;
- ArrowCameraTemplate arrowCameraTemplate;
- void Awake()
- {
- BowCamera.ins.GetComponent<Camera>().enabled = false;
- }
- void Start()
- {
- if (arrow.simulatedParabola) {
- arrowCameraTemplate = new ArrowCameraTemplate2(this);
- } else {
- arrowCameraTemplate = new ArrowCameraTemplate1(this);
- }
- }
- void OnDestroy()
- {
- BowCamera.ins.GetComponent<Camera>().enabled = true;
- }
- void FixedUpdate()
- {
- arrowCameraTemplate.Update();
- }
- }
- class ArrowCameraTemplate2 : ArrowCameraTemplate
- {
- public ArrowCameraTemplate2(ArrowCamera arrowCamera) : base(arrowCamera) {
- this.arrowCamera.transform.parent = null;
- arrowCamera.transform.localPosition = new Vector3(8.33f, 2.45f, 6.4f);
- arrowCamera.transform.localEulerAngles = new Vector3(0, -56, 0);
- }
- bool isHit = false;
- public override void Update() {
- if (!isHit) {
- isHit = arrowCamera.arrow.isHit;
- if (isHit) {
- this.arrowCamera.transform.SetParent(this.arrowCamera.arrow.transform);
- arrowCamera.transform.localPosition = new Vector3(-0.6f, 0.1f, -0.8f);
- arrowCamera.transform.LookAt(this.arrowCamera.arrow.transform.Find("Head"));
- Sequence seq = DOTween.Sequence();
- seq.PrependInterval(1f);
- seq.AppendCallback(delegate() {
- this.arrowCamera.arrow.nextShoot();
- this.arrowCamera.arrow.enabled = false;
- GameObject.Destroy(this.arrowCamera.gameObject);
- });
- return;
- }
- }
- if (!arrowCamera.arrow) {
- GameObject.Destroy(this.arrowCamera.gameObject);
- }
- }
- }
- class ArrowCameraTemplate1 : ArrowCameraTemplate
- {
- public ArrowCameraTemplate1(ArrowCamera arrowCamera) : base(arrowCamera) {
- this.arrowCamera.arrow.activeEffectCyclone(true);
- }
-
- /**相机移动 */
- private bool cameraMoveFinish = false;
- //相机的位置xyz变化 【每秒变化量,最小值,最大值】
- private float[] cpcs = {
- //运动中
- 6, 0, 0.4f,
- 6, 0, 0.2f,
- -18f, -1 - Mathf.Clamp(Arrow.speed / 20 * 6, 0, 6), 0,
- //击中后
- -3.5f, -0.6f, 0.4f,
- -3.5f, 0.1f, 0.2f,
- 30, -1 - Mathf.Clamp(Arrow.speed / 20 * 6, 0, 6), -0.8f
- };
- public override void Update() {
- if (cameraMoveFinish) {
- return;
- }
- Transform cameraT = this.arrowCamera.transform;
- Vector3 cameraPosition = cameraT.localPosition;
- if (this.arrowCamera.arrow.isHit) {
- cameraPosition.x = Mathf.Clamp(cameraPosition.x + this.cpcs[9] * Time.deltaTime, this.cpcs[10], this.cpcs[11]);
- cameraPosition.y = Mathf.Clamp(cameraPosition.y + this.cpcs[12] * Time.deltaTime, this.cpcs[13], this.cpcs[14]);
- cameraPosition.z = Mathf.Clamp(cameraPosition.z + this.cpcs[15] * Time.deltaTime, this.cpcs[16], this.cpcs[17]);
- float d = Vector3.Distance(cameraPosition, new Vector3(
- this.cpcs[9] < 0 ? this.cpcs[10]: this.cpcs[11],
- this.cpcs[12] < 0 ? this.cpcs[13]: this.cpcs[14],
- this.cpcs[15] < 0 ? this.cpcs[16]: this.cpcs[17]
- ));
- if (d < 0.001f) {
- cameraMoveFinish = true;
- Sequence seq = DOTween.Sequence();
- seq.AppendInterval(1.0f);
- seq.AppendCallback(delegate() {
- this.arrowCamera.arrow.nextShoot();
- this.arrowCamera.arrow.enabled = false;
- GameObject.Destroy(this.arrowCamera.gameObject);
- });
- }
- } else {
- cameraPosition.x = Mathf.Clamp(cameraPosition.x + this.cpcs[0] * Time.deltaTime, this.cpcs[1], this.cpcs[2]);
- cameraPosition.y = Mathf.Clamp(cameraPosition.y + this.cpcs[3] * Time.deltaTime, this.cpcs[4], this.cpcs[5]);
- cameraPosition.z = Mathf.Clamp(cameraPosition.z + this.cpcs[6] * Time.deltaTime, this.cpcs[7], this.cpcs[8]);
- }
- cameraT.localPosition = cameraPosition;
- cameraT.LookAt(this.arrowCamera.arrow.transform.Find("Head"));
- }
- }
- class ArrowCameraTemplate {
- public ArrowCamera arrowCamera;
- public ArrowCameraTemplate(ArrowCamera arrowCamera)
- {
- this.arrowCamera = arrowCamera;
- }
- public virtual void Update() {}
- }
- // public class ArrowCamera : MonoBehaviour
- // {
- // public Arrow arrow;
- // void FixedUpdate()
- // {
- // updateMoveCamera();
- // }
- // /**相机移动 */
- // private Vector3 cameraPosition = new Vector3();
- // private bool cameraMoveFinish = false;
- // //相机的位置xyz变化 【每秒变化量,最小值,最大值】
- // private float[] cpcs = {
- // //运动中
- // 0, 0, 0,
- // 1.5f, 0, 0.25f,
- // -7, -1.5f, 0,
- // //击中后
- // -3.5f, -1.2f, 0,
- // -3.5f, 0, 0.5f,
- // 7, -1.5f, -1.5f
- // };
- // private void updateMoveCamera() {
- // if (cameraMoveFinish) {
- // return;
- // }
- // Transform cameraT = this.transform;
- // cameraPosition.x = cameraT.localPosition.x;
- // cameraPosition.y = cameraT.localPosition.y;
- // cameraPosition.z = cameraT.localPosition.z;
- // if (arrow.isHit) {
- // cameraPosition.x = Mathf.Clamp(cameraPosition.x + this.cpcs[9] * Time.deltaTime, this.cpcs[10], this.cpcs[11]);
- // cameraPosition.y = Mathf.Clamp(cameraPosition.y + this.cpcs[12] * Time.deltaTime, this.cpcs[13], this.cpcs[14]);
- // cameraPosition.z = Mathf.Clamp(cameraPosition.z + this.cpcs[15] * Time.deltaTime, this.cpcs[16], this.cpcs[17]);
- // float d = Vector3.Distance(cameraPosition, new Vector3(
- // this.cpcs[9] < 0 ? this.cpcs[10]: this.cpcs[11],
- // this.cpcs[12] < 0 ? this.cpcs[13]: this.cpcs[14],
- // this.cpcs[15] < 0 ? this.cpcs[16]: this.cpcs[17]
- // ));
- // if (d < 0.001f) {
- // cameraMoveFinish = true;
- // Sequence seq = DOTween.Sequence();
- // seq.AppendInterval(1.0f);
- // seq.AppendCallback(delegate() {
- // arrow.nextShoot();
- // Destroy(cameraT.gameObject);
- // this.enabled = false;
- // });
- // }
- // } else {
- // cameraPosition.x = Mathf.Clamp(cameraPosition.y + this.cpcs[0] * Time.deltaTime, this.cpcs[1], this.cpcs[2]);
- // cameraPosition.y = Mathf.Clamp(cameraPosition.y + this.cpcs[3] * Time.deltaTime, this.cpcs[4], this.cpcs[5]);
- // cameraPosition.z = Mathf.Clamp(cameraPosition.z + this.cpcs[6] * Time.deltaTime, this.cpcs[7], this.cpcs[8]);
- // }
- // cameraT.localPosition = cameraPosition;
- // cameraT.LookAt(arrow.transform.Find("Head"));
- // }
- // }
|