1118OPSSNew/Assets/Zion/Scripts/GameScene/Anchor/CubeScirpt.cs

116 lines
3.7 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Microsoft.MixedReality.Toolkit.UI;
using UnityEngine;
using UnityEngine.XR.WSA;
//using UnityEngine.XR.WSA.Persistence;
public class CubeScirpt : MonoBehaviour
{
/// <summary>
/// 被保存的锚点
/// </summary>
public string ObjectAnchorStoreName;
/// <summary>
/// 储存锚点的仓库
/// </summary>
//WorldAnchorStore anchorStore;
// /// <summary>
/// 是否被移动
/// </summary>
bool HasMove = false;
// Start is called before the first frame update
void Start()
{
//WorldAnchorStore的静态方法 获取WorldAnchorStore实例
//WorldAnchorStore.GetAsync(AnchorStoreReady);
}
//private void AnchorStoreReady(WorldAnchorStore store)
//{
// // anchorStore = store;
// // string[] ids = anchorStore.GetAllIds();
// //遍历之前保存的空间锚 载入指定id场景对象信息
// for (int i = 0; i < ids.Length; i++)
// {
// //if (ids[i] == ObjectAnchorStoreName)
// {
// // WorldAnchor worldAnchor = anchorStore.Load(ids[i], gameObject);
// break;
// }
// }
//}
// Update is called once per frame
void Update()
{
if (HasMove)
{
//gameObject.transform.position = Camera.main.transform.position + Camera.main.transform.forward * 2;
}
//Selecte();
}
//private void AttachingAnchor_OnTrackingChanged(WorldAnchor self, bool located)
//{
// Debug.Log("located:" + located);
// if (located)
// {
// bool saved = anchorStore.Save(ObjectAnchorStoreName, self);
// self.OnTrackingChanged -= AttachingAnchor_OnTrackingChanged;
// }
//}
//public void Selecte()
//{
// if (anchorStore == null)
// {
// return;
// }
// if (HasMove)
// {
// WorldAnchor attachingAnchor = gameObject.AddComponent<WorldAnchor>();
// if (attachingAnchor.isLocated)
// {
// bool saved = anchorStore.Save(ObjectAnchorStoreName, attachingAnchor);
// }
// else
// {
// //有时空间锚能立刻被定位到这时给对象添加空间锚后空间锚组件的isLocated属性值会被设为true这时 OnTrackingChanged
// //事件不会被触发。因此在添加空间锚组件后推荐立刻使用初始的isLocated状态去调用 OnTrackingChanged 事件
// attachingAnchor.OnTrackingChanged += AttachingAnchor_OnTrackingChanged;
// }
// }
// else
// {
// //当全息对象已附加空间锚组件后,不能被移动,如果需要移动全息对象:
// //立刻销毁空间锚组件
// //移动全息对象
// //添加一个新的空间锚到全息对象上
// WorldAnchor anchor = gameObject.GetComponent<WorldAnchor>();
// if (anchor != null)
// {
// DestroyImmediate(anchor);
// }
// string[] ids = anchorStore.GetAllIds();
// for (int i = 0; i < ids.Length; i++)
// {
// if (ids[i] == ObjectAnchorStoreName)
// {
// bool deleted = anchorStore.Delete(ids[i]);
// break;
// }
// }
// }
//}
//public void OnManipulationStarted(ManipulationEventData eventData)
//{
// Debug.Log("OnManipulationStarted");
// HasMove = true;
//}
//public void OnManipulationEnded(ManipulationEventData eventData)
//{
// Debug.Log("OnManipulationEnded");
// HasMove = false;
//}
}