PlayerManager.cs
4.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
//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;
}
}