123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330 |
- 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();
- }
- // Debug.Log("Clear SpotsList obVuforia");
- // GameManager.Instance.destroyGo(this.obVuforia.gameObject);
- //GameManager.Instance.destroyGo(_spotsObj);
- // _spotsObj = null;
- //Debug.Log("Clear SpotsList obVuforia VuforiaItem");
- //GameManager.Instance.destroyGo(VuforiaItem);
- }
- 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();
- }
- isInitModel = true;
- /*
- if (!isInitModel)
- {
- Dictionary<string, ModelList> NewmodelList = new Dictionary<string, ModelList>();
- foreach (var mlkeys in modelList.Keys)
- {
- ModelList ml = modelList[mlkeys];
- ml._model = GameObject.Instantiate<GameObject>(ml.Model);
- JsonData msg = UserSceneManager.smsg;
- for (int i = 0; i < msg["listSpoit"].Count; i++)
- {
- Debug.Log("DGJ2 ==New1==> " + this.id + "_" + msg["listSpoit"][i]["id"].ToString());
- if (this.id == msg["listSpoit"][i]["id"].ToString())
- {
- for (int j = 0; j < msg["listSpoit"][i]["material"].Count; j++)
- {
- if (msg["listSpoit"][i]["material"][j]["materialList"] != null && msg["listSpoit"][i]["material"][j]["materialList"].IsArray)
- {
- for (int z = 0; z < msg["listSpoit"][i]["material"][j]["materialList"].Count; z++)
- {
- Debug.Log("DGJ2 ==New1==> " + this.triggerImage + "_" + msg["listSpoit"][i]["material"][j]["materialList"][z]["id"].ToJson() + "_" + (msg["listSpoit"][i]["material"][j]["materialList"][z]["objectTransform"].ToJson()));
- ml.materialList[z].objectTransform = JsonConvert.DeserializeObject<ObjectTransform>(msg["listSpoit"][i]["material"][j]["materialList"][z]["objectTransform"].ToJson());
- //modellist.materialList[z].initModelObj();
- Debug.Log("DGJ2 ==New1==> " + ml.materialList[z].id + "_" + msg["listSpoit"][i]["material"][j]["materialList"][z]["id"].ToJson());
- ml.materialList[z].name = this.triggerImage;
- // GameManager.Instance.StartCoroutine(modellist.materialList[z].initFrist());
- }
- }
- }
- }
- }
- NewmodelList.Add(mlkeys, ml);
- for (int i = 0; i < ml.materialList.Count; i++)
- {
- if (ml._model.transform.GetChild(0).GetComponent<YangShiManager>())
- {
- if (ml.materialList[i]._model)
- {
- ml.materialList[i]._model = ml._model.transform.GetChild(0).GetComponent<YangShiManager>().yangshiList[i].useObj;
- ml.materialList[i].prefabModel = ml.materialList[i]._model;
-
- // ml.materialList[i].initFrist();
- }
- else
- {
- ml.materialList[i]._model = ml._model.transform.GetChild(0).GetComponent<YangShiManager>().yangshiText.gameObject;
- ml.materialList[i].prefabModel = ml.materialList[i]._model;
-
- // ml.materialList[i].initFrist();
- }
- }
- else
- {
- ml.materialList[i]._model = ml._model.transform.GetChild(i).gameObject;
- ml.materialList[i].prefabModel = ml._model.transform.GetChild(i).gameObject;
-
- // ml.materialList[i].initFrist();
- }
- }
- ml.Model.SetActive(true);
- ml.Model.transform.parent = _spotsObj.transform;
- GameObject modelList2 = ml.Model;
- BoundingBox bb = modelList2.GetComponent<BoundingBox>();
- if (bb)
- {
- GameObject.Destroy(bb);
- }
- NearInterationGrabbable ng = modelList2.GetComponent<NearInterationGrabbable>();
- if (ng)
- {
- GameObject.Destroy(ng);
- }
- ManipulationHandler mh = modelList2.GetComponent<ManipulationHandler>();
- if (mh)
- {
- GameObject.Destroy(mh);
- }
- BoxCollider bc = modelList2.GetComponent<BoxCollider>();
- if (!bc)
- {
- bc = modelList2.AddComponent<BoxCollider>();
- bc.size = new Vector3(bc.size.x, bc.size.y, 0.01f);
- }
- bb = modelList2.AddComponent<BoundingBox>();
- bb.FlattenAxis = BoundingBox.FlattenModeType.FlattenZ;
- bb.ActiveHandle = BoundingBox.HandleType.Rotation | BoundingBox.HandleType.Scale;
- ng = modelList2.AddComponent<NearInterationGrabbable>();
- mh = modelList2.AddComponent<ManipulationHandler>();
- TimerMgr.Instance.CreateTimer(() =>
- {
- bb.enabled = GameManager.m_IsStartEditorzu;
- if (modelList2.transform.Find("BoundingBox") && modelList2.transform.Find("BoundingBox").gameObject != null)
- modelList2.transform.Find("BoundingBox").gameObject.SetActive(GameManager.m_IsStartEditorzu);
- if (bc)
- {
- bc.enabled = GameManager.m_IsStartEditorzu;
- }
- if (mh)
- mh.enabled = GameManager.m_IsStartEditorzu;
- if (ng)
- ng.enabled = GameManager.m_IsStartEditorzu;
- }, 1, -1);
- ml.initModelObj();
- }
- modelList = NewmodelList;
- isInitModel = true;
- }*/
- }
- UserSceneUI.Instance.obj.GetComponent<UserChooseScene>().st.SetActive(false);
- SendNetConnectPointTrigger sendNet = new SendNetConnectPointTrigger();
- sendNet.sn = SendSN.GetSN();
- //sendNet.sn = API_GSXR_Slam.SlamManager.plugin.SN;
- 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());
- // if (obVuforia.TargetName == behaviour.TargetName)
- // SpotsObj.SetActive(false);
- }
- }
- 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);
- }
- }
- }
|