123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using UnityEngine.XR.ARFoundation;
- public class ImageLibraryTest : MonoBehaviour
- {
- [SerializeField]
- private Text text;
- [SerializeField]
- private Text text2;
- [SerializeField]
- private ARTrackedImageManager imagerManager;
- [SerializeField]
- private List<ARTrackedImage> listARTrackedImage;
- [SerializeField]
- private bool state = false;
- private ARTrackedImage oldTrackedImage;
- public void Start()
- {
- listARTrackedImage = new List<ARTrackedImage>();
- oldTrackedImage = null;
- text.text = "打开识别图管理 ";
-
- }
- private void Update()
- {
- text2.text = imagerManager.trackables.count.ToString();
- if (oldTrackedImage != null && oldTrackedImage.trackingState != UnityEngine.XR.ARSubsystems.TrackingState.Tracking)
- {
- // 离开识别图
- Debug.Log(" Lost " + oldTrackedImage.name);
- VuforialControl.Instance.TrackingLost(int.Parse(oldTrackedImage.referenceImage.name));
- oldTrackedImage = null;
- }
- foreach (var trackedImage in imagerManager.trackables)
- {
- Debug.Log($"Image: {trackedImage.referenceImage.name} is at " +
- $"{trackedImage.transform.position}" + $" {trackedImage.trackingState.ToString()} ");
- if (!listARTrackedImage.Contains(trackedImage))
- listARTrackedImage.Add(trackedImage);
- if (trackedImage.trackingState == UnityEngine.XR.ARSubsystems.TrackingState.Tracking)
- {
- Debug.Log(" This is " + trackedImage.referenceImage.name);
- text.text = " This is " + trackedImage.referenceImage.name;
- if (oldTrackedImage != trackedImage)
- {
- oldTrackedImage = trackedImage;
- VuforialControl.Instance.TrackingFound(oldTrackedImage.transform, int.Parse(oldTrackedImage.referenceImage.name), 0);
- }
- }
- }
- if (listARTrackedImage.Count < 1)
- {
- return;
- }
- }
- }
|