// Registers a Virtual Button at native code. This method is called
    // implicitly by the ImageTargetBehaviour.CreateVirtualButton method. This
    // method should not be called by user code.
    public bool RegisterVirtualButton(VirtualButtonBehaviour vb,
        string imageTargetName)
    {
        TrackerBehaviour.RectangleData rectData =
                new TrackerBehaviour.RectangleData();

        Vector2 leftTop, rightBottom;
        vb.CalculateButtonArea(out leftTop, out rightBottom);
        rectData.leftTopX = leftTop.x;
        rectData.leftTopY = leftTop.y;
        rectData.rightBottomX = rightBottom.x;
        rectData.rightBottomY = rightBottom.y;

        IntPtr rectPtr = Marshal.AllocHGlobal(
            Marshal.SizeOf(typeof(TrackerBehaviour.RectangleData)));
        Marshal.StructureToPtr(rectData, rectPtr, false);

        bool registerWorked =
            (createVirtualButton(imageTargetName, vb.VirtualButtonName,
                                    rectPtr) != 0);

        if (registerWorked)
        {
            int id = virtualButtonGetId(imageTargetName, vb.VirtualButtonName);

            // Initialize the id of the button:
            vb.InitializeID(id);

            // Check we don't have an entry for this id:
            if (!mVBBehaviourDict.ContainsKey(id))
            {
                // Add:
                mVBBehaviourDict.Add(id, vb);
                mVBDataArrayDirty = true;
            }
        }

        return registerWorked;
    }
    public void LateUpdate()
    {
        // Update the button pose:
        if (UpdatePose())
        {
            // Area has changed, update the QCAR trackable:
            string trackableName = this.GetImageTarget().TrackableName;
            TrackerBehaviour.RectangleData rectData =
                new TrackerBehaviour.RectangleData();

            rectData.leftTopX = mLeftTop.x;
            rectData.leftTopY = mLeftTop.y;
            rectData.rightBottomX = mRightBottom.x;
            rectData.rightBottomY = mRightBottom.y;

            IntPtr rectPtr = Marshal.AllocHGlobal(Marshal.SizeOf(
                                    typeof(TrackerBehaviour.RectangleData)));
            Marshal.StructureToPtr(rectData, rectPtr, false);
            virtualButtonSetAreaRectangle(trackableName, this.VirtualButtonName,
                                            rectPtr);
            Marshal.FreeHGlobal(rectPtr);
        }

        // Update the sensitivity of the button if it has changed since the
        // last update:
        if (mSensitivityDirty)
        {
            ImageTargetBehaviour itb = this.GetImageTarget();
            if (virtualButtonSetSensitivity(itb.TrackableName,
                                            this.VirtualButtonName,
                                            (int)mSensitivity) == 0)
            {
                Debug.LogError("Virtual Button sensitivity could not be set.");
            }
            else
            {
                mSensitivityDirty = false;
            }
        }
    }