Example #1
0
 private void OnDestroy()
 {
     if (Application.isPlaying && this.mUnregisterOnDestroy)
     {
         ImageTargetAbstractBehaviour imageTargetBehaviour = this.GetImageTargetBehaviour();
         if (imageTargetBehaviour != null)
         {
             imageTargetBehaviour.ImageTarget.DestroyVirtualButton(this.mVirtualButton);
         }
     }
 }
Example #2
0
        public bool UpdatePose()
        {
            ImageTargetAbstractBehaviour imageTargetBehaviour = this.GetImageTargetBehaviour();

            if (imageTargetBehaviour == null)
            {
                return(false);
            }
            Transform parent = base.transform.parent;

            while (parent != null)
            {
                if (parent.localScale[0] != parent.localScale[1] || parent.localScale[0] != parent.localScale[2])
                {
                    Debug.LogWarning("Detected non-uniform scale in virtual  button object hierarchy. Forcing uniform scaling of object '" + parent.name + "'.");
                    parent.localScale = new Vector3(parent.localScale[0], parent.localScale[0], parent.localScale[0]);
                }
                parent = parent.parent;
            }
            this.mHasUpdatedPose = true;
            if (base.transform.parent != null && base.transform.parent.gameObject != imageTargetBehaviour.gameObject)
            {
                base.transform.localPosition = Vector3.zero;
            }
            Vector3 vector = imageTargetBehaviour.transform.InverseTransformPoint(base.transform.position);

            vector.y = 0.001f;
            Vector3 position = imageTargetBehaviour.transform.TransformPoint(vector);

            base.transform.position = position;
            base.transform.rotation = imageTargetBehaviour.transform.rotation;
            Vector2 vec;
            Vector2 vec2;

            this.CalculateButtonArea(out vec, out vec2);
            float threshold = imageTargetBehaviour.transform.localScale[0] * 0.001f;

            if (!VirtualButtonAbstractBehaviour.Equals(vec, this.mLeftTop, threshold) || !VirtualButtonAbstractBehaviour.Equals(vec2, this.mRightBottom, threshold))
            {
                this.mLeftTop     = vec;
                this.mRightBottom = vec2;
                return(true);
            }
            return(false);
        }
Example #3
0
        public bool SetPosAndScaleFromButtonArea(Vector2 topLeft, Vector2 bottomRight)
        {
            ImageTargetAbstractBehaviour imageTargetBehaviour = this.GetImageTargetBehaviour();

            if (imageTargetBehaviour == null)
            {
                return(false);
            }
            float   num     = imageTargetBehaviour.transform.lossyScale[0];
            Vector2 vector  = (topLeft + bottomRight) * 0.5f;
            Vector2 vector2 = new Vector2(bottomRight[0] - topLeft[0], topLeft[1] - bottomRight[1]);
            Vector3 vector3 = new Vector3(vector[0] / num, 0.001f, vector[1] / num);
            Vector3 vector4 = new Vector3(vector2[0], (vector2[0] + vector2[1]) * 0.5f, vector2[1]);

            base.transform.position   = imageTargetBehaviour.transform.TransformPoint(vector3);
            base.transform.localScale = vector4 / base.transform.parent.lossyScale[0];
            return(true);
        }
Example #4
0
        public bool CalculateButtonArea(out Vector2 topLeft, out Vector2 bottomRight)
        {
            ImageTargetAbstractBehaviour imageTargetBehaviour = this.GetImageTargetBehaviour();

            if (imageTargetBehaviour == null)
            {
                topLeft = (bottomRight = Vector2.zero);
                return(false);
            }
            Vector3 vector  = imageTargetBehaviour.transform.InverseTransformPoint(base.transform.position);
            float   num     = imageTargetBehaviour.transform.lossyScale[0];
            Vector2 vector2 = new Vector2(vector[0] * num, vector[2] * num);
            Vector2 vector3 = Vector2.Scale(new Vector2(base.transform.lossyScale[0], base.transform.lossyScale[2]) * 0.5f, new Vector2(1f, -1f));

            topLeft     = vector2 - vector3;
            bottomRight = vector2 + vector3;
            return(true);
        }
Example #5
0
        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);
        }
Example #6
0
 private void CreateMissingDataSetTrackableBehaviours(DataSet dataSet)
 {
     foreach (Trackable current in dataSet.GetTrackables())
     {
         if (!this.mTrackableBehaviours.ContainsKey(current.ID))
         {
             if (current is ImageTarget)
             {
                 ImageTargetAbstractBehaviour imageTargetAbstractBehaviour = this.CreateImageTargetBehaviour((ImageTarget)current);
                 imageTargetAbstractBehaviour.CreateMissingVirtualButtonBehaviours();
                 this.mTrackableBehaviours[current.ID] = imageTargetAbstractBehaviour;
                 this.mAutomaticallyCreatedBehaviours.Add(current.ID);
             }
             else if (current is MultiTarget)
             {
                 MultiTargetAbstractBehaviour value = this.CreateMultiTargetBehaviour((MultiTarget)current);
                 this.mTrackableBehaviours[current.ID] = value;
                 this.mAutomaticallyCreatedBehaviours.Add(current.ID);
             }
             else if (current is CylinderTarget)
             {
                 CylinderTargetAbstractBehaviour value2 = this.CreateCylinderTargetBehaviour((CylinderTarget)current);
                 this.mTrackableBehaviours[current.ID] = value2;
                 this.mAutomaticallyCreatedBehaviours.Add(current.ID);
             }
             else if (current is VuMarkTemplate)
             {
                 if (!this.mVuMarkManager.ContainsVuMarkTemplate(current.ID))
                 {
                     VuMarkAbstractBehaviour behaviour = this.CreateVuMarkBehaviour((VuMarkTemplate)current);
                     this.mVuMarkManager.AddTemplateBehaviour(behaviour);
                 }
             }
             else if (current is ObjectTarget)
             {
                 DataSetTrackableBehaviour value3 = this.CreateObjectTargetBehaviour((ObjectTarget)current);
                 this.mTrackableBehaviours[current.ID] = value3;
                 this.mAutomaticallyCreatedBehaviours.Add(current.ID);
             }
         }
     }
 }
Example #7
0
        internal void UpdateVirtualButtons(int numVirtualButtons, IntPtr virtualButtonPtr)
        {
            Dictionary <int, VuforiaManagerImpl.VirtualButtonData> dictionary = new Dictionary <int, VuforiaManagerImpl.VirtualButtonData>();

            for (int i = 0; i < numVirtualButtons; i++)
            {
                VuforiaManagerImpl.VirtualButtonData virtualButtonData = (VuforiaManagerImpl.VirtualButtonData)Marshal.PtrToStructure(new IntPtr(virtualButtonPtr.ToInt64() + (long)(i * Marshal.SizeOf(typeof(VuforiaManagerImpl.VirtualButtonData)))), typeof(VuforiaManagerImpl.VirtualButtonData));
                dictionary.Add(virtualButtonData.id, virtualButtonData);
            }
            List <VirtualButtonAbstractBehaviour> list = new List <VirtualButtonAbstractBehaviour>();

            using (Dictionary <int, TrackableBehaviour> .ValueCollection.Enumerator enumerator = this.mTrackableBehaviours.Values.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    ImageTargetAbstractBehaviour imageTargetAbstractBehaviour = enumerator.Current as ImageTargetAbstractBehaviour;
                    if (imageTargetAbstractBehaviour != null && imageTargetAbstractBehaviour.enabled)
                    {
                        foreach (VirtualButtonAbstractBehaviour current in imageTargetAbstractBehaviour.GetVirtualButtonBehaviours())
                        {
                            if (current.enabled)
                            {
                                list.Add(current);
                            }
                        }
                    }
                }
            }
            foreach (VirtualButtonAbstractBehaviour current2 in list)
            {
                VuforiaManagerImpl.VirtualButtonData virtualButtonData2;
                if (dictionary.TryGetValue(current2.VirtualButton.ID, out virtualButtonData2))
                {
                    current2.OnTrackerUpdated(virtualButtonData2.isPressed > 0);
                }
                else
                {
                    current2.OnTrackerUpdated(false);
                }
            }
        }
Example #8
0
        private ImageTargetAbstractBehaviour CreateImageTargetBehaviour(ImageTarget imageTarget)
        {
            GameObject gameObject = new GameObject();
            ImageTargetAbstractBehaviour imageTargetAbstractBehaviour = BehaviourComponentFactory.Instance.AddImageTargetBehaviour(gameObject);

            Debug.Log(string.Concat(new object[]
            {
                "Creating Image Target with values: \n ID:           ",
                imageTarget.ID,
                "\n Name:         ",
                imageTarget.Name,
                "\n Path:         ",
                ((ImageTargetImpl)imageTarget).DataSet.Path,
                "\n Size:         ",
                imageTarget.GetSize().x,
                "x",
                imageTarget.GetSize().y
            }));
            imageTargetAbstractBehaviour.InitializeTarget(imageTarget, true);
            return(imageTargetAbstractBehaviour);
        }
        public static VirtualButtonAbstractBehaviour CreateVirtualButton(string vbName, Vector2 localScale, GameObject immediateParent)
        {
            GameObject gameObject = new GameObject(vbName);
            VirtualButtonAbstractBehaviour virtualButtonAbstractBehaviour = BehaviourComponentFactory.Instance.AddVirtualButtonBehaviour(gameObject);
            ImageTargetAbstractBehaviour   componentInChildren            = immediateParent.transform.root.gameObject.GetComponentInChildren <ImageTargetAbstractBehaviour>();

            if (componentInChildren == null || componentInChildren.ImageTarget == null)
            {
                Debug.LogError("Could not create Virtual Button. immediateParent\"immediateParent\" object is not an Image Target or a child of one.");
                UnityEngine.Object.Destroy(gameObject);
                return(null);
            }
            gameObject.transform.parent = immediateParent.transform;
            virtualButtonAbstractBehaviour.SetVirtualButtonName(vbName);
            virtualButtonAbstractBehaviour.transform.localScale = new Vector3(localScale[0], 1f, localScale[1]);
            if (Application.isPlaying && !componentInChildren.CreateNewVirtualButtonFromBehaviour(virtualButtonAbstractBehaviour))
            {
                return(null);
            }
            virtualButtonAbstractBehaviour.UnregisterOnDestroy = true;
            return(virtualButtonAbstractBehaviour);
        }
Example #10
0
        public ImageTargetAbstractBehaviour GetImageTargetBehaviour()
        {
            if (base.transform.parent == null)
            {
                return(null);
            }
            GameObject gameObject = base.transform.parent.gameObject;

            while (gameObject != null)
            {
                ImageTargetAbstractBehaviour component = gameObject.GetComponent <ImageTargetAbstractBehaviour>();
                if (component != null)
                {
                    return(component);
                }
                if (gameObject.transform.parent == null)
                {
                    return(null);
                }
                gameObject = gameObject.transform.parent.gameObject;
            }
            return(null);
        }
Example #11
0
 private void AssociateVirtualButtonBehaviours(VirtualButtonAbstractBehaviour[] vbBehaviours, DataSet dataSet)
 {
     for (int i = 0; i < vbBehaviours.Length; i++)
     {
         VirtualButtonAbstractBehaviour virtualButtonAbstractBehaviour = vbBehaviours[i];
         if (virtualButtonAbstractBehaviour.VirtualButtonName == null)
         {
             Debug.LogError("VirtualButton at " + i + " has no name.");
         }
         else
         {
             ImageTargetAbstractBehaviour imageTargetBehaviour = virtualButtonAbstractBehaviour.GetImageTargetBehaviour();
             if (imageTargetBehaviour == null)
             {
                 Debug.LogError("VirtualButton named " + virtualButtonAbstractBehaviour.VirtualButtonName + " is not attached to an ImageTarget.");
             }
             else if (dataSet.Contains(imageTargetBehaviour.Trackable))
             {
                 imageTargetBehaviour.AssociateExistingVirtualButtonBehaviour(virtualButtonAbstractBehaviour);
             }
         }
     }
 }