/// <summary>
        /// Setup the Tracking UI.
        /// After the setup, this script is destroyed.
        /// </summary>
        public void Setup()
        {
            // Load Prefab
            if (_loadedObject == null)
            {
                var loadedPrefab = Resources.Load(_prefabPath) as GameObject;
                if (loadedPrefab == null)
                {
                    Debug.LogErrorFormat("Could not load Prefab: {0}", _prefabPath);
                    return;
                }
                _loadedObject = loadedPrefab.GetComponent <BaseSlamTrackingCanvasConfigurer>();
            }

            // Attach Controller
            var controller = gameObject.AddComponent <SlamTrackingUIController>();

            // Set Prefab
            controller.Prefab = _loadedObject;

            // Listen to Slam
            var localizer = gameObject.GetComponent <SlamLocalizer>();

            controller.ListenToSlamLocalizer(localizer);

            // Destroy
            if (Application.isEditor && !Application.isPlaying)
            {
                DestroyImmediate(this);
            }
            else
            {
                Destroy(this);
            }
        }
Exemple #2
0
 /// <summary>
 /// Executed when Slam Tracking is lost
 /// </summary>
 private void OnSlamTrackingLost()
 {
     // Create UI
     if (_prefabInstance == null)
     {
         if (_prefab == null)
         {
             Debug.LogError("Prefab is null, cannot instantiate UI");
             return;
         }
         _prefabInstance = Instantiate(_prefab);
         _prefabInstance.AutoConfigure();
     }
 }
        /// <summary>
        /// Executed when Slam Tracking is lost
        /// </summary>
        private void OnSlamTrackingLost()
        {
            if (_prefabInstance)
            {
                Destroy(_prefabInstance.gameObject);
                _prefabInstance = null;
            }

            if (_prefab == null)
            {
                Debug.LogError("Prefab is null, cannot instantiate UI");
                return;
            }
            _prefabInstance = Instantiate(_prefab);
            _prefabInstance.AutoConfigure();
        }
Exemple #4
0
        /// <summary>
        /// Executed when Slam tracking is recovered
        /// </summary>
        private void OnSlamTrackingRecovered()
        {
            // Destroy UI
            if (_prefabInstance != null)
            {
                var messageController = _prefabInstance.GetComponentInChildren <BaseSlamTrackingMessageController>();
                if (messageController == null)
                {
                    Debug.LogWarning("Instance does not contain SlamTrackingMessageController. Destroying instance.");
                    Destroy(_prefabInstance.gameObject);
                    return;
                }

                // Hide and then destroy
                messageController.Hide(() =>
                {
                    Destroy(_prefabInstance.gameObject);
                    _prefabInstance = null;
                });
            }
        }