private bool CreateImageTargets() { int num = VuforiaWrapper.Instance.DataSetGetNumTrackableType((int)TypeMapping.GetTypeID(typeof(ImageTarget)), this.mDataSetPtr); if (num <= 0) { return(false); } IntPtr intPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(ImageTargetData)) * num); if (VuforiaWrapper.Instance.DataSetGetTrackablesOfType((int)TypeMapping.GetTypeID(typeof(ImageTarget)), intPtr, num, this.mDataSetPtr) == 0) { Debug.LogError("Could not create Image Targets"); return(false); } for (int i = 0; i < num; i++) { ImageTargetData imageTargetData = (ImageTargetData)Marshal.PtrToStructure(new IntPtr(intPtr.ToInt64() + (long)(i * Marshal.SizeOf(typeof(ImageTargetData)))), typeof(ImageTargetData)); if (!this.mTrackablesDict.ContainsKey(imageTargetData.id)) { StringBuilder stringBuilder = new StringBuilder(128); VuforiaWrapper.Instance.DataSetGetTrackableName(this.mDataSetPtr, imageTargetData.id, stringBuilder, 128); ImageTarget value = new ImageTargetImpl(stringBuilder.ToString(), imageTargetData.id, ImageTargetType.PREDEFINED, this); this.mTrackablesDict[imageTargetData.id] = value; } } Marshal.FreeHGlobal(intPtr); return(true); }
public override ImageTargetAbstractBehaviour EnableTracking(TargetFinder.TargetSearchResult result, GameObject gameObject) { IntPtr intPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(ImageTargetData))); int num = VuforiaWrapper.Instance.TargetFinderEnableTracking(result.TargetSearchResultPtr, intPtr); ImageTargetData imageTargetData = (ImageTargetData)Marshal.PtrToStructure(intPtr, typeof(ImageTargetData)); Marshal.FreeHGlobal(intPtr); StateManagerImpl stateManagerImpl = (StateManagerImpl)TrackerManager.Instance.GetStateManager(); ImageTargetAbstractBehaviour result2 = null; if (imageTargetData.id == -1) { Debug.LogError("TargetSearchResult " + result.TargetName + " could not be enabled for tracking."); } else { ImageTarget imageTarget = new CloudRecoImageTargetImpl(result.TargetName, imageTargetData.id, imageTargetData.size); this.mImageTargets[imageTargetData.id] = imageTarget; result2 = stateManagerImpl.FindOrCreateImageTargetBehaviourForTrackable(imageTarget, gameObject); } IntPtr intPtr2 = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(int)) * num); VuforiaWrapper.Instance.TargetFinderGetImageTargets(intPtr2, num); List <int> list = new List <int>(); for (int i = 0; i < num; i++) { int item = Marshal.ReadInt32(new IntPtr(intPtr2.ToInt64() + (long)(i * Marshal.SizeOf(typeof(int))))); list.Add(item); } Marshal.FreeHGlobal(intPtr2); ImageTarget[] array = this.mImageTargets.Values.ToArray <ImageTarget>(); for (int j = 0; j < array.Length; j++) { ImageTarget imageTarget2 = array[j]; if (!list.Contains(imageTarget2.ID)) { stateManagerImpl.DestroyTrackableBehavioursForTrackable(imageTarget2, true); this.mImageTargets.Remove(imageTarget2.ID); } } return(result2); }