using System; using System.Collections; using UnityEngine; using UnityEngine.XR.WSA; //using UnityEngine.XR.WSA.Sharing; /// /// 导入锚点 /// public class ImpotAnchorScript : MonoBehaviour { public GameObject loaderObj; public GameObject model; public string exportingAnchorName; // 导入的目标对象 public GameObject targetObject; int retryCount = 20; public byte[] exportingAnchorBytes; public Vector3 anchorOriginalPos; void Start() { #if UNITY_EDITOR loaderObj.SetActive(false); //anchorOriginalPos = transform.position; #endif } //public void OnImportComplete(SerializationCompletionReason completionReason, WorldAnchorTransferBatch deserializedTransferBatch) //{ // if (completionReason != SerializationCompletionReason.Succeeded) // { // if (retryCount > 0) // { // retryCount--; // WorldAnchorTransferBatch.ImportAsync(exportingAnchorBytes, OnImportComplete); // } // return; // } // string[] ids = deserializedTransferBatch.GetAllIds(); // foreach (string id in ids) // { // if (targetObject != null && id.Equals(exportingAnchorName)) // { // if (targetObject.GetComponent() == null) // { // targetObject.AddComponent(); // } // deserializedTransferBatch.LockObject(id, targetObject); // //CubeCommand.Instance.Init(); // loaderObj.SetActive(false); // anchorOriginalPos = model.transform.localPosition; // return; // } // } //} IEnumerator GetData() { WWW www = new WWW("http://172.16.1.128:8100/aaa.txt"); yield return www; if (www.error == null) { //exportingAnchorBytes = new List(Convert.FromBase64String(str)); // exportingAnchorBytes = www.bytes; if (BitConverter.ToInt32(www.bytes, 0) == 9999) { byte[] tmps = new byte[www.bytes.Length - 4]; Array.Copy(www.bytes, 4, tmps, 0, www.bytes.Length - 4); exportingAnchorBytes = tmps; } } else { } } IEnumerator GetAnchor() { WWW w = new WWW(Application.streamingAssetsPath + "/AnchorSetting.txt"); yield return w; if (w.error == null) { exportingAnchorBytes = w.bytes; Import(); } } public void Import() { Debug.Log(exportingAnchorBytes.Length); //WorldAnchorTransferBatch.ImportAsync(exportingAnchorBytes, OnImportComplete); } public void Exit() { Application.Quit(); } }