Mostrando postagens com marcador Unity. Mostrar todas as postagens
Mostrando postagens com marcador Unity. Mostrar todas as postagens

domingo, 5 de fevereiro de 2017

Como apresentar a leitura de um comando de voz no ambiente de Realidade Aumentada Vuforia - UNITY

A seguir será apresentada uma solução encontrada para o problema de inserção de textos em tempo real a partir da leitura de um comando de voz no ambiente de Realidade Aumentada no UNITY for Android.

Primeiramente vamos apresentar o contexto:


  1. O ambiente de Realidade Aumentada adotado chama-se Vuforia ;
  2. O plugin de comando de voz é o  Android Ultimate Plugin ;
  3. O problema em questão é integrar o comando de voz no ambiente de RA utilizando um botão "falar";
  4. A partir do comando, um texto é apresentado no ambiente validando o comando e em seguida é executado o comando caso seja reconhecido;
  5. Comandos de voz como socorro, me ajuda, estou perdido, automaticamente é realizado uma ligação para o cuidador e uma mensagem SMS também é enviada.

Para apresentar o texto em tempo real, utilizou-se o método OnGUI do Monobehavior:

Este método OnGUI atualiza a interface por frame, ou seja, o texto é atualizado em tempo real.

Os botões foram inseridos a partir do GUI.Button;

O GUI.TextField se encarregou de retornar o texto gerado a partir do comando de voz

Com relação ao posicionamentodo botão e do texto na interface, utilizou-se o referencial Screen.width e Screen.height.

Segue o código do GUI interface:


#region "GUI"
    void OnGUI(){

guiStyle.fontSize = 50;
       
        //imprime um campo de texto na interface e posiciona no canto inferior da tela
        resultText = GUI.TextField(new Rect(350, Screen.height - 150, 200, 100), resultText,25,guiStyle);

       //imprime um botão com um ícone "falar" no canto inferior direito
if (GUI.Button(new Rect(Screen.width -250, Screen.height -250, 250, 250), iconeFalar))
        {
            StartListeningWithExtraLanguage();
        }
}
#endregion




sexta-feira, 11 de novembro de 2016

Simple solution to add 3D dynamic text in UNITY Vuforia

Considering that you already know how to build a simple example of Vuforia in UNITY, I´m going to register here a simple way to add dynamic 3D text.

1) First of all, insert a 3D Text in the scene. Go to menu GameObject > 3D Object > 3D Text. Write any text in there and call it "dynamicText";

2) Move this 3D Text into ImageTarget;

2) Create a C# Script. Right button on Asset windows > create > C# Script.


Write this code in there:

using UnityEngine;
using UnityEngine.UI;
using System.Collections;

public class textScript : MonoBehaviour {

         // Define this variable will allow you to associate your 3D Text. 
         // To associate it you have to grab the 

[SerializeField]
private TextMesh changeTextMesh = null;

// Use this for initialization
void Start () {
changeTextMesh.text = "This is the new text";
}

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

}
}

3) Save it and go back to the scene. Grab this C# script into the ImageTarget;

4) Grab the dynamicText into the changeTextMesh variable that is obviously located in the ImageTarget inspector (where you input your C# Script)

5) By the time you connect the dynamicText with changeTextMesh it will work like a charm.