PlayerManager.cs
2.6 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
//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:5000/glosa?texto=";
public GameObject loading_snippet;
//private const string BASE_URL = "http://150.165.205.9/anims/AssetBundles/0_DefaultBundles/";
public InputField INFIELD;
private int version = 1;
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!");
}
}
protected override WWW loadAssetBundle(string aniName)
{
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 string getGlosaFromServer(string str)
{
string strToServer = "";
foreach (char c in str)
if (c.Equals(' '))
strToServer += "%20";
else
strToServer += c;
Debug.Log("str to server -> " + strToServer);
string urlWithText = SERVER_URL + strToServer;
WWW www = new WWW(urlWithText);
StartCoroutine(waitForRequest(www));
// while(!www.isDone) Thread.Sleep(250);
Debug.Log("returned from server -> " + www.text);
return www.text;
}
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);
}
}