private void CreateVirtualButtonsFromNative()
        {
            int num = VuforiaWrapper.Instance.ImageTargetGetNumVirtualButtons(this.mDataSet.DataSetPtr, base.Name);

            if (num > 0)
            {
                IntPtr intPtr  = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(VuforiaManagerImpl.VirtualButtonData)) * num);
                IntPtr intPtr2 = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(RectangleData)) * num);
                VuforiaWrapper.Instance.ImageTargetGetVirtualButtons(intPtr, intPtr2, num, this.mDataSet.DataSetPtr, base.Name);
                for (int i = 0; i < num; i++)
                {
                    VuforiaManagerImpl.VirtualButtonData virtualButtonData = (VuforiaManagerImpl.VirtualButtonData)Marshal.PtrToStructure(new IntPtr(intPtr.ToInt64() + (long)(i * Marshal.SizeOf(typeof(VuforiaManagerImpl.VirtualButtonData)))), typeof(VuforiaManagerImpl.VirtualButtonData));
                    if (!this.mVirtualButtons.ContainsKey(virtualButtonData.id))
                    {
                        RectangleData area          = (RectangleData)Marshal.PtrToStructure(new IntPtr(intPtr2.ToInt64() + (long)(i * Marshal.SizeOf(typeof(RectangleData)))), typeof(RectangleData));
                        int           num2          = 128;
                        StringBuilder stringBuilder = new StringBuilder(num2);
                        if (VuforiaWrapper.Instance.ImageTargetGetVirtualButtonName(this.mDataSet.DataSetPtr, base.Name, i, stringBuilder, num2) == 0)
                        {
                            Debug.LogError("Failed to get virtual button name.");
                        }
                        else
                        {
                            VirtualButton value = new VirtualButtonImpl(stringBuilder.ToString(), virtualButtonData.id, area, this, this.mDataSet);
                            this.mVirtualButtons.Add(virtualButtonData.id, value);
                        }
                    }
                }
                Marshal.FreeHGlobal(intPtr);
                Marshal.FreeHGlobal(intPtr2);
            }
        }
Exemple #2
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);
                }
            }
        }