Log in or register to post comments

Virtual Button problem

May 25, 2014 - 12:37pm #1

Hi i just recently started using Vuforia sdk and i have difficulties making virtual buttons ...i must say at the beggining that i tryed the sample app and well did not understand it ;/
 

here is what i did:
i added virtual button to the scene as a child of image targer then added plane as a child of virtual button so i can see it . Then i have written simple script to manage button actions and added that script to image targer.

 

public class ManageButtons : MonoBehaviour, IVirtualButtonEventHandler {

    // Use this for initialization    
    void Start () {
        
        VirtualButtonBehaviour[] vbs = GetComponentsInChildren<VirtualButtonBehaviour>();

        foreach (VirtualButtonBehaviour item in vbs) {            
            item.RegisterEventHandler(this);            
        }        
    }

    // Update is called once per frame    
    void Update () {
    }

    public void OnButtonPressed(VirtualButtonAbstractBehaviour vb) {        
        Debug.Log("Helllllloooooooooo");        
    }
    
    public void OnButtonReleased(VirtualButtonAbstractBehaviour vb) {        
        Debug.Log("Goooooodbyeeee");        
    }
}

 

and it's not working ;/ can anyone indicate me to a solution
 

Virtual Button problem

May 29, 2014 - 7:36am #8

Virutal buttons are not visible by default in Play Mode. 

The reason you see an outline around the Virtual Buttons in the example is because there was code written to implement that. 

See the VirtualButtonsUIEventHandler.cs

     /// <summary>
    /// Create a mesh outline for the virtual button.
    /// </summary>
    private void CreateVBMesh(VirtualButtonBehaviour vb)
    {
        GameObject vbObject = vb.gameObject;

        MeshFilter meshFilter = vbObject.GetComponent<MeshFilter>();
        if (!meshFilter)
        {
            meshFilter = vbObject.AddComponent<MeshFilter>();
        }

        // Setup vertex positions.
        Vector3 p0 = new Vector3(-0.5f, 0, -0.5f);
        Vector3 p1 = new Vector3(-0.5f, 0, 0.5f);
        Vector3 p2 = new Vector3(0.5f, 0, -0.5f);
        Vector3 p3 = new Vector3(0.5f, 0, 0.5f);

        Mesh mesh = new Mesh();
        mesh.vertices = new Vector3[] { p0, p1, p2, p3 };
        mesh.triangles = new int[]  {
                                        0,1,2,
                                        2,1,3
                                    };

        // Add UV coordinates.
        mesh.uv = new Vector2[]{
                new Vector2(0,0),
                new Vector2(1,0),
                new Vector2(0,1),
                new Vector2(1,1)
                };

        // Add empty normals array.
        mesh.normals = new Vector3[mesh.vertices.Length];

        // Automatically calculate normals.
        mesh.RecalculateNormals();
        mesh.name = "VBPlane";

        meshFilter.sharedMesh = mesh;

        MeshRenderer meshRenderer = vbObject.GetComponent<MeshRenderer>();
        if (!meshRenderer)
        {
            meshRenderer = vbObject.AddComponent<MeshRenderer>();
        }

        meshRenderer.sharedMaterial = mVirtualButtonMaterial;
    }

I haven't experimented with this, and I'm an admitted C# N00B.  But I'm pretty sure this is what you're looking for.  I changed one of the vector values and could see the change reflected in the Virutal Button highlight shape when I went to Play Mode again.

Virtual Button problem

May 29, 2014 - 4:17am #7

Well i can't figure out why it's not working. But it's not essensial for my project, just wanted to check out how it works

Virtual Button problem

May 27, 2014 - 8:30am #6

I don't see my Virtual Buttons in Play mode either.  I think that is the default setup.

 

This page:  https://developer.vuforia.com/resources/dev-guide/virtual-buttons

Mentions this:

Shape: Make buttons easily identifiable to stand out from rest of image; highlight active buttons in the augmentation layer to hint at 'active regions' on the target

I didn't see any example code for this, so I'm not sure what method they're suggesting to 'highlight' the buttons. 

 

And you're correct about the Y position.  I can't change mine either.

Virtual Button problem

May 27, 2014 - 12:26am #5

By not visible i mean that i can't see it when testing. It's visible in editor but when i test it with camera i cant see it. I'll try to tweak the settings and position maybe it will help

 

I cant't chande thy Y position of button

Virtual Button problem

May 26, 2014 - 12:02pm #4

I'm not sure exactly what you mean by "visible".  But I believe the VirtualButtonPreviewMaterial (light blue by default) should be visible to your AR Camera. 

If the buttons are sitting on top of your ImageTracker, you may need to adjust the Y position to put the buttons on top of the ImageTracker. 

Changing the sensitivity on my buttons from Low to High did not change their visibility.  I can still see them in the editor. 

Virtual Button problem

May 26, 2014 - 11:28am #3

I have sensivity set to High. The button is not visible ... is it normal?

Virtual Button problem

May 26, 2014 - 10:59am #2

Hey there,

I recently did some playing with Virtual Buttons myself. 

This is the script that I got working for my Next and Back buttons.

using UnityEngine;
using System.Collections;

public class CustomVirtualButtonEventHandler : MonoBehaviour , IVirtualButtonEventHandler {
	public int nextcounter=0; //Init counter at zero
	// Use this for initialization
	void Start () {


				VirtualButtonAbstractBehaviour[] vbs = GetComponentsInChildren<VirtualButtonAbstractBehaviour> ();
				for (int i = 0; i < vbs.Length; ++i) {
						vbs [i].RegisterEventHandler (this);
				}
		}

	// Update is called once per frame
	void Update () {
		}
		public void OnButtonPressed( VirtualButtonAbstractBehaviour vb ){
			
				Debug.Log (vb.name + " Pressed");
				if (vb.name == "VBNext") {	
						nextcounter ++;
						Debug.Log ("counter = " + nextcounter);	
				}
				if (vb.name == "VBBack") {	
						nextcounter --;
						Debug.Log ("counter = " + nextcounter);		
				}
		}


		public void OnButtonReleased( VirtualButtonAbstractBehaviour vb ){
			
			Debug.Log( vb.name +" Released" );

		}
	}

I'm not a C# programmer, so I'm not sure why your code isn't working.  Make sure that when you select your Virtual Button in the Unity editor that the Virtual Button Behaviour Script is enabled with the correct script, Button Name, and Sensitivity. 

Log in or register to post comments