Example #1
0
    private bool CreateNewVirtualButtonFromBehaviour(VirtualButtonBehaviour newVBB)
    {
        // Calculate the button area:
        Vector2 leftTop, rightBottom;

        newVBB.CalculateButtonArea(out leftTop, out rightBottom);
        RectangleData area = new RectangleData
        {
            leftTopX     = leftTop.x,
            leftTopY     = leftTop.y,
            rightBottomX = rightBottom.x,
            rightBottomY = rightBottom.y
        };

        VirtualButton virtualButton = mImageTarget.CreateVirtualButton(newVBB.VirtualButtonName, area);

        if (virtualButton == null)
        {
            Destroy(newVBB.gameObject);
            return(false);
        }

        IEditorVirtualButtonBehaviour newEditorVBB = newVBB;

        newEditorVBB.InitializeVirtualButton(virtualButton);
        mVirtualButtonBehaviours.Add(virtualButton.ID, newVBB);
        return(true);
    }
Example #2
0
    // 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)
    {
        VirtualButtonBehaviour.RectangleData rectData =
            new VirtualButtonBehaviour.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(VirtualButtonBehaviour.RectangleData)));

        Marshal.StructureToPtr(rectData, rectPtr, false);

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

        if (registerWorked)
        {
            int id = virtualButtonGetId(DataSetPtr, 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);
            }
        }

        return(registerWorked);
    }
Example #3
0
    public void OnButtonPressed(VirtualButtonBehaviour vb)
    {
        Vector2 topLeftPos     = Vector2.zero;
        Vector2 bottomRightPos = Vector2.zero;

        //this.abominationCopy.SetActive (true);

        if (vb.CalculateButtonArea(out topLeftPos, out bottomRightPos))
        {
            GameObject abomination = GameObject.Instantiate <GameObject> (this.abominationCopy, this.transform);
            abomination.SetActive(true);
            Vector3 placement = this.abominationCopy.transform.localPosition;
            placement.x = topLeftPos.x;
            placement.z = topLeftPos.y;

            abomination.transform.localPosition = placement;

            Debug.Log("Placed object!");
        }
        else
        {
            Debug.LogError("Calculate button area failed!");
        }
    }
Example #4
0
    // 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)
    {
        VirtualButtonBehaviour.RectangleData rectData =
                new VirtualButtonBehaviour.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(VirtualButtonBehaviour.RectangleData)));
        Marshal.StructureToPtr(rectData, rectPtr, false);

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

        if (registerWorked)
        {
            int id = virtualButtonGetId(DataSetPtr, 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);
            }
        }

        return registerWorked;
    }
    private bool CreateNewVirtualButtonFromBehaviour(VirtualButtonBehaviour newVBB)
    {
        // Calculate the button area:
        Vector2 leftTop, rightBottom;
        newVBB.CalculateButtonArea(out leftTop, out rightBottom);
        VirtualButton.RectangleData area = new VirtualButton.RectangleData
        {
            leftTopX = leftTop.x,
            leftTopY = leftTop.y,
            rightBottomX = rightBottom.x,
            rightBottomY = rightBottom.y
        };

        VirtualButton virtualButton = mImageTarget.CreateVirtualButton(newVBB.VirtualButtonName, area);

        if (virtualButton == null)
        {
            Destroy(newVBB.gameObject);
            return false;
        }

        IEditorVirtualButtonBehaviour newEditorVBB = newVBB;
        newEditorVBB.InitializeVirtualButton(virtualButton);
        mVirtualButtonBehaviours.Add(virtualButton.ID, newVBB);
        return true;
    }
    /// <summary>
    /// Associates existing virtual button behaviour with virtualbuttons and creates new VirtualButtons if necessary
    /// </summary>
    void IEditorImageTargetBehaviour.AssociateExistingVirtualButtonBehaviour(VirtualButtonBehaviour virtualButtonBehaviour)
    {
        VirtualButton virtualButton = mImageTarget.GetVirtualButtonByName(virtualButtonBehaviour.VirtualButtonName);

        if (virtualButton == null)
        {
            Vector2 leftTop, rightBottom;
            virtualButtonBehaviour.CalculateButtonArea(out leftTop, out rightBottom);
            VirtualButton.RectangleData area = new VirtualButton.RectangleData
                                                {
                                                    leftTopX = leftTop.x,
                                                    leftTopY = leftTop.y,
                                                    rightBottomX = rightBottom.x,
                                                    rightBottomY = rightBottom.y
                                                };
            virtualButton = mImageTarget.CreateVirtualButton(virtualButtonBehaviour.VirtualButtonName, area);

            // Create the virtual button
            if (virtualButton != null)
            {
                Debug.Log("Successfully created virtual button " +
                          virtualButtonBehaviour.VirtualButtonName +
                          " at startup");

                virtualButtonBehaviour.UnregisterOnDestroy = true;
            }
            else
            {
                Debug.LogError("Failed to create virtual button " +
                               virtualButtonBehaviour.VirtualButtonName +
                               " at startup");
            }
        }

        if (virtualButton != null)
        {
            //  Duplicate check:
            if (!mVirtualButtonBehaviours.ContainsKey(virtualButton.ID))
            {
                // OK:
                IEditorVirtualButtonBehaviour editorVirtualButtonBehaviour = virtualButtonBehaviour;
                editorVirtualButtonBehaviour.InitializeVirtualButton(virtualButton);
                mVirtualButtonBehaviours.Add(virtualButton.ID, virtualButtonBehaviour);

                Debug.Log("Found VirtualButton named " +
                        virtualButtonBehaviour.VirtualButton.Name + " with id " +
                        virtualButtonBehaviour.VirtualButton.ID);

                // Handle any changes to the virtual button in the scene
                // that are not reflected in the config file
                virtualButtonBehaviour.UpdatePose();
                if (!virtualButtonBehaviour.UpdateAreaRectangle() ||
                    !virtualButtonBehaviour.UpdateSensitivity())
                {
                    Debug.LogError("Failed to update virtual button " +
                                   virtualButtonBehaviour.VirtualButton.Name +
                                   " at startup");
                }
                else
                {
                    Debug.Log("Updated virtual button " +
                              virtualButtonBehaviour.VirtualButton.Name +
                              " at startup");
                }
            }
        }
    }
Example #7
0
    /// <summary>
    /// Associates existing virtual button behaviour with virtualbuttons and creates new VirtualButtons if necessary
    /// </summary>
    void IEditorImageTargetBehaviour.AssociateExistingVirtualButtonBehaviour(VirtualButtonBehaviour virtualButtonBehaviour)
    {
        VirtualButton virtualButton = mImageTarget.GetVirtualButtonByName(virtualButtonBehaviour.VirtualButtonName);

        if (virtualButton == null)
        {
            Vector2 leftTop, rightBottom;
            virtualButtonBehaviour.CalculateButtonArea(out leftTop, out rightBottom);
            var area = new RectangleData
            {
                leftTopX     = leftTop.x,
                leftTopY     = leftTop.y,
                rightBottomX = rightBottom.x,
                rightBottomY = rightBottom.y
            };
            virtualButton = mImageTarget.CreateVirtualButton(virtualButtonBehaviour.VirtualButtonName, area);

            // Create the virtual button
            if (virtualButton != null)
            {
                Debug.Log("Successfully created virtual button " +
                          virtualButtonBehaviour.VirtualButtonName +
                          " at startup");

                virtualButtonBehaviour.UnregisterOnDestroy = true;
            }
            else
            {
                Debug.LogError("Failed to create virtual button " +
                               virtualButtonBehaviour.VirtualButtonName +
                               " at startup");
            }
        }

        if (virtualButton != null)
        {
            //  Duplicate check:
            if (!mVirtualButtonBehaviours.ContainsKey(virtualButton.ID))
            {
                // OK:
                IEditorVirtualButtonBehaviour editorVirtualButtonBehaviour = virtualButtonBehaviour;
                editorVirtualButtonBehaviour.InitializeVirtualButton(virtualButton);
                mVirtualButtonBehaviours.Add(virtualButton.ID, virtualButtonBehaviour);

                Debug.Log("Found VirtualButton named " +
                          virtualButtonBehaviour.VirtualButton.Name + " with id " +
                          virtualButtonBehaviour.VirtualButton.ID);

                // Handle any changes to the virtual button in the scene
                // that are not reflected in the config file
                virtualButtonBehaviour.UpdatePose();
                if (!virtualButtonBehaviour.UpdateAreaRectangle() ||
                    !virtualButtonBehaviour.UpdateSensitivity())
                {
                    Debug.LogError("Failed to update virtual button " +
                                   virtualButtonBehaviour.VirtualButton.Name +
                                   " at startup");
                }
                else
                {
                    Debug.Log("Updated virtual button " +
                              virtualButtonBehaviour.VirtualButton.Name +
                              " at startup");
                }
            }
        }
    }