123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using XRTool.Util;
- public class ArrowList : UnitySingleton<ArrowList>
- {
- public GameObject arrow;
- public int num = 0;
- void Update()
- {
- //if (Input.GetKey(KeyCode.I))
- //{
- // Vector3[] v3List = GetCorners(1f);
- // for (int i = 0; i < v3List.Length; i++)
- // {
- // Debug.Log(v3List[i]);
- // }
- //}
- }
- public void AddArrow(float Valuex, float Valuey)
- {
- if (this.transform.childCount >= 5)
- {
- Destroy(transform.GetChild(0).gameObject);
- }
- ShowArrow(Valuex, Valuey);
- }
- public void ShowArrow(float Valuex, float Valuey)
- {
- if (transform.childCount > 0)
- {
- num++;
- if (num > 9)
- {
- num = 1;
- }
- }
- else
- {
- num = 1;
- }
- GameObject obj = Instantiate(arrow) as GameObject;
- //obj.GetComponentInChildren<Text>().text = Valuex + "," + Valuey;
- obj.transform.position = CameraView.PosChange(Valuex, 1 - Valuey, 1, GHZRTCCamera.Instance.cam.transform);
- obj.transform.SetParent(this.transform);
- NewJiantou newJiantou = obj.transform.GetComponent<NewJiantou>();
- if (newJiantou)
- {
- newJiantou.Init(num);
- }
- if (TimerMgr.Instance)
- {
- TimerMgr.Instance.CreateTimer(() => { Destroy(obj); }, 60f);
- }
- }
- public void DeleteAll()
- {
- if (transform.childCount > 0)
- {
- for (int i = 0; i < transform.childCount; i++)
- {
- Destroy(transform.GetChild(i).gameObject);
- }
- }
- num = 0;
- }
- public Vector3 PosChange(float a, float b)
- {
- Vector3[] v3List = GetCorners(1f);
- Vector3 posX = Vector3.zero;
- float juliX = Vector3.Distance(v3List[1], v3List[0]);
- Vector3 vector = (v3List[1] - v3List[0]).normalized; //向量单位化
- float rand = juliX * a;//随机距离
- posX = vector * rand; //得到新坐标
- posX += v3List[0];
- Vector3 posY = Vector3.zero;
- float juliY = Vector3.Distance(v3List[2], v3List[0]);
- Vector3 vectorY = (v3List[0] - v3List[2]).normalized; //向量单位化
- float randY = b * juliY;//随机距离
- posY = vectorY * randY; //得到新坐标
- posY += v3List[2];
- return new Vector3(posX.x, posY.y, v3List[0].z);
- }
- Vector3[] GetCorners(float distance)
- {
- Vector3[] corners = new Vector3[4];
- float halfFOV = (GHZRTCCamera.Instance.cam.fieldOfView * 0.5f) * Mathf.Deg2Rad;
- float aspect = GHZRTCCamera.Instance.cam.aspect;
- float height = distance * Mathf.Tan(halfFOV);
- float width = height * aspect;
- Transform tx = GHZRTCCamera.Instance.cam.transform;
- // UpperLeft
- corners[0] = tx.position - (tx.right * width);
- corners[0] += tx.up * height;
- corners[0] += tx.forward * distance;
- // UpperRight
- corners[1] = tx.position + (tx.right * width);
- corners[1] += tx.up * height;
- corners[1] += tx.forward * distance;
- // LowerLeft
- corners[2] = tx.position - (tx.right * width);
- corners[2] -= tx.up * height;
- corners[2] += tx.forward * distance;
- // LowerRight
- corners[3] = tx.position + (tx.right * width);
- corners[3] -= tx.up * height;
- corners[3] += tx.forward * distance;
- return corners;
- }
- }
|