- Home /
This post has been wikified, any user with enough reputation can edit it.
Question by
Clarenceonline · Sep 02, 2013 at 05:16 AM ·
gui buttonttsgui labelgui layout
[HELP] GUI not showing up as they should be in the C# script
please help me anyone, any help would be appreciated the gui layout, label and buttons are not showing up when i add the script to the main camera.
using UnityEngine; using System; using System.Collections;
public class Example : MonoBehaviour {
private string [] LocalizedStrings;
private static TTSBridge ttsengine;
public Font unicodearial;
string thetext = "Awesome dude! Input a phrase to speech.\n You can use enter to make a new line.\nTry something!";
int retval;
string deviceLanguage ="";
string TTSLanguage ="";
//string TTSLanguages="";
float thepitch = 1.0f;
float oldpitch = 1.0f;
float therate = 1.0f;
float oldrate = 1.0f;
#if UNITY_ANDROID
void Start () {
AndroidJNI.AttachCurrentThread();
// Retrieve device current language
using (AndroidJavaClass cls = new AndroidJavaClass("java.util.Locale")) {
using (AndroidJavaObject locale = cls.CallStatic<AndroidJavaObject>("getDefault")) {
deviceLanguage = locale.Call<string>("getDisplayLanguage");
}
}
// Startup vibration Java object
ttsengine = new TTSBridge();
ttsengine.Init();
}
#endif
void OnGUI() {
GUI.color = Color.white;
GUI.skin.font = unicodearial;
GUILayout.BeginArea(new Rect(20, 10, Screen.width-40, Screen.height-80));
GUILayout.Label("Android Native TTS engine plugin example demo");
GUILayout.Space(10.0f);
GUILayout.Label("device language:"+deviceLanguage);
GUILayout.Space(10.0f);
GUILayout.Label("TTS engine language:"+TTSLanguage);
if(ttsengine.isInitialized())
TTSLanguage = ttsengine.GetLanguage();
if(GUILayout.Button("Switch to english", GUILayout.Height(40)))
{
if UNITY_ANDROID
retval = ttsengine.SetLanguage("inglese");
Debug.Log( "setLanguage(US) returned: "+retval);
endif
}
GUILayout.Space(10.0f);
if(GUILayout.Button("Switch to "+deviceLanguage+"(default)", GUILayout.Height(40)))
{
if UNITY_ANDROID
retval=ttsengine.SetLanguage("italiano");
Debug.Log( "setLanguage(ITA) returned: "+retval);
endif
}
GUILayout.Space(40.0f);
GUILayout.Label("Set pitch: "+thepitch);
thepitch = GUILayout.HorizontalSlider(thepitch,0.1f,2.0f, GUILayout.Height(50));
if (thepitch!=oldpitch)
{
oldpitch=thepitch;
if UNITY_ANDROID
ttsengine.SetPitch(thepitch);
endif
}
GUILayout.Space(30.0f);
GUILayout.Label("Set speed: "+therate);
therate = GUILayout.HorizontalSlider(therate,0.5f,2.0f, GUILayout.Height(50));
if (therate!=oldrate)
{
oldrate=therate;
if UNITY_ANDROID
retval=ttsengine.SetSpeechRate(therate);
endif
}
GUILayout.Space(20.0f);
thetext = GUILayout.TextArea( thetext, 200 );
GUILayout.Space(20.0f);
if(GUILayout.Button("TALK", GUILayout.Height(80)))
{
// talk
if UNITY_ANDROID
ttsengine.Speak(thetext.ToLower());
endif
}
GUILayout.Space(30.0f);
GUILayout.EndArea();
GUI.Label(new Rect(0,Screen.height-40,Screen.width,40),"Litobyte Softworks - Native TTS engine plugin v 1.1.0");
}
void OnApplicationQuit()
{
ttsengine.Dispose();
}
}
Comment