142 lines
4.1 KiB
C#
142 lines
4.1 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using UnityEngine.XR.WSA;
|
|
//using UnityEngine.XR.WSA.Sharing;
|
|
/// <summary>
|
|
/// 导出锚点
|
|
/// </summary>
|
|
public class ExportAnchorScript : MonoBehaviour
|
|
{
|
|
public string exportingAnchorName;
|
|
private List<byte> exportingAnchorBytes = new List<byte>();
|
|
|
|
WorldAnchor gameRootAnchor;
|
|
public Text uploadingTip;
|
|
public Text createTip;
|
|
public Text createTip2;
|
|
public Button uploadingBtn;
|
|
public Button createBtn;
|
|
public Button quitBtn;
|
|
public TextMeshProUGUI posText;
|
|
public Transform anchorPos;
|
|
public Transform anchorParent;
|
|
|
|
|
|
IEnumerator read()
|
|
{
|
|
WWW www = new WWW(Application.persistentDataPath + "/AnchorSetting.txt");
|
|
|
|
yield return www;
|
|
|
|
byte[] test = www.bytes;
|
|
exportingAnchorBytes = test.ToList();
|
|
}
|
|
void Start()
|
|
{
|
|
//StartCoroutine(read());
|
|
uploadingBtn.onClick.AddListener(() =>
|
|
{
|
|
uploadingBtn.interactable = false;
|
|
Invoke("ResetBtn", 5);
|
|
UpLoadingAnchor();
|
|
});
|
|
|
|
createBtn.onClick.AddListener(() =>
|
|
{
|
|
createBtn.interactable = false;
|
|
Invoke("ResetBtn", 5);
|
|
Send();
|
|
});
|
|
|
|
quitBtn.onClick.AddListener(() =>
|
|
{
|
|
UnityEngine.SceneManagement.SceneManager.LoadScene("LoginSenceMR");
|
|
});
|
|
}
|
|
private void Update()
|
|
{
|
|
posText.text = anchorPos.localPosition.ToString("f3")+"\n"+anchorPos.localEulerAngles.ToString("f3");
|
|
}
|
|
public void SetAnchorParent()
|
|
{
|
|
anchorPos.SetParent(anchorParent);
|
|
}
|
|
public void SetAnchor()
|
|
{
|
|
anchorPos.SetParent(null);
|
|
}
|
|
public void ResetBtn()
|
|
{
|
|
if (!createBtn.interactable) createBtn.interactable = true;
|
|
if (!uploadingBtn.interactable) uploadingBtn.interactable = true;
|
|
}
|
|
|
|
private void OnExportDataAvailable(byte[] data)
|
|
{
|
|
exportingAnchorBytes.AddRange(data);
|
|
createTip2.gameObject.SetActive(true);
|
|
createTip2.text = exportingAnchorBytes.ToArray().Length.ToString();
|
|
|
|
}
|
|
|
|
public void Send()
|
|
{
|
|
if (exportingAnchorBytes != null) exportingAnchorBytes.Clear();
|
|
gameRootAnchor = GetComponent<WorldAnchor>();
|
|
if (gameRootAnchor!=null)
|
|
{
|
|
DestroyImmediate(gameRootAnchor);
|
|
}
|
|
//gameRootAnchor = gameObject.AddComponent<WorldAnchor>();
|
|
//WorldAnchorTransferBatch transferBatch = new WorldAnchorTransferBatch();
|
|
//transferBatch.AddWorldAnchor(exportingAnchorName, this.GetComponent<WorldAnchor>());
|
|
//WorldAnchorTransferBatch.ExportAsync(transferBatch, OnExportDataAvailable, OnExportComplete);
|
|
}
|
|
|
|
|
|
//private void OnExportComplete(SerializationCompletionReason completionReason)
|
|
//{
|
|
// createTip2.text = exportingAnchorBytes.ToArray().Length.ToString()+"\n"+ completionReason;
|
|
// if (completionReason == SerializationCompletionReason.Succeeded)
|
|
// {
|
|
// WriteAnchorSetting();
|
|
// }
|
|
// else
|
|
// {
|
|
// createTip.text = "生成失败";
|
|
// }
|
|
//}
|
|
private void WriteAnchorSetting()
|
|
{
|
|
FileStream sw = new FileStream(Application.persistentDataPath + "/AnchorSetting.txt", FileMode.OpenOrCreate, FileAccess.Write);
|
|
sw.Write(exportingAnchorBytes.ToArray(), 0, exportingAnchorBytes.ToArray().Length);
|
|
sw.Close();
|
|
sw.Dispose();
|
|
createTip.text = "生成成功";
|
|
createTip2.gameObject.SetActive(false);
|
|
}
|
|
|
|
public void UpLoadingAnchor()
|
|
{
|
|
|
|
StartCoroutine(MyNetMQClient.UpLoadFile("http://" + MyNetMQClient.CallIP + "/Handler/Files.ashx", exportingAnchorBytes.ToArray(), "AnchorSetting.txt", back =>
|
|
{
|
|
if (back.state)
|
|
{
|
|
uploadingTip.text = "上传成功";
|
|
}
|
|
else
|
|
{
|
|
uploadingTip.text = "上传失败";
|
|
}
|
|
}));
|
|
}
|
|
|
|
}
|