Пример #1
0
            // ArucoObjectController methods

            /// <summary>
            /// Activates the tracker associated with the <paramref name="arucoObject"/> and configure its gameObject.
            /// </summary>
            /// <param name="arucoObject">The added ArUco object.</param>
            protected virtual void ArucoObjectsController_ArucoObjectAdded(ArucoObject arucoObject)
            {
                if (arucoObject.GetType() != typeof(ArucoMarker))
                {
                    ArucoObjectTracker tracker = null;
                    if (!additionalTrackers.TryGetValue(arucoObject.GetType(), out tracker))
                    {
                        throw new ArgumentException("No tracker found for the type '" + arucoObject.GetType() + "'.", "arucoObject");
                    }
                    else if (!tracker.IsActivated)
                    {
                        tracker.Activate(this);
                    }
                }
            }
        /// <summary>
        ///     Deactivates the tracker associated with the <paramref name="arucoObject" /> if it was the last one of this type.
        /// </summary>
        /// <param name="arucoObject">The removed</param>
        protected virtual void ArucoObjectsController_ArucoObjectRemoved(ArucoObject arucoObject)
        {
            ArucoObjectTracker tracker = null;

            if (arucoObject.GetType() == typeof(ArucoMarker) ||
                !additionalTrackers.TryGetValue(arucoObject.GetType(), out tracker))
            {
                return;
            }

            if (tracker.IsActivated)
            {
                var deactivateTracker = true;

                // Try to find at leat one object of the same type as arucoObject
                foreach (var arucoObjectDictionary in ArucoObjects)
                {
                    foreach (var arucoObject2 in arucoObjectDictionary.Value)
                    {
                        if (arucoObject2.GetType() == arucoObject.GetType())
                        {
                            deactivateTracker = false;
                            break;
                        }
                    }

                    if (!deactivateTracker)
                    {
                        break;
                    }
                }

                if (deactivateTracker)
                {
                    tracker.Deactivate();
                }
            }
        }