123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510 |
- using SC.XR.Unity.Module_InputSystem;
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- using UnityEngine;
- using UnityEngine.UI;
- using Ximmerse.XR.Tag;
- /// <summary>
- /// 机柜Tag管理
- /// </summary>
- public class BladeServerManager : MonoSingleton<BladeServerManager>
- {
- /// <summary>
- /// 所有的 UIItem
- /// </summary>
- public List<DataItem> listTagTracking = new List<DataItem>();
- // public List<TagTracking> nowTagTracking = new List<TagTracking>();
- /// <summary>
- /// 当前识别到的Tag
- /// </summary>
- public Dictionary<int, TagTracking> dicNowTagTracking = new Dictionary<int, TagTracking>();
- /// <summary>
- /// 当前使用的Tag
- /// </summary>
- public TagTracking foundTag;
- public string foundID;
- /// <summary>
- /// 当前Tag对应的UIItem
- /// </summary>
- public DataItem foundItem;
- /// <summary>
- /// 当前Tag 对应的机柜
- /// </summary>
- public MachineObj foundMachineObj;
- /// <summary>
- /// 检测角度
- /// </summary>
- public float foundAngle;
- /// <summary>
- /// 显示移动的距离
- /// </summary>
- public float showDis;
- /// <summary>
- /// 隐藏的距离
- /// </summary>
- public float fadeDis;
- /// <summary>
- /// 编辑Tag的移动框
- /// </summary>
- // public Transform selectPanel;
- /// <summary>
- /// 模拟测试用的
- /// </summary>
- public TagTracking TestTracking;
- public GameObject deviceDetails;
- /// <summary>
- /// 同步位置的Obj
- /// </summary>
- private Transform tagObj;
- /// <summary>
- /// 是否是编辑状态
- /// </summary>
- private bool state = false;
- //public delegate void TrackingFound(DataItem tagobj);
- ///// <summary>
- ///// 物体识别到显示
- ///// </summary>
- //public TrackingFound OnTrackFound;
- //public delegate void TrackingLast(DataItem tagobj);
- ///// <summary>
- ///// 物体识别到隐藏
- ///// </summary>
- //public TrackingLast OnTrackLast;
- private bool isSync;
- public bool isDaoHang;
- private void Start()
- {
- tagObj = new GameObject("TagObj").transform;
- tagObj.position = Vector3.zero;
- tagObj.eulerAngles = Vector3.zero;
- isSync = false;
- showDis = 0.55f;
- fadeDis = 1.3f;
- //ManipulationHandler manipulation = selectPanel.GetComponent<ManipulationHandler>();
- //manipulation.PointerDown.AddListener(( msg )=> { SelectPointerDown(); });
- //manipulation.PointerUp.AddListener((msg) => { SelectPointerUp(); });
- }
- float dis;
- float angle;
- Quaternion rot;
- float roty;
- Transform point;
- private void Update()
- {
- #if UNITY_EDITOR
- if(Input.GetKeyDown(KeyCode.K))
- {
- OnTrackingFound(TestTracking);
- }
- #endif
- // Debug.Log(state);
- // if(isDaoHang)
- TagSynchronization();
- }
- /// <summary>
- /// 同步Tag
- /// </summary>
- private void TagSynchronization()
- {
- if (foundItem != null && foundTag != null && !state)
- {
- dis = Vector3.Distance(new Vector3(foundTag.transform.position.x,0, foundTag.transform.position.z) ,new Vector3(OpenXRCamera.Instance.head.transform.position.x,0, OpenXRCamera.Instance.head.transform.position.z) );
-
- angle = Vector3.Angle(OpenXRCamera.Instance.head.GetComponent<Camera>().transform.forward, foundTag.transform.position - OpenXRCamera.Instance.head.transform.position);
- // Debug.Log("Dis " + dis + " Angle" + angle + " showDis " + showDis + " fadeDis " + fadeDis);
- if (Mathf.Abs(dis) < showDis && isDaoHang)
- {
- if (!foundItem.gameObject.activeSelf&& (BD_ShowDevicecDetailsObj.Instance == null||(BD_ShowDevicecDetailsObj.Instance != null && (!BD_ShowDevicecDetailsObj.Instance.gameObject.activeSelf||
- !BD_ShowDevicecDetailsObj.Instance.transform.parent.gameObject.activeSelf))))
- {
- Debug.Log("DGJ ==== >> ShowFoundItem ");
- foundItem.gameObject.SetActive(true);
- if (BD_ShowDevicecDetailsObj.Instance != null && BD_ShowDevicecDetailsObj.Instance.gameObject.activeSelf)
- BD_ShowDevicecDetailsObj.Instance.gameObject.SetActive(false);
- // ScenesManager.Instance.showOffice(ScenesManager.SceneType.DeviceDetails);
- // OnTrackFound(foundItem);
- }
- point = foundTag.transform.GetChild(0);
- point.localPosition = foundItem.offsetPos;
- switch (Mathf.Abs(foundItem.eulerAxle))
- {
- case 1:
- point.localEulerAngles = new Vector3(0, 0, 90 * (foundItem.eulerAxle / Mathf.Abs(foundItem.eulerAxle)));
- break;
- case 2:
- point.localEulerAngles = new Vector3(0, foundItem.eulerAxle > 0 ? 0 : 180, 0);
- break;
- case 3:
- point.localEulerAngles = new Vector3(90 * (foundItem.eulerAxle / Mathf.Abs(foundItem.eulerAxle)), 0, 0);
- break;
- default:
- break;
- }
- if (isSync)
- {
- Debug.Log("Dis " + dis + " Angle" + angle + " showDis " + showDis + " fadeDis " + fadeDis);
- Debug.Log("FoundItem " + foundItem.transform.position + " point" + point.transform.position + " CA " + new Vector3(point.transform.position.x - foundItem.transform.position.x, 0, point.position.z - foundItem.transform.position.z));
- //foundItem.transform.Translate(new Vector3(0, point.eulerAngles.y, 0), Time.deltaTime * 10);
- foundItem.transform.eulerAngles = new Vector3(0, point.eulerAngles.y, 0);
- foundItem.transform.position = point.transform.position;
- UICallManager.Instance.OnTrackfound(foundItem);
- isSync = false;
- //MachineRoomManager.Instance.transform.eulerAngles = new Vector3(MachineRoomManager.Instance.transform.eulerAngles.x, point.eulerAngles.y+180, MachineRoomManager.Instance.transform.eulerAngles.z);
- //MachineRoomManager.Instance.transform.position += new Vector3(point.transform.position.x - foundItem.transform.position.x, point.position.y - foundItem.transform.position.y, point.position.z - foundItem.transform.position.z);
- //float offy = OpenXRCamera.Instance.transform.position.y - foundItem.transform.position.y;
- //offy = offy * 0.05f;
- //MachineRoomManager.Instance.transform.position += new Vector3(0, offy, 0);
- }
-
- }
- // 隐藏的距离判断改由每个DataItem 自己监测
- //else if (Mathf.Abs(dis) > fadeDis)
- //{
- // //OnTrackLast(foundItem);
- // // foundItem.gameObject.SetActive(false);
- // foundItem.Hide();
- // UICallManager.Instance.OnTracklast(foundItem);
- // foundItem = null;
- // // foundTag = null;
- // dicNowTagTracking.Clear();
- // dicNowTagTracking = new Dictionary<int, TagTracking>();
-
-
- //}
- }
- else
- {
- isSync = true;
- }
- }
- public void OnTrackingFound(TagTracking tracking)
- {
- #region 组合Tag识别
- //if (!dicNowTagTracking.ContainsKey(tracking.TrackId))
- //{
- // //if(dicNowTagTracking.Count==1)
- // //{
- // // TagTracking firstTracking = dicNowTagTracking.FirstOrDefault().Value;
- // // Debug.Log(firstTracking.TrackId +" "+tracking.TrackId+" "+ Vector3.Distance(firstTracking.transform.position, tracking.transform.position) + " Distance");
- // // //if (Vector3.Distance(firstTracking.transform.position, tracking.transform.position) < 0.1f) // 判断两个Tag是否为并列使用
- // // //{
- // // // dicNowTagTracking.Add(tracking.TrackId, tracking);
- // // // tagObj.SetParent(tracking.transform);
- // // // tagObj.localEulerAngles = Vector3.zero;
- // // // tagObj.localPosition = Vector3.zero;
- // // // tagObj.SetParent(firstTracking.transform);
- // // // if (tagObj.localPosition.x > 0)
- // // // {
- // // // foundTag = firstTracking;
- // // // foundID = tracking.TrackId.ToString() + firstTracking.TrackId.ToString();
- // // // }
- // // // else
- // // // {
- // // // foundTag = tracking;
- // // // foundID = firstTracking.TrackId.ToString() + tracking.TrackId.ToString();
- // // // }
- // // //}
- // // //else
- // // //{
- // // // // 初始化
- // // // StartTracking(tracking);
- // // //}
- // //}
- // //else
- // //{
- // // // 初始化
- // // StartTracking(tracking);
- // //}
- // #endregion
- // if (dicNowTagTracking == null || dicNowTagTracking.Count == 0)
- // {
- // // 初始化
- // StartTracking(tracking);
- // }
- //}
- #endregion
- foundTag = tracking;
- foundID = tracking.TrackId.ToString();
- Debug.Log("FoundID "+ foundID);
- // UILogManager.Instance.SendLogText(2, foundID);
- if (foundItem==null|| foundItem.tagId!= int.Parse( foundID))
- {
- QueryFoundItem(int.Parse(foundID));
- isSync = true;
- WayFindingManager.Instance.CloseWayFind();
- // ScenesManager.Instance.showOffice(ScenesManager.SceneType.DeviceDetails);
- }
-
- Debug.Log(" FoundItem " + foundItem.ID);
- UILogManager.Instance.SendLogText(1, tracking.TrackId.ToString() + " " + foundID);
- }
- public void OnTrackingLost(TagTracking tracking)
- {
- //if (tracking.TrackId == foundTag.TrackId)
- // foundItem = null;
- }
- private void StartTracking(TagTracking tracking)
- {
- if(MachineRoomManager.Instance.isDataInit)
- {
- dicNowTagTracking.Clear();
- dicNowTagTracking = new Dictionary<int, TagTracking>();
- dicNowTagTracking.Add(tracking.TrackId, tracking);
- foundTag = tracking;
- foundID = tracking.TrackId.ToString();
- }
-
- }
- private void QueryFoundItem(int foundID)
- {
- Debug.Log("DGJ ===> QueryFoundItem " + listTagTracking.Count);
- if (MachineRoomManager.Instance.isDataInit)
- {
- int row = SynPlayerTransform.Instance.GetRowCabinets();
- bool orientation = SynPlayerTransform.Instance.GetOrientation();
- if(orientation)
- {
- row += 2;
- }
- else
- {
- row += 1;
- }
- Debug.Log(row * MachineRoomManager.Instance.data.list + " " + (row + 1) * MachineRoomManager.Instance.data.list);
- for (int i = row*MachineRoomManager.Instance.data.list; i < (row+1)*MachineRoomManager.Instance.data.list; i++)
- {
- Debug.Log("DGJ ===> " + listTagTracking[i].tagId);
- if (listTagTracking[i].tagId == foundID)
- {
- if (foundItem != null)
- {
- //foundItem.gameObject.SetActive(false);
- // foundItem.Hide();
- if (state)
- {
- foundItem.isSelect = false;
- foundItem.SetSelect(false);
- // foundItem.SaveEdiotrData(selectPanel);
- }
- }
- foundItem = listTagTracking[i];
- // foundItem.gameObject.SetActive(true);
- Debug.Log(" QueryFoundItem " + foundID);
- if (state)
- {
- //selectPanel.eulerAngles = foundItem.transform.eulerAngles;
- //selectPanel.position = foundItem.transform.position;
- //selectPanel.gameObject.SetActive(true);
- foundItem.isSelect = true;
- foundItem.SetSelect(true);
- }
- break;
- }
- }
- #region old
- //for (int i = 0; i < listTagTracking.Count; i++)
- //{
- // Debug.Log("DGJ ===> " + listTagTracking[i].tagId);
- // if (listTagTracking[i].tagId == foundID)
- // {
- // if (foundItem != null)
- // {
- // //foundItem.gameObject.SetActive(false);
- // // foundItem.Hide();
- // if (state)
- // {
- // foundItem.isSelect = false;
- // foundItem.SetSelect(false);
- // // foundItem.SaveEdiotrData(selectPanel);
- // }
- // }
- // foundItem = listTagTracking[i];
- // // foundItem.gameObject.SetActive(true);
- // Debug.Log(" QueryFoundItem " + foundID);
- // if (state)
- // {
- // //selectPanel.eulerAngles = foundItem.transform.eulerAngles;
- // //selectPanel.position = foundItem.transform.position;
- // //selectPanel.gameObject.SetActive(true);
- // foundItem.isSelect = true;
- // foundItem.SetSelect(true);
- // }
- // break;
- // }
- //}
- // 找到x-tag 对应的机柜
- //for (int i = 0; i < MachineRoomManager.Instance.listObjes.Count; i++)
- //{
- // if(MachineRoomManager.Instance.listObjes[i].deviceParameters!=null&&MachineRoomManager.Instance.listObjes[i].deviceParameters.deviceId == foundItem.ID.ToString())
- // {
- // // 找到后,
- // foundMachineObj = MachineRoomManager.Instance.listObjes[i];
- // }
- //}
- #endregion
- if (foundItem != null && foundItem.tagId != foundID)
- {
- //foundItem.gameObject.SetActive(false);
- // foundItem.Hide();
- foundItem.isSelect = false;
- foundItem.SetSelect(false);
- foundItem = null;
-
- }
- }
-
-
- }
- public void EditorTag( Text text)
- {
- if(foundItem!=null)
- {
- text.text = state ? "打开" : "关闭";
- text.text += "机柜Tag编辑";
- state = !state;
- if(state)
- {
- //selectPanel.eulerAngles = foundItem.transform.eulerAngles;
- //selectPanel.position = foundItem.transform.position;
- //selectPanel.gameObject.SetActive(true);
-
- foundItem.isSelect = true;
- foundItem.SetSelect(true);
- }
- else
- {
- foundItem.SaveEdiotrData(foundTag.transform);
- //selectPanel.gameObject.SetActive(false);
- foundItem.isSelect = false;
- foundItem.SetSelect(false);
- }
- }
- if(!state)
- {
- //for (int i = 0; i < listTagTracking.Count; i++)
- //{
- // listTagTracking[i].SaveData();
- //}
- foundItem.SaveData();
- // Servermanager.Instance.Save();
- MachineRoomManager.Instance.SaveAllData();
- }
- }
- public void SelectPointerEnter()
- {
- //if(foundItem!=null)
- // foundItem.SelectObj(selectPanel);
- }
-
- public void SelectPointerDown()
- {
- if (foundItem != null&& foundTag!=null)
- {
- foundItem.isSelect = true;
- foundItem.SetSelect( true);
- }
-
- }
- public void SelectPointerUp()
- {
- if (foundItem != null && foundTag != null)
- {
- foundItem.isSelect = false;
- foundItem.SetSelect(false);
- foundItem.SaveEdiotrData(foundTag.transform);
- }
-
- }
- private void SaveData()
- {
- /*
- *
- *
- */
- }
- }
|