/// <summary>
        /// Creates an Image Target based on the provided parameters.
        /// </summary>
        /// <param name="name">The name to give the Image Target.</param>
        /// <param name="image">The image that represents the target.</param>
        /// <param name="width">The width of the Image Target.</param>
        /// <param name="callback">The callback to use for any status updates of the new Image Target.</param>
        /// <param name="isStationary">Set this to true if the position of this Image Target in the physical world is fixed and the local geometry is planar.</param>
        /// <returns>The newly created Image Target.</returns>
        private Target CreateTarget(string name, Texture2D image, float width, MLImageTracker.Target.OnImageResultDelegate callback, bool isStationary)
        {
            if (string.IsNullOrEmpty(name))
            {
                MLPluginLog.Error("MLImageTracker.CreateTarget failed to add MLImageTracker.Target to ImageTracker. Reason: The unique name provided is null or empty.");
                return(null);
            }

            if (image == null)
            {
                MLPluginLog.ErrorFormat("MLImageTracker.CreateTarget failed to add MLImageTracker.Target \"{0}\" to ImageTracker. Reason: The Texture2D image provided is null.", name);
                return(null);
            }

            if (callback == null)
            {
                MLPluginLog.ErrorFormat("MLImageTracker.CreateTarget failed to add MLImageTracker.Target \"{0}\" to ImageTracker. Reason: The callback function provided is null.", name);
                return(null);
            }

            // Check to see if a version of this image is already tracked.
            // Currently this only checks for unique names.
            if (this.targetList.FindIndex((Target target) => target.TargetSettings.Name.Equals(name)) > -1)
            {
                MLPluginLog.ErrorFormat("MLImageTracker.CreateTarget failed to add MLImageTracker.Target \"{0}\" to ImageTracker. Reason: A target with the same name is already added to this tracker.", name);
                return(null);
            }

            return(new Target(name, image, width, callback, this.handle, isStationary));
        }
        /// <summary>
        // Adds an image target to be tracked.
        /// </summary>
        public static MLImageTargetStarterKit AddTarget(string id, Texture2D texture, float longerDimension, MLImageTracker.Target.OnImageResultDelegate callback, bool isStationary = false)
        {
            MLImageTargetStarterKit newTargetStarterKit = new MLImageTargetStarterKit();

            callback += newTargetStarterKit.HandleStatusUpdates;

            MLImageTracker.Target newTarget = MLImageTracker.AddTarget(id, texture, longerDimension, callback, isStationary);

            if (newTarget == null)
            {
                Debug.LogErrorFormat("MLImageTrackerStarterKit.AddTarget was unable to create the new image target with id: {0}.", id);
                return(null);
            }

            newTargetStarterKit.InitializeWithTarget(newTarget);
            return(newTargetStarterKit);
        }
        /// <summary>
        /// Internal call used to add an Image Target with the provided parameters to the Image Tracker.
        /// </summary>
        /// <param name="name">The name to give the Image Target.</param>
        /// <param name="image">The image that represents the target.</param>
        /// <param name="longerDimension">Size of the longer dimension in scene units.</param>
        /// <param name="callback">The callback to use for any status updates of the new Image Target.</param>
        /// <param name="isStationary">Set this to true if the position of this Image Target in the physical world is fixed and the local geometry is planar.</param>
        /// <returns>The newly created Image Target.</returns>
        private Target AddTargetInternal(string name, Texture2D image, float longerDimension, MLImageTracker.Target.OnImageResultDelegate callback, bool isStationary = false)
        {
            Target newTarget = this.CreateTarget(name, image, longerDimension, callback, isStationary);

            if (newTarget == null)
            {
                MLPluginLog.ErrorFormat("MLImageTracker.AddTargetInternal failed to add MLImageTarget \"{0}\" to ImageTracker. Tracker Handle: {1}", name, this.handle);
                return(null);
            }

            if (!newTarget.IsValid)
            {
                MLPluginLog.ErrorFormat("MLImageTracker.AddTargetInternal failed to add MLImageTracker.Target \"{0}\" to ImageTracker. Tracker Handle: {1}", name, this.handle);
                newTarget.Dispose();
                return(null);
            }

            this.targetList.Add(newTarget);
            return(newTarget);
        }
 /// <summary>
 /// Adds an Image Target to the image tracker system.
 /// </summary>
 /// <param name="name">The unique name of this target.</param>
 /// <param name="image">
 /// Texture2D representing the Image Target.
 /// The aspect ration of the target should not be changed. Set the "Non Power of 2" property of Texture2D to none.
 /// </param>
 /// <param name="longerDimension">Size of the longer dimension in scene units.</param>
 /// <param name="callback">The function that will be triggered with target info.</param>
 /// <param name="isStationary">
 /// Set this to true if the position of this Image Target in the physical world is fixed and the local
 /// geometry is planar.
 /// </param>
 /// <returns>MLImageTracker.Target if the target was created and added successfully, null otherwise.</returns>
 public static Target AddTarget(string name, Texture2D image, float longerDimension, MLImageTracker.Target.OnImageResultDelegate callback, bool isStationary = false)
 {
     return(Instance.AddTargetInternal(name, image, longerDimension, callback, isStationary));
 }