| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- public class ArrowTraceDebug : MonoBehaviour
- {
- [SerializeField] Transform cameraTF;
- [SerializeField] Transform tracePoints;
- [SerializeField] Button btnTap;
- [SerializeField] ButtonListener btnL;
- [SerializeField] ButtonListener btnR;
- [SerializeField] ButtonListener btnFar;
- [SerializeField] ButtonListener btnNear;
- bool isBtnLDown = false;
- bool isBtnRDown = false;
- bool isValid = false;
- int crossHairIsOpen = -1;
- public static ArrowTraceDebug ins;
- void Awake() {
- ins = this;
- }
- void OnDestroy() {
- if (ins == this) ins = null;
- SaveCameraData();
- }
- void Start()
- {
- btnTap.onClick.AddListener(() => {
- isValid = !isValid;
- if (isValid) {
- GameMgr.ins.gameMode.PauseTimeCounting(this);
- } else {
- GameMgr.ins.gameMode.ResumeTimeCounting(this);
- }
- CheckValidAndUpdateUI();
- //自动开关准心
- if (isValid && CrossHair.ins) {
- crossHairIsOpen = CrossHair.ins.GetOpen() ? 1 : 0;
- CrossHair.ins.SetOpen(false);
- } else if (!isValid && CrossHair.ins && crossHairIsOpen > -1) {
- CrossHair.ins.SetOpen(crossHairIsOpen == 1 ? true : false);
- }
- });
- btnL.onPointerDown += (e) => {
- isBtnLDown = true;
- };
- btnL.onPointerUp += (e) => {
- isBtnLDown = false;
- };
- btnR.onPointerDown += (e) => {
- isBtnRDown = true;
- };
- btnR.onPointerUp += (e) => {
- isBtnRDown = false;
- };
- btnFar.onPointerDown += (e) => {
- Camera camera = cameraTF.GetComponent<Camera>();
- camera.orthographicSize += 3;
- };
- btnNear.onPointerDown += (e) => {
- Camera camera = cameraTF.GetComponent<Camera>();
- if (camera.orthographicSize >= 3) {
- camera.orthographicSize -= 3;
- }
- };
- CheckValidAndUpdateUI();
- ResumeCameraData();
- }
- void Update() {
- if (isValid) {
- if (isBtnLDown) {
- MoveCamera(Time.deltaTime * -20f);
- }
- if (isBtnRDown) {
- MoveCamera(Time.deltaTime * 20f);
- }
- }
- }
- void CheckValidAndUpdateUI() {
- btnTap.GetComponentInChildren<Text>().text = isValid ? "退出查看" : "查看轨迹";
- btnL.gameObject.SetActive(isValid);
- btnR.gameObject.SetActive(isValid);
- btnFar.gameObject.SetActive(isValid);
- btnNear.gameObject.SetActive(isValid);
- cameraTF.gameObject.SetActive(isValid);
- tracePoints.gameObject.SetActive(isValid);
- transform.Find("Canvas/Mask").gameObject.SetActive(isValid);
- }
- void MoveCamera(float dz) {
- Vector3 pos = cameraTF.transform.localPosition;
- pos.z += dz;
- cameraTF.transform.localPosition = pos;
- }
- Arrow arrow;
- public void OnArrowUpdate(Arrow arrow) {
- if (arrow != this.arrow) {
- this.arrow = arrow;
- ClearTracePoints();
- }
- GameObject.Instantiate(
- this.tracePoints.GetChild(0).gameObject,
- arrow.transform.position,
- Quaternion.identity,
- this.tracePoints
- ).SetActive(true);
- }
- void ClearTracePoints() {
- for (int i = 1; i < this.tracePoints.childCount; i++) {
- Transform t = this.tracePoints.GetChild(i);
- if (t && t.gameObject) Destroy(t.gameObject);
- }
- }
- static bool hasSaveCameraData = false;
- static Vector3 cameraSavePosition;
- static float cameraSaveOrthographicSize;
- void SaveCameraData() {
- cameraSavePosition = cameraTF.localPosition;
- cameraSaveOrthographicSize = cameraTF.GetComponent<Camera>().orthographicSize;
- hasSaveCameraData = true;
- }
- void ResumeCameraData() {
- if (hasSaveCameraData) {
- hasSaveCameraData = false;
- cameraTF.localPosition = cameraSavePosition;
- cameraTF.GetComponent<Camera>().orthographicSize = cameraSaveOrthographicSize;
- }
- }
- }
|