Commit 86a015df8b49174823494466ed7c2ce0f6988713

Authored by Mateus Lustosa
1 parent e37ad421

Adds frame wait on GPM; Fix traslation cancel button; Changes subtitles font; Im…

…proves Logger; Adds request waiter coroutine
Assets/Scenes/Main.unity
@@ -4849,7 +4849,7 @@ MonoBehaviour: @@ -4849,7 +4849,7 @@ MonoBehaviour:
4849 m_CancelButton: Cancel 4849 m_CancelButton: Cancel
4850 m_InputActionsPerSecond: 10 4850 m_InputActionsPerSecond: 10
4851 m_RepeatDelay: 0.5 4851 m_RepeatDelay: 0.5
4852 - m_ForceModuleActive: 0 4852 + m_ForceModuleActive: 1
4853 --- !u!114 &842733393 4853 --- !u!114 &842733393
4854 MonoBehaviour: 4854 MonoBehaviour:
4855 m_ObjectHideFlags: 0 4855 m_ObjectHideFlags: 0
@@ -5796,9 +5796,10 @@ MonoBehaviour: @@ -5796,9 +5796,10 @@ MonoBehaviour:
5796 m_GameObject: {fileID: 970584908} 5796 m_GameObject: {fileID: 970584908}
5797 m_Enabled: 1 5797 m_Enabled: 1
5798 m_EditorHideFlags: 0 5798 m_EditorHideFlags: 0
5799 - m_Script: {fileID: 11500000, guid: a9cc0ccbda0accb4ea816c19265b622f, type: 3} 5799 + m_Script: {fileID: 11500000, guid: 2f9320693b408af41867b25eefd59d32, type: 3}
5800 m_Name: 5800 m_Name:
5801 m_EditorClassIdentifier: 5801 m_EditorClassIdentifier:
  5802 + maximumLines: 20
5802 --- !u!114 &970584913 5803 --- !u!114 &970584913
5803 MonoBehaviour: 5804 MonoBehaviour:
5804 m_ObjectHideFlags: 0 5805 m_ObjectHideFlags: 0
@@ -7925,7 +7926,7 @@ RectTransform: @@ -7925,7 +7926,7 @@ RectTransform:
7925 m_Children: 7926 m_Children:
7926 - {fileID: 1952387009} 7927 - {fileID: 1952387009}
7927 m_Father: {fileID: 1620867682} 7928 m_Father: {fileID: 1620867682}
7928 - m_RootOrder: 0 7929 + m_RootOrder: 1
7929 m_AnchorMin: {x: 0, y: 0} 7930 m_AnchorMin: {x: 0, y: 0}
7930 m_AnchorMax: {x: 1, y: 1} 7931 m_AnchorMax: {x: 1, y: 1}
7931 m_AnchoredPosition: {x: 0, y: 0} 7932 m_AnchoredPosition: {x: 0, y: 0}
@@ -10268,7 +10269,7 @@ RectTransform: @@ -10268,7 +10269,7 @@ RectTransform:
10268 m_Children: 10269 m_Children:
10269 - {fileID: 1697118936} 10270 - {fileID: 1697118936}
10270 m_Father: {fileID: 1620867682} 10271 m_Father: {fileID: 1620867682}
10271 - m_RootOrder: 1 10272 + m_RootOrder: 0
10272 m_AnchorMin: {x: 0, y: 0} 10273 m_AnchorMin: {x: 0, y: 0}
10273 m_AnchorMax: {x: 1, y: 0} 10274 m_AnchorMax: {x: 1, y: 0}
10274 m_AnchoredPosition: {x: 0, y: 0} 10275 m_AnchoredPosition: {x: 0, y: 0}
@@ -10701,8 +10702,8 @@ RectTransform: @@ -10701,8 +10702,8 @@ RectTransform:
10701 m_LocalScale: {x: 1, y: 1, z: 1} 10702 m_LocalScale: {x: 1, y: 1, z: 1}
10702 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} 10703 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
10703 m_Children: 10704 m_Children:
10704 - - {fileID: 1265043070}  
10705 - {fileID: 1533000892} 10705 - {fileID: 1533000892}
  10706 + - {fileID: 1265043070}
10706 - {fileID: 1024302432} 10707 - {fileID: 1024302432}
10707 - {fileID: 861767965} 10708 - {fileID: 861767965}
10708 - {fileID: 848083143} 10709 - {fileID: 848083143}
@@ -11496,11 +11497,11 @@ MonoBehaviour: @@ -11496,11 +11497,11 @@ MonoBehaviour:
11496 m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI, 11497 m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI,
11497 Version=1.0.0.0, Culture=neutral, PublicKeyToken=null 11498 Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
11498 m_FontData: 11499 m_FontData:
11499 - m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0} 11500 + m_Font: {fileID: 12800000, guid: e0e3a41abb6c4a8419def4e22a7aa35e, type: 3}
11500 m_FontSize: 24 11501 m_FontSize: 24
11501 - m_FontStyle: 1 11502 + m_FontStyle: 0
11502 m_BestFit: 0 11503 m_BestFit: 0
11503 - m_MinSize: 22 11504 + m_MinSize: 2
11504 m_MaxSize: 80 11505 m_MaxSize: 80
11505 m_Alignment: 7 11506 m_Alignment: 7
11506 m_AlignByGeometry: 0 11507 m_AlignByGeometry: 0
Assets/Scripts/Player Manager/GenericPlayerManager.cs
@@ -18,16 +18,17 @@ @@ -18,16 +18,17 @@
18 * - Reprodução 18 * - Reprodução
19 * Quando não há acesso aos bundles dos sinais de pontuação, eles são ignorados. 19 * Quando não há acesso aos bundles dos sinais de pontuação, eles são ignorados.
20 * Ç adicionado como TYPE_WORD. 20 * Ç adicionado como TYPE_WORD.
  21 + *
  22 + * Log directory: http://docs.unity3d.com/Manual/LogFiles.html
21 */ 23 */
22 24
23 -//Log Dir http://docs.unity3d.com/Manual/LogFiles.html  
24 using UnityEngine; 25 using UnityEngine;
25 using System.Collections; 26 using System.Collections;
26 using System.Collections.Generic; 27 using System.Collections.Generic;
27 using System; 28 using System;
28 using System.Threading; 29 using System.Threading;
29 using UnityEngine.UI; 30 using UnityEngine.UI;
30 -using LAViD.VLibras; 31 +using LAViD.VLibras.Utils;
31 32
32 public abstract class GenericPlayerManager : MonoBehaviour { 33 public abstract class GenericPlayerManager : MonoBehaviour {
33 34
@@ -220,7 +221,7 @@ public abstract class GenericPlayerManager : MonoBehaviour { @@ -220,7 +221,7 @@ public abstract class GenericPlayerManager : MonoBehaviour {
220 return state; 221 return state;
221 } 222 }
222 catch (NullReferenceException nre) { 223 catch (NullReferenceException nre) {
223 - LAViD.VLibras.Utils.Logger.Log("'" + name + "' não foi encontrado!\n" + nre.ToString()); 224 + PlayerLogger.Log("'" + name + "' não foi encontrado!\n" + nre.ToString());
224 } 225 }
225 226
226 return null; 227 return null;
@@ -245,21 +246,28 @@ public abstract class GenericPlayerManager : MonoBehaviour { @@ -245,21 +246,28 @@ public abstract class GenericPlayerManager : MonoBehaviour {
245 246
246 /** 247 /**
247 * Returns the asset bundle named aniName. 248 * Returns the asset bundle named aniName.
248 - *  
249 - * @return AssetBundle - se for encontrado.  
250 - * null - se ocorrer num erro. 249 + * @return WWW - request.
251 */ 250 */
252 protected abstract WWW loadAssetBundle(string aniName); 251 protected abstract WWW loadAssetBundle(string aniName);
253 252
254 - /**  
255 - * Listen to changes in the playing status. 253 + /**
  254 + * Called when a bundle request causes error.
  255 + * @param gloss - gloss been loaded.
  256 + * @param word - bundle requested.
256 */ 257 */
257 - protected abstract void onConnectionError(string gloss, string word); 258 + public abstract void onConnectionError(string gloss, string word);
258 259
259 - /** 260 + /**
260 * Listen to changes in the playing status. 261 * Listen to changes in the playing status.
261 */ 262 */
262 - protected abstract void onPlayingStateChange(); 263 + public abstract void onPlayingStateChange();
  264 +
  265 + /**
  266 + * Waits for response or time runs out.
  267 + * Check for WWW.isDone, true if success, false if timeout.
  268 + * @param www - request.
  269 + */
  270 + protected abstract IEnumerator WaitForResponse(WWW www);
263 271
264 protected abstract WWW getCheckConnectionRequest(); 272 protected abstract WWW getCheckConnectionRequest();
265 273
@@ -423,7 +431,7 @@ public abstract class GenericPlayerManager : MonoBehaviour { @@ -423,7 +431,7 @@ public abstract class GenericPlayerManager : MonoBehaviour {
423 this.subtitles.updateLetterSpeed(); 431 this.subtitles.updateLetterSpeed();
424 } 432 }
425 433
426 - LAViD.VLibras.Utils.Logger.Log("Animação \"" + animName + "\" inexistente."); 434 + PlayerLogger.Log("Animação \"" + animName + "\" inexistente.");
427 } 435 }
428 else 436 else
429 { 437 {
@@ -505,10 +513,10 @@ public abstract class GenericPlayerManager : MonoBehaviour { @@ -505,10 +513,10 @@ public abstract class GenericPlayerManager : MonoBehaviour {
505 513
506 if (checkConnectionRequest.responseHeaders.Count > 0) 514 if (checkConnectionRequest.responseHeaders.Count > 0)
507 { 515 {
508 - LAViD.VLibras.Utils.Logger.Log(checkConnectionRequest.responseHeaders["STATUS"]); 516 + PlayerLogger.Log(checkConnectionRequest.responseHeaders["STATUS"]);
509 connected = checkConnectionRequest.responseHeaders["STATUS"].Contains("404"); 517 connected = checkConnectionRequest.responseHeaders["STATUS"].Contains("404");
510 } 518 }
511 - else LAViD.VLibras.Utils.Logger.Log("No response headers.");*/ 519 + else PlayerLogger.Log("No response headers.");*/
512 520
513 bool connected = true; 521 bool connected = true;
514 bool playingStarted = false; 522 bool playingStarted = false;
@@ -523,21 +531,14 @@ public abstract class GenericPlayerManager : MonoBehaviour { @@ -523,21 +531,14 @@ public abstract class GenericPlayerManager : MonoBehaviour {
523 531
524 if ( ! nonexistent && ! loaded && connected) 532 if ( ! nonexistent && ! loaded && connected)
525 { 533 {
526 - WWW www = loadAssetBundle(aniName);  
527 - yield return www; 534 + WWW bundleRequest = loadAssetBundle(aniName);
  535 + yield return WaitForResponse(bundleRequest);
528 536
529 - LAViD.VLibras.Utils.Logger.Log("Bundle request done (" + aniName + ")."); 537 + PlayerLogger.Log("GPM", "lAP", "Bundle request done (" + aniName + ").");
530 538
531 - if (www.error == null) 539 + if (bundleRequest.isDone && bundleRequest.error == null)
532 { 540 {
533 - AssetBundle bundle = www.assetBundle;  
534 -  
535 - /*LAViD.VLibras.Utils.Logger.Log("count: " + www.responseHeaders.Count);  
536 - if (www.responseHeaders.Count > 0)  
537 - LAViD.VLibras.Utils.Logger.Log(www.responseHeaders["STATUS"]);  
538 -  
539 - // if (www.responseHeaders.Count > 0 && www.responseHeaders["STATUS"].EndsWith("200 OK"));  
540 - */ 541 + AssetBundle bundle = bundleRequest.assetBundle;
541 542
542 if (bundle != null && !String.IsNullOrEmpty(bundle.mainAsset.name)) 543 if (bundle != null && !String.IsNullOrEmpty(bundle.mainAsset.name))
543 { 544 {
@@ -547,19 +548,22 @@ public abstract class GenericPlayerManager : MonoBehaviour { @@ -547,19 +548,22 @@ public abstract class GenericPlayerManager : MonoBehaviour {
547 if (aniClip) 548 if (aniClip)
548 { 549 {
549 COMPONENT_ANIMATION.AddClip(aniClip, aniName); 550 COMPONENT_ANIMATION.AddClip(aniClip, aniName);
550 - yield return null; 551 + if (playingStarted) yield return new WaitForEndOfFrame();
551 552
552 loadedAssetBundles.Add(aniName); 553 loadedAssetBundles.Add(aniName);
553 loaded = true; 554 loaded = true;
554 555
555 - LAViD.VLibras.Utils.Logger.Log("Bundle \"" + aniName + "\" loaded!"); 556 + PlayerLogger.Log("GPM", "lAP", "Bundle \"" + aniName + "\" loaded!");
556 } 557 }
557 - else LAViD.VLibras.Utils.Logger.Log("Sinal \"" + aniName + "\" foi não carregado corretamente."); 558 + else PlayerLogger.Log("GPM", "lAP", "Sign \"" + aniName + "\" wasn't loaded successfuly.");
558 } 559 }
  560 + else PlayerLogger.Log("GPM", "lAP", "Bundle \"" + aniName + "\" wasn't loaded successfuly.");
  561 +
  562 + if ( ! loaded) nonexistentAssetBundles.Add(aniName);
559 } 563 }
560 else 564 else
561 { 565 {
562 - LAViD.VLibras.Utils.Logger.Log("Connection error"); 566 + PlayerLogger.Log("GPM", "lAP", "Connection error.");
563 onConnectionError(gloss, aniName); 567 onConnectionError(gloss, aniName);
564 } 568 }
565 } 569 }
@@ -589,15 +593,7 @@ public abstract class GenericPlayerManager : MonoBehaviour { @@ -589,15 +593,7 @@ public abstract class GenericPlayerManager : MonoBehaviour {
589 // Soletra palavra 593 // Soletra palavra
590 else 594 else
591 { 595 {
592 - // Se a animação não foi carregada e nem está marcada como não existente,  
593 - // adiciona ao set de animações não existentes  
594 - if ( ! nonexistent && connected)  
595 - {  
596 - LAViD.VLibras.Utils.Logger.Log("Non existent");  
597 - nonexistentAssetBundles.Add(aniName);  
598 - }  
599 -  
600 - LAViD.VLibras.Utils.Logger.Log("~~ To spell: " + aniName); 596 + PlayerLogger.Log("GPM", "lAP", "To spell: " + aniName);
601 597
602 if (this.flags.Contains(aniName) || this.intervalAnimations.Contains(aniName)) 598 if (this.flags.Contains(aniName) || this.intervalAnimations.Contains(aniName))
603 { 599 {
@@ -626,8 +622,7 @@ public abstract class GenericPlayerManager : MonoBehaviour { @@ -626,8 +622,7 @@ public abstract class GenericPlayerManager : MonoBehaviour {
626 } 622 }
627 } 623 }
628 624
629 - if (playingStarted)  
630 - yield return new WaitForEndOfFrame(); 625 + if (playingStarted) yield return new WaitForEndOfFrame();
631 } 626 }
632 627
633 // Default 628 // Default
Assets/Scripts/Player Manager/Logger.cs
@@ -1,28 +0,0 @@ @@ -1,28 +0,0 @@
1 -using UnityEngine;  
2 -using UnityEngine.UI;  
3 -  
4 -namespace LAViD.VLibras.Utils {  
5 -  
6 - public class Logger : MonoBehaviour {  
7 -  
8 - public static Logger instance;  
9 -  
10 - private Text textObj;  
11 -  
12 - void Start()  
13 - {  
14 - Logger.instance = this;  
15 - this.textObj = this.gameObject.GetComponent<Text>();  
16 - }  
17 -  
18 - public static void Log(string text)  
19 - {  
20 - if (Logger.instance != null)  
21 - Logger.instance.textObj.text = text + "\n" + Logger.instance.textObj.text;  
22 -  
23 - Debug.Log(text);  
24 - }  
25 -  
26 - }  
27 -  
28 -}  
Assets/Scripts/Player Manager/Logger.cs.meta
@@ -1,12 +0,0 @@ @@ -1,12 +0,0 @@
1 -fileFormatVersion: 2  
2 -guid: a9cc0ccbda0accb4ea816c19265b622f  
3 -timeCreated: 1475716239  
4 -licenseType: Pro  
5 -MonoImporter:  
6 - serializedVersion: 2  
7 - defaultReferences: []  
8 - executionOrder: 0  
9 - icon: {instanceID: 0}  
10 - userData:  
11 - assetBundleName:  
12 - assetBundleVariant:  
Assets/Scripts/Player Manager/PlayerLogger.cs 0 → 100644
@@ -0,0 +1,32 @@ @@ -0,0 +1,32 @@
  1 +using UnityEngine;
  2 +using UnityEngine.UI;
  3 +
  4 +namespace LAViD.VLibras.Utils {
  5 +
  6 + public abstract class PlayerLogger : MonoBehaviour {
  7 +
  8 + public static PlayerLogger instance;
  9 +
  10 + protected virtual void Start()
  11 + {
  12 + PlayerLogger.instance = this;
  13 + }
  14 +
  15 + protected abstract void write(string text);
  16 +
  17 + public static void Log(string text)
  18 + {
  19 + if (PlayerLogger.instance != null)
  20 + PlayerLogger.instance.write(text);
  21 +
  22 + Debug.Log(text);
  23 + }
  24 +
  25 + public static void Log(string classSign, string methodSign, string text)
  26 + {
  27 + PlayerLogger.Log(classSign + "." + methodSign + ": " + text);
  28 + }
  29 +
  30 + }
  31 +
  32 +}
Assets/Scripts/Player Manager/PlayerLogger.cs.meta 0 → 100644
@@ -0,0 +1,12 @@ @@ -0,0 +1,12 @@
  1 +fileFormatVersion: 2
  2 +guid: a9cc0ccbda0accb4ea816c19265b622f
  3 +timeCreated: 1475716239
  4 +licenseType: Pro
  5 +MonoImporter:
  6 + serializedVersion: 2
  7 + defaultReferences: []
  8 + executionOrder: 0
  9 + icon: {instanceID: 0}
  10 + userData:
  11 + assetBundleName:
  12 + assetBundleVariant:
Assets/Scripts/Player Manager/Utils.cs
@@ -10,12 +10,6 @@ namespace LAViD.VLibras.Utils { @@ -10,12 +10,6 @@ namespace LAViD.VLibras.Utils {
10 return new Color(color.r, color.g, color.b, alpha); 10 return new Color(color.r, color.g, color.b, alpha);
11 } 11 }
12 12
13 - public static void Log(this Debug debug, string text)  
14 - {  
15 - Debug.Log(text);  
16 - Logger.Log(text);  
17 - }  
18 -  
19 } 13 }
20 14
21 } 15 }
Assets/Scripts/PlayerManager.cs
1 -//Log Dir http://docs.unity3d.com/Manual/LogFiles.html  
2 -  
3 -// requisiçao http get no unity  
4 -// vlibras.lavid.ufpb.br:5000/glosa?texto=CASA%LAVID%123  
5 using UnityEngine; 1 using UnityEngine;
6 using System.Collections; 2 using System.Collections;
7 -using System.Collections.Generic;  
8 using System; 3 using System;
9 -using System.IO;  
10 -using System.Text;  
11 -using System.Runtime.InteropServices;  
12 using UnityEngine.UI; 4 using UnityEngine.UI;
13 -using System.Threading;  
14 -using System.Net;  
15 using LAViD.VLibras.Utils; 5 using LAViD.VLibras.Utils;
16 6
17 public class PlayerManager : GenericPlayerManager { 7 public class PlayerManager : GenericPlayerManager {
@@ -84,7 +74,7 @@ public class PlayerManager : GenericPlayerManager { @@ -84,7 +74,7 @@ public class PlayerManager : GenericPlayerManager {
84 74
85 public void playDict(string word) 75 public void playDict(string word)
86 { 76 {
87 - LAViD.VLibras.Utils.Logger.Log("Requesting dictionary: " + word); 77 + PlayerLogger.Log("Requesting dictionary: " + word);
88 78
89 this.dictWord = word; 79 this.dictWord = word;
90 base.gloss = word; 80 base.gloss = word;
@@ -130,20 +120,20 @@ public class PlayerManager : GenericPlayerManager { @@ -130,20 +120,20 @@ public class PlayerManager : GenericPlayerManager {
130 120
131 protected override WWW loadAssetBundle(string aniName) 121 protected override WWW loadAssetBundle(string aniName)
132 { 122 {
133 - LAViD.VLibras.Utils.Logger.Log("Requesting bundle: " + BASE_URL + regionPath + aniName); 123 + PlayerLogger.Log("PM", "lAB", "Requesting bundle: " + BASE_URL + regionPath + aniName);
134 return WWW.LoadFromCacheOrDownload(BASE_URL + regionPath + aniName, this.regionHash); 124 return WWW.LoadFromCacheOrDownload(BASE_URL + regionPath + aniName, this.regionHash);
135 } 125 }
136 126
137 private System.Object LOCKER_STATE = new System.Object(); 127 private System.Object LOCKER_STATE = new System.Object();
138 128
139 - protected override void onPlayingStateChange() 129 + public override void onPlayingStateChange()
140 { 130 {
141 lock (LOCKER_STATE) { 131 lock (LOCKER_STATE) {
142 this.screenManager.changeStates(base.isPlaying(), base.isPaused(), ! String.IsNullOrEmpty(base.gloss)); 132 this.screenManager.changeStates(base.isPlaying(), base.isPaused(), ! String.IsNullOrEmpty(base.gloss));
143 } 133 }
144 } 134 }
145 135
146 - protected override void onConnectionError(string gloss, string word) 136 + public override void onConnectionError(string gloss, string word)
147 { 137 {
148 if (gloss.Equals(this.dictWord)) 138 if (gloss.Equals(this.dictWord))
149 { 139 {
@@ -156,11 +146,11 @@ public class PlayerManager : GenericPlayerManager { @@ -156,11 +146,11 @@ public class PlayerManager : GenericPlayerManager {
156 // Called from microphone icon at main interface 146 // Called from microphone icon at main interface
157 public void callVoiceRecognizer() 147 public void callVoiceRecognizer()
158 { 148 {
159 - LAViD.VLibras.Utils.Logger.Log("Requesting voice recognizer"); 149 + PlayerLogger.Log("Requesting voice recognizer");
160 150
161 string gloss = voiceRecognizer.callRecognition(); 151 string gloss = voiceRecognizer.callRecognition();
162 this.translateScreenText.text = gloss; 152 this.translateScreenText.text = gloss;
163 - LAViD.VLibras.Utils.Logger.Log("Voice recognizer answer: " + gloss); 153 + PlayerLogger.Log("Voice recognizer answer: " + gloss);
164 154
165 this.screenManager.switchScreen("translate"); 155 this.screenManager.switchScreen("translate");
166 } 156 }
@@ -179,11 +169,11 @@ public class PlayerManager : GenericPlayerManager { @@ -179,11 +169,11 @@ public class PlayerManager : GenericPlayerManager {
179 if (connection.error == null) 169 if (connection.error == null)
180 { 170 {
181 if (connection.responseHeaders.Count > 0) 171 if (connection.responseHeaders.Count > 0)
182 - LAViD.VLibras.Utils.Logger.Log(connection.responseHeaders["STATUS"]); 172 + PlayerLogger.Log(connection.responseHeaders["STATUS"]);
183 else 173 else
184 - LAViD.VLibras.Utils.Logger.Log("No STATUS"); 174 + PlayerLogger.Log("No STATUS");
185 } 175 }
186 - else LAViD.VLibras.Utils.Logger.Log("ERROR: " + connection.error); 176 + else PlayerLogger.Log("ERROR: " + connection.error);
187 177
188 return false;*/ 178 return false;*/
189 179
@@ -199,7 +189,7 @@ public class PlayerManager : GenericPlayerManager { @@ -199,7 +189,7 @@ public class PlayerManager : GenericPlayerManager {
199 { 189 {
200 if (e.Response != null) 190 if (e.Response != null)
201 { 191 {
202 - LAViD.VLibras.Utils.Logger.Log(((HttpWebResponse)e.Response).StatusCode); 192 + PlayerLogger.Log(((HttpWebResponse)e.Response).StatusCode);
203 return ((HttpWebResponse)e.Response).StatusCode == HttpStatusCode.NotFound; 193 return ((HttpWebResponse)e.Response).StatusCode == HttpStatusCode.NotFound;
204 } 194 }
205 } 195 }
@@ -210,90 +200,95 @@ public class PlayerManager : GenericPlayerManager { @@ -210,90 +200,95 @@ public class PlayerManager : GenericPlayerManager {
210 return false;*/ 200 return false;*/
211 } 201 }
212 202
213 - private IEnumerator translate(string gloss)  
214 - {  
215 - bool returnSuccess = true;  
216 - bool timeout = false; 203 + protected override IEnumerator WaitForResponse(WWW www)
  204 + {
  205 + PlayerLogger.Log("PM", "WFR", "Stating time check.");
217 206
218 - LAViD.VLibras.Utils.Logger.Log("Requesting translator: " + gloss); 207 +#if UNITY_ANDROID
  208 + const float timeoutLimit = 10f;
  209 +#elif UNITY_IOS
  210 + const float timeoutLimit = 3f;
  211 +#endif
  212 +
  213 + float timer = 0;
  214 +
  215 + while ( ! www.isDone)
  216 + {
  217 + if (timer > timeoutLimit)
  218 + {
  219 + PlayerLogger.Log("PM", "WFR", "Timeout.");
  220 + yield break;
  221 + }
219 222
  223 +#if UNITY_ANDROID
  224 + timer += Time.deltaTime;
  225 + yield return null;
  226 +#elif UNITY_IOS
  227 + timer += 0.1f;
  228 + yield return new WaitForSeconds(0.1f);
  229 +#endif
  230 + }
  231 +
  232 + PlayerLogger.Log("PM", "WFR", "Done.");
  233 + }
  234 +
  235 + private IEnumerator translate(string gloss)
  236 + {
220 base.randomAnimations.lockFor("translate"); 237 base.randomAnimations.lockFor("translate");
221 this.screenManager.setLoadingSnippetState(true); 238 this.screenManager.setLoadingSnippetState(true);
222 239
223 WWW glossRequest = new WWW(SERVER_URL + WWW.EscapeURL(gloss)); 240 WWW glossRequest = new WWW(SERVER_URL + WWW.EscapeURL(gloss));
224 - LAViD.VLibras.Utils.Logger.Log("Translate: Request: " + SERVER_URL + WWW.EscapeURL(gloss));  
225 241
226 - if (glossRequest != null)  
227 - {  
228 - const float timeoutLimit = 10f;  
229 - float timer = 0;  
230 -  
231 - LAViD.VLibras.Utils.Logger.Log("Translate: Stating time check."); 242 + PlayerLogger.Log("PM", "t", "Gloss: " + gloss);
  243 + PlayerLogger.Log("PM", "t", "Request: " + SERVER_URL + WWW.EscapeURL(gloss));
  244 +
  245 + yield return WaitForResponse(glossRequest);
232 246
233 - while (!glossRequest.isDone) 247 + try {
  248 + if ( ! glossRequest.isDone)
234 { 249 {
235 - if (timer > timeoutLimit)  
236 - {  
237 - timeout = true;  
238 - break;  
239 - }  
240 -  
241 - timer += Time.deltaTime;  
242 - yield return null; 250 + this.screenManager.showConnectionErrorDialog(
  251 + PlayerManager.ERROR_STATUS_MESSAGE.CONNECTION_TIMEOUT_FAILURE);
  252 +
  253 + PlayerLogger.Log("PM", "t", "Timeout.");
243 } 254 }
  255 + else if (glossRequest.error != null)
  256 + {
  257 + this.screenManager.showConnectionErrorDialog(
  258 + PlayerManager.ERROR_STATUS_MESSAGE.INTERNET_CONNECTION_FAILURE);
244 259
245 - LAViD.VLibras.Utils.Logger.Log("Translate: Timeout check finished."); 260 + PlayerLogger.Log("PM", "t", "(WWW) Error: " + glossRequest.error);
  261 + }
  262 + else if (glossRequest.responseHeaders.Count == 0 || !glossRequest.responseHeaders["STATUS"].EndsWith("200 OK"))
  263 + {
  264 + PlayerLogger.Log("PM", "t", "Unsuccessful answer.");
246 265
247 - if (!timeout) 266 + this.screenManager.showConnectionErrorDialog(
  267 + PlayerManager.ERROR_STATUS_MESSAGE.TRANSLATOR_CONNECTION_FAILURE);
  268 + }
  269 + else if (String.IsNullOrEmpty(glossRequest.text))
248 { 270 {
249 - if (glossRequest.error == null)  
250 - {  
251 - LAViD.VLibras.Utils.Logger.Log("Translate: Request: count=" + glossRequest.responseHeaders.Count + ", status=" + glossRequest.responseHeaders["STATUS"]);  
252 - returnSuccess = glossRequest.responseHeaders.Count > 0 && glossRequest.responseHeaders["STATUS"].EndsWith("200 OK");  
253 -  
254 - if (returnSuccess)  
255 - {  
256 - if (!String.IsNullOrEmpty(glossRequest.text))  
257 - {  
258 - LAViD.VLibras.Utils.Logger.Log("Translator answer: " + glossRequest.text);  
259 -  
260 - base.gloss = glossRequest.text;  
261 - base.playNow(glossRequest.text);  
262 - this.screenManager.setLoadingSnippetState(false);  
263 - base.randomAnimations.unlockFor("translate");  
264 -  
265 - yield break;  
266 - }  
267 - else LAViD.VLibras.Utils.Logger.Log("Error at PlayerManager.translate: empty answer.");  
268 - }  
269 - else LAViD.VLibras.Utils.Logger.Log("Error at PlayerManager.translate: unsuccessful answer.");  
270 - }  
271 - else LAViD.VLibras.Utils.Logger.Log("Error at PlayerManager.translate: (WWW) glosaRequest: " + glossRequest.error); 271 + PlayerLogger.Log("PM", "t", "Empty answer.");
272 } 272 }
273 - else LAViD.VLibras.Utils.Logger.Log("Error at PlayerManager.translate: timeout.");  
274 - }  
275 - else LAViD.VLibras.Utils.Logger.Log ("Error at PlayerManager.translate: (WWW) glosaRequest is NULL."); 273 + else
  274 + {
  275 + PlayerLogger.Log("PM", "t", "Answer: " + glossRequest.text);
276 276
277 - base.gloss = gloss.ToUpper(); 277 + gloss = glossRequest.text;
278 278
279 - this.screenManager.setLoadingSnippetState(false);  
280 - base.randomAnimations.unlockFor("translate"); 279 + base.gloss = gloss;
  280 + base.playNow(base.gloss);
281 281
282 - if (returnSuccess)  
283 - {  
284 - this.screenManager.showConnectionErrorDialog(  
285 - PlayerManager.ERROR_STATUS_MESSAGE.TRANSLATOR_CONNECTION_FAILURE); 282 + yield break;
  283 + }
  284 +
  285 + base.gloss = gloss.ToUpper();
286 } 286 }
287 - else if (timeout) 287 + finally
288 { 288 {
289 - this.screenManager.showConnectionErrorDialog(  
290 - PlayerManager.ERROR_STATUS_MESSAGE.CONNECTION_TIMEOUT_FAILURE); 289 + this.screenManager.setLoadingSnippetState(false);
  290 + base.randomAnimations.unlockFor("translate");
291 } 291 }
292 - else  
293 - {  
294 - this.screenManager.showConnectionErrorDialog(  
295 - PlayerManager.ERROR_STATUS_MESSAGE.INTERNET_CONNECTION_FAILURE);  
296 - }  
297 - } 292 + }
298 293
299 } 294 }
Assets/Scripts/UI/ScreenManager.cs
@@ -125,6 +125,12 @@ public class ScreenManager : MonoBehaviour { @@ -125,6 +125,12 @@ public class ScreenManager : MonoBehaviour {
125 } 125 }
126 } 126 }
127 127
  128 + private void pause()
  129 + {
  130 + playerManager.setPauseState(true);
  131 + setPauseMenuState(true);
  132 + }
  133 +
128 public void switchScreen(GameObject screen) 134 public void switchScreen(GameObject screen)
129 { 135 {
130 bool active = screen.activeSelf; 136 bool active = screen.activeSelf;
@@ -135,16 +141,13 @@ public class ScreenManager : MonoBehaviour { @@ -135,16 +141,13 @@ public class ScreenManager : MonoBehaviour {
135 141
136 screen.SetActive(true); 142 screen.SetActive(true);
137 143
138 - if (playerManager.isPlayingIntervalAnimation())  
139 - playerManager.stopAll(); 144 + if (playerManager.isPlayingIntervalAnimation())
  145 + playerManager.stopAll();
140 146
141 - else if (playerManager.isPlaying())  
142 - {  
143 - playerManager.setPauseState(true);  
144 - setPauseMenuState(true);  
145 - }  
146 -  
147 - setAvatarColliderState(false); 147 + else if (playerManager.isPlaying())
  148 + pause();
  149 +
  150 + setAvatarColliderState(false);
148 randomAnimations.lockFor(LOCK_ID); 151 randomAnimations.lockFor(LOCK_ID);
149 152
150 if (screen == infoScreen) 153 if (screen == infoScreen)
@@ -181,6 +184,9 @@ public class ScreenManager : MonoBehaviour { @@ -181,6 +184,9 @@ public class ScreenManager : MonoBehaviour {
181 { 184 {
182 settingsPanel.Animate(true); 185 settingsPanel.Animate(true);
183 setPanelOpen(true); 186 setPanelOpen(true);
  187 +
  188 + if (playerManager.isPlaying())
  189 + pause();
184 } 190 }
185 191
186 public void openRegionPanel() 192 public void openRegionPanel()
Assets/Scripts/VisualLogger.cs 0 → 100644
@@ -0,0 +1,31 @@ @@ -0,0 +1,31 @@
  1 +using System.Collections.Generic;
  2 +using UnityEngine.UI;
  3 +
  4 +namespace LAViD.VLibras.Utils {
  5 +
  6 + public class VisualLogger : PlayerLogger {
  7 +
  8 + private Text textObj;
  9 + public int maximumLines = 20;
  10 +
  11 + private List<string> logs = new List<string>();
  12 +
  13 + protected override void Start()
  14 + {
  15 + base.Start();
  16 + this.textObj = this.gameObject.GetComponent<Text>();
  17 + }
  18 +
  19 + protected override void write(string text)
  20 + {
  21 + this.logs.Insert(0, text);
  22 +
  23 + if (this.logs.Count > this.maximumLines)
  24 + this.logs.RemoveAt(this.logs.Count - 1);
  25 +
  26 + this.textObj.text = string.Join("\n", this.logs.ToArray());
  27 + }
  28 +
  29 + }
  30 +
  31 +}
0 \ No newline at end of file 32 \ No newline at end of file
Assets/Scripts/VisualLogger.cs.meta 0 → 100644
@@ -0,0 +1,12 @@ @@ -0,0 +1,12 @@
  1 +fileFormatVersion: 2
  2 +guid: 2f9320693b408af41867b25eefd59d32
  3 +timeCreated: 1475762751
  4 +licenseType: Pro
  5 +MonoImporter:
  6 + serializedVersion: 2
  7 + defaultReferences: []
  8 + executionOrder: 0
  9 + icon: {instanceID: 0}
  10 + userData:
  11 + assetBundleName:
  12 + assetBundleVariant: