123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329 |
- using LitJson;
- using Newtonsoft.Json;
- using SC.XR.Unity.Module_InputSystem;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using Vuforia;
- using XRTool.Util;
- public class SpotsItem
- {
- public List<sspos> position;
- public string id;
- public string name;
- public string triggerImageMark;
- public Vector3 pos;
- public Vector3 eul;
- public string updateTime;
- public string triggerImage;
- public int triggerImageId;
- public UserSceneItem usi;
-
- public Dictionary<string, ModelList> modelList = new Dictionary<string, ModelList>();
- public GameObject VuforiaItem;
- GameObject _spotsObj;
- public GameObject SpotsObj
- {
- get
- {
- if (_spotsObj == null)
- {
- VuforiaItem = new GameObject("Vufroia--"+name);
- VuforiaItem.transform.parent = usi.SceneModel.transform;
- VuforiaItem.transform.localPosition = Vector3.zero;
- VuforiaItem.transform.localEulerAngles = Vector3.zero;
- VuforiaItem.SetActive(false);
- _spotsObj = new GameObject("景点--"+name);
- _spotsObj.transform.parent = VuforiaItem.transform;
- }
- return _spotsObj;
- }
- }
- public ObserverBehaviour obVuforia;
- public bool isInitModel;
- public void Clear()
- {
- Debug.Log("Clear SpotsList modelList");
- foreach (var i in modelList.Values)
- {
- i.Clear();
- }
-
-
-
-
-
-
- }
- public void setObVuforia(ObserverBehaviour obVuforia)
- {
- this.obVuforia = obVuforia;
- Debug.Log("添加Vuforia监听" + obVuforia.TargetName+" 景点===》"+name);
- this.obVuforia.OnTargetStatusChanged += OnTargetStatusChanged;
- obVuforia.gameObject.name = "ImageTarget_" + obVuforia.TargetName;
- obVuforia.gameObject.AddComponent<TurnOffBehaviour>();
- if (obVuforia.gameObject.GetComponent<DefaultObserverEventHandler>())
- {
- GameObject.Destroy(obVuforia.gameObject.GetComponent<DefaultObserverEventHandler>());
- }
- obVuforia.gameObject.AddComponent<DefaultObserverEventHandler>();
- DefaultObserverEventHandler imageaction = obVuforia.gameObject.GetComponent<DefaultObserverEventHandler>();
- obj = new GameObject("Cube");
- obj.transform.parent = imageaction.transform;
- obj.transform.localEulerAngles = new Vector3(90, 0, 0);
- obj.transform.localPosition = Vector3.zero;
- }
- GameObject obj;
- void OnTargetStatusChanged(ObserverBehaviour behaviour, TargetStatus status)
- {
- if (status.Status == Status.TRACKED)
- {
- Debug.Log("OnTargetStatusChanged 发现 " + behaviour.TargetName + "status ==>" + status.Status.ToString());
- if(obVuforia.TargetName == behaviour.TargetName)
- {
- foreach (var item in usi.SpotsList.Keys)
- {
- if (usi.SpotsList[item].obVuforia.TargetName == behaviour.TargetName)
- {
- if (usi.SpotsList[item].VuforiaItem.activeSelf&& usi.SpotsList[item].id!=id )
- {
- usi.SpotsList[item].VuforiaItem.SetActive(false);
- }
- else if(usi.SpotsList[item].id == id)
- {
- VuforiaItem.SetActive(true);
- }
- }
- else
- {
- usi.SpotsList[item].VuforiaItem.SetActive(false);
- }
- }
- Debug.Log("OnTargetStatusChanged 发现 VuforiaItem " + VuforiaItem.name);
- TimerMgr.Instance.CreateTimer(()=> {
- VuforiaItem.transform.position = obj.transform.position;
- VuforiaItem.transform.eulerAngles = obj.transform.eulerAngles;
- VuforiaItem.transform.eulerAngles = new Vector3(0, VuforiaItem.transform.eulerAngles.y, 0);
- Debug.Log("OnTargetStatusChanged 发现 " + obj.transform.position + "status ==>" + obj.transform.eulerAngles);
- }, 0.1f,10);
- foreach (var i in modelList.Values)
- {
- Debug.Log("initModelObj===> " + i.id);
- i._model = SpotsObj;
- i.initModelObj();
- }
-
- }
- UserSceneUI.Instance.obj.GetComponent<UserChooseScene>().st.SetActive(false);
- SendNetConnectPointTrigger sendNet = new SendNetConnectPointTrigger();
- sendNet.sn = SendSN.GetSN();
-
- sendNet.projectId = int.Parse(usi.id);
- sendNet.id =int.Parse(id);
- string jsonData = JsonMapper.ToJson(sendNet);
- Debug.Log(jsonData);
- HttpTool.Instance.Post(HttpAction.sn_viewpoint, jsonData, (string msg)=> { });
- }
- else
- {
- Debug.Log("OnTargetStatusChanged 消失 " + behaviour.TargetName + "status ==>" + status.Status.ToString());
-
-
- }
- }
- public void initSpoitTfInfo(JsonData data)
- {
- if (data["nowScale"] != null && (data["nowScale"]["x"].ToString() != "0" || data["nowScale"]["y"].ToString() != "0" || data["nowScale"]["z"].ToString() != "0"))
- {
- SpotsObj.transform.localScale = new Vector3(float.Parse(data["nowScale"]["x"].ToString()), float.Parse(data["nowScale"]["y"].ToString()), float.Parse(data["nowScale"]["z"].ToString()));
- }
- else
- {
- SpotsObj.transform.localScale = Vector3.one;
- }
- if (data["nowPos"] != null && (data["nowPos"]["x"].ToString() != "0" || data["nowPos"]["y"].ToString() != "0" || data["nowPos"]["z"].ToString() != "0"))
- {
- SpotsObj.transform.localPosition = new Vector3(float.Parse(data["nowPos"]["x"].ToString()), float.Parse(data["nowPos"]["y"].ToString()), float.Parse(data["nowPos"]["z"].ToString()));
- }
- else
- {
- SpotsObj.transform.localPosition = Vector3.zero;
- }
- if (data["nowRot"] != null && (data["nowRot"]["x"].ToString() != "0" || data["nowRot"]["y"].ToString() != "0" || data["nowRot"]["z"].ToString() != "0"))
- {
- SpotsObj.transform.localEulerAngles = new Vector3(float.Parse(data["nowRot"]["x"].ToString()), float.Parse(data["nowRot"]["y"].ToString()), float.Parse(data["nowRot"]["z"].ToString()));
- }
- else
- {
- SpotsObj.transform.localEulerAngles = Vector3.zero;
- }
- }
- public void init()
- {
- VuforiaItem.transform.parent = usi.SceneModel.transform;
- VuforiaItem.transform.localPosition = Vector3.zero;
- VuforiaItem.transform.localEulerAngles = Vector3.zero;
- VuforiaItem.SetActive(false);
- }
- public void show()
- {
- foreach(var v in modelList.Values)
- {
- v.init(true);
- }
- }
- }
|