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 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 modelList = new Dictionary(); 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(); if (obVuforia.gameObject.GetComponent()) { GameObject.Destroy(obVuforia.gameObject.GetComponent()); } obVuforia.gameObject.AddComponent(); DefaultObserverEventHandler imageaction = obVuforia.gameObject.GetComponent(); 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(); } /* if (!isInitModel) { Dictionary NewmodelList = new Dictionary(); foreach (var mlkeys in modelList.Keys) { ModelList ml = modelList[mlkeys]; ml._model = GameObject.Instantiate(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(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()) { if (ml.materialList[i]._model) { ml.materialList[i]._model = ml._model.transform.GetChild(0).GetComponent().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().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(); if (bb) { GameObject.Destroy(bb); } NearInterationGrabbable ng = modelList2.GetComponent(); if (ng) { GameObject.Destroy(ng); } ManipulationHandler mh = modelList2.GetComponent(); if (mh) { GameObject.Destroy(mh); } BoxCollider bc = modelList2.GetComponent(); if (!bc) { bc = modelList2.AddComponent(); bc.size = new Vector3(bc.size.x, bc.size.y, 0.01f); } bb = modelList2.AddComponent(); bb.FlattenAxis = BoundingBox.FlattenModeType.FlattenZ; bb.ActiveHandle = BoundingBox.HandleType.Rotation | BoundingBox.HandleType.Scale; ng = modelList2.AddComponent(); mh = modelList2.AddComponent(); 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().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); } } }