//Log Dir http://docs.unity3d.com/Manual/LogFiles.html // requisiçao http get no unity // vlibras.lavid.ufpb.br:5000/glosa?texto=CASA%LAVID%123 using UnityEngine; using System.Collections; using System.Collections.Generic; using System; using System.IO; using System.Text; using System.Runtime.InteropServices; using UnityEngine.UI; using System.Threading; public class PlayerManager : GenericPlayerManager { private const string BASE_URL = "http://150.165.205.9/anims/ANDROID/"; private const string SERVER_URL = "http://vlibras.lavid.ufpb.br/glosa?texto="; public GameObject loading_snippet; protected VoiceRecognition voiceRecognizer; //private const string BASE_URL = "http://150.165.205.9/anims/AssetBundles/0_DefaultBundles/"; public InputField INFIELD; private int version = 1; private bool thereIsConnection; public Canvas canvas_connection_error; private string[] randomAnimationNames = new string[] { //"[OLA]", "[ESPREGUIÇADA]", //"[BOCEJAR]", "[BOCEJAR_01]", //"[COCHILAR]", "[COCHILAR_01]", //"[PISCADA]", //"[PISCADA_01]", //"[PISCADA_02]", //"[PISCADA_03]", //"[RELAXAR]", //"[RELAXAR_01]" }; public override void Start() { base.setRandomAnimations(new RandomAnimations(this, randomAnimationNames, 2, 1F), randomAnimationNames); base.Start(); Application.ExternalCall("onLoadPlayer");//var onLoadPlayer = function(){} voiceRecognizer = new VoiceRecognition(); Screen.fullScreen = false; } public void catchGlosa(String glosa) { base.glosa = glosa; start_web_play(); } public void start_web_play() { try { base.play(); } catch(Exception e) { e.ToString();//Debug.Log(e+" :: Ops!"); } } public void start_web_play(string glosa) { try { if (base.isLoading() || base.isPlaying()) base.stop_animations(); base.play(glosa); } catch(Exception e) { e.ToString();//Debug.Log(e+" :: Ops!"); } } protected override WWW loadAssetBundle(string aniName) { if (aniName[0] == '[' && aniName[aniName.Length - 1] == ']') { string assetPath = Application.dataPath + "/Bundles/" + aniName; if ( ! File.Exists(assetPath)) return null; try { WWW www = new WWW("file://" + assetPath); return www; } catch (Exception e) { Debug.Log(e); } } return WWW.LoadFromCacheOrDownload(BASE_URL + aniName, version); } protected override void onPlayingStateChange() {} IEnumerator translate() { WWW glosaRequest = new WWW(SERVER_URL + WWW.EscapeURL(base.glosa)); try { waitForRequest(glosaRequest); } catch (Exception e) { e.ToString(); } if (glosaRequest != null) { loading_snippet.SetActive(true); yield return glosaRequest; loading_snippet.SetActive(false); if ( ! String.IsNullOrEmpty(glosaRequest.text)) { base.glosa = glosaRequest.text; Debug.Log("Server answer: " + glosa); } else { base.glosa = base.glosa.ToUpper(); Debug.Log("No answer: " + glosa); } } else Debug.Log ("eita"); base.play(); } public void start_inputfield_web_play() { try { base.glosa = INFIELD.text; StartCoroutine("translate"); } catch (Exception e) { Debug.Log (e+" :: Exception StartCourr"); } } protected IEnumerator waitForRequest(WWW www) { yield return www.isDone; // check for errors if (www.error == null) Debug.Log("WWW Ok!: " + www.text); else Debug.Log("WWW Error: "+ www.error); } // Called from microphone icon at main interface public void callVoiceRecognizer() { CheckConnection(); if(thereIsConnection) { base.glosa = voiceRecognizer.callRecognition(); if(!base.glosa.Equals("")) { StartCoroutine(translate ()); } } else { Debug.Log("NO NET"); DisplayConnectionError(); //base.voiceRecognizer.callConnectionError(); //base.voiceRecognizer.callConnectionError(); } //base.voiceRecognizer.callConnectionError();*/ } void CheckConnection() { thereIsConnection = false; WWW www = new WWW("https://www.google.com.br"); waitForRequest(www); if(www.bytesDownloaded > 0){ thereIsConnection = true; //Debug.Log("connection ok"); } else{ Debug.Log("no connection"); thereIsConnection = false; } } void DisplayConnectionError(){ canvas_connection_error.enabled = true; SetAvatarCollider(false); ScreenReferences.HOME_SCREEN = false; } public void HideConnectionError(){ canvas_connection_error.enabled = false; SetAvatarCollider(true); ScreenReferences.HOME_SCREEN = true; } }