/// <summary> /// Adjust the game object's scale of the ArUco object according to its MarkerSideLength property. /// </summary> /// <param name="arucoObject"></param> protected override void ArucoObject_PropertyUpdated(ArucoObject arucoObject) { base.ArucoObject_PropertyUpdated(arucoObject); if (arucoObject.GetType() == typeof(ArucoMarker)) { MarkerTracker.AdjustGameObjectScale(arucoObject); } else { additionalTrackers[arucoObject.GetType()].AdjustGameObjectScale(arucoObject); } }
// 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); } } }
// ArucoObjectController methods /// <summary> /// Suscribe to the property events of an ArUco object, and hide its gameObject since it has not been detected yet. /// </summary> /// <param name="arucoObject">The new ArUco object to suscribe.</param> protected virtual void ArucoObjectController_ArucoObjectAdded(ArucoObject arucoObject) { ArucoObjectTracker tracker = null; if (arucoObject.GetType() != typeof(ArucoMarker) && !additionalTrackers.TryGetValue(arucoObject.GetType(), out tracker)) { Debug.LogError("No tracker found for the type '" + arucoObject.GetType() + "'. Removing the object '" + arucoObject.gameObject.name + "' from the tracking list."); Remove(arucoObject); return; } if (tracker != null && !tracker.IsActivated) { tracker.Activate(this); } arucoObject.gameObject.SetActive(false); }
/// <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(); } } }
// ArucoObjectController methods /// <summary> /// Activate 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)) { return; } // Activate the tracker if necessary ArucoObjectTracker tracker = null; if (!additionalTrackers.TryGetValue(arucoObject.GetType(), out tracker)) { throw new System.ArgumentException("No tracker found for the type '" + arucoObject.GetType() + "'.", "arucoObject"); } else if (!tracker.IsActivated) { tracker.Activate(this); } // Configure the game object AdjustGameObjectScale(arucoObject); arucoObject.gameObject.SetActive(false); }