Example #1
0
        /// <summary>
        /// Register's a target and its events for the aggregated events issued by TrackerKeeper.
        /// </summary>
        /// <param name="target">Target.</param>
        public AbstractTrackableFoundEventHandler Register(AbstractTrackableFoundEventHandler target)
        {
            if (targets?.Contains(target) == false)
            {
                targets.Add(target);
                target.onFound.AddListener(TargetFinder(target));
                target.onLost.AddListener(TargetLoser(target));
                target.onProximity.AddListener(TargetProximity(target));
                target.onSafe.AddListener(TargetSafe(target));
            }

            return(target);
        }
Example #2
0
        /// <summary>
        /// Creates an event handler that can handle losing a given target. The event handler will
        /// fire the targetChanged event if the lost target was the <see cref="CurrentTarget"/>. If
        /// losing this target means that there are no tracked targets, then the <see
        /// cref="onAllTargetsLost"/> event is fired. Finally, Vuforia's Persistent Extended Tracking
        /// is reset, if it was active.
        /// </summary>
        /// <returns>The loser.</returns>
        /// <param name="target">Target.</param>
        private UnityAction TargetLoser(AbstractTrackableFoundEventHandler target)
        {
            return(() =>
            {
                onTargetLost?.Invoke(target.transform);

                if (!HasTargets && hadAnyTargets)
                {
                    hadAnyTargets = HasTargets;
                    if (!done)
                    {
                        Invoke(nameof(OnAllTargetsLost), 1);
                    }
                }
            });
        }
Example #3
0
        /// <summary>
        /// Creates an event handler that can handle finding a given target.
        /// </summary>
        /// <returns>The finder.</returns>
        /// <param name="target">Target.</param>
        private UnityAction TargetFinder(AbstractTrackableFoundEventHandler target)
        {
            return(() =>
            {
                CancelInvoke(nameof(OnAllTargetsLost));

                if (HasTargets && !hadAnyTargets && Tracking)
                {
                    onAnyTargetFound?.Invoke();
                }

                onTargetFound?.Invoke(target.transform);

                foreach (var otherTarget in targets)
                {
                    if (otherTarget != target && otherTarget.Found)
                    {
                        otherTarget.ForceLost();
                    }
                }

                hadAnyTargets = HasTargets;
            });
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="T:Juniper.XR.TrackingStateChangeEventArgs"/> class.
 /// </summary>
 /// <param name="src">     Source.</param>
 /// <param name="tracking">If set to <c>true</c> tracking.</param>
 public TrackingStateChangeEventArgs(AbstractTrackableFoundEventHandler src, bool tracking)
 {
     Source   = src;
     Tracking = tracking;
 }
Example #5
0
 /// <summary>
 /// Creates an event handler that can handle finding a given target.
 /// </summary>
 /// <returns>The finder.</returns>
 /// <param name="target">Target.</param>
 private UnityAction TargetSafe(AbstractTrackableFoundEventHandler target)
 {
     return(() => onTargetSafe.Invoke(target.transform));
 }