12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- using LitJson;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using XRTool.Util;
- public class SynPlayerTransform : MonoSingleton<SynPlayerTransform>
- {
- public Transform player;
- public bool isPushPos;
- void Start()
- {
- isPushPos = false;
- player = OpenXRCamera.Instance.head;
- StartCoroutine(PushPos(0.5f));
- }
- // Update is called once per frame
- void Update()
- {
- transform.eulerAngles = new Vector3(0, player.eulerAngles.y, 0);
- transform.position = new Vector3(player.position.x, 0, player.position.z);
- // UILogManager.Instance.text3.text = transform.localEulerAngles.y.ToString();
- if (Input.GetKeyDown(KeyCode.Y))
- {
- isPushPos = !isPushPos;
- }
- }
- private IEnumerator PushPos (float times)
- {
-
-
- while (true)
- {
- yield return new WaitForSeconds(times);
- if (isPushPos)
- {
- JsonData obj = new JsonData();
- obj["x"] = (float)(Mathf.Round(player.position.x * 100)) / 100;
- obj["y"] = (float)(Mathf.Round(player.position.y * 100)) / 100;
- obj["z"] = (float)(Mathf.Round(player.position.z * 100)) / 100;
- obj["time"] = CommonMethod.GetCurrentTimeUnixMilliseconds();
- MQTTManager.Instance.PushMsg(MQTTManager.Instance.front + "younuo", obj.ToJson());
- }
- }
- }
- /// <summary>
- /// 返回当前朝向的机柜 , False 单排机柜 1 3 5...
- /// </summary>
- /// <returns></returns>
- public bool GetOrientation()
- {
- if (Mathf.Abs(transform.localEulerAngles.y) > 90&& Mathf.Abs(transform.localEulerAngles.y)<270)
- {
- return true;
- }
- return false;
- }
- /// <summary>
- /// 判断当前在第几排机柜之间
- /// </summary>
- public int GetRowCabinets()
- {
- int row = 0;
- float rowDis = 0;
- int index = 0;
- for (int i = 0; i < MachineRoomManager.Instance.listObjes.Count; i+=MachineRoomManager.Instance.data.line*2)
- {
- float disZ = Mathf.Abs(transform.position.z - MachineRoomManager.Instance.listObjes[i].transform.position.z);
- if(rowDis>disZ)
- {
- row = index;
- rowDis = disZ;
- }
- index++;
- }
- return row;
- }
- }
|