diff --git a/Assets/Scenes/Main.unity b/Assets/Scenes/Main.unity index e590dd6..4ea7e4a 100644 --- a/Assets/Scenes/Main.unity +++ b/Assets/Scenes/Main.unity @@ -4849,7 +4849,7 @@ MonoBehaviour: m_CancelButton: Cancel m_InputActionsPerSecond: 10 m_RepeatDelay: 0.5 - m_ForceModuleActive: 0 + m_ForceModuleActive: 1 --- !u!114 &842733393 MonoBehaviour: m_ObjectHideFlags: 0 @@ -5796,9 +5796,10 @@ MonoBehaviour: m_GameObject: {fileID: 970584908} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: a9cc0ccbda0accb4ea816c19265b622f, type: 3} + m_Script: {fileID: 11500000, guid: 2f9320693b408af41867b25eefd59d32, type: 3} m_Name: m_EditorClassIdentifier: + maximumLines: 20 --- !u!114 &970584913 MonoBehaviour: m_ObjectHideFlags: 0 @@ -7925,7 +7926,7 @@ RectTransform: m_Children: - {fileID: 1952387009} m_Father: {fileID: 1620867682} - m_RootOrder: 0 + m_RootOrder: 1 m_AnchorMin: {x: 0, y: 0} m_AnchorMax: {x: 1, y: 1} m_AnchoredPosition: {x: 0, y: 0} @@ -10268,7 +10269,7 @@ RectTransform: m_Children: - {fileID: 1697118936} m_Father: {fileID: 1620867682} - m_RootOrder: 1 + m_RootOrder: 0 m_AnchorMin: {x: 0, y: 0} m_AnchorMax: {x: 1, y: 0} m_AnchoredPosition: {x: 0, y: 0} @@ -10701,8 +10702,8 @@ RectTransform: m_LocalScale: {x: 1, y: 1, z: 1} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_Children: - - {fileID: 1265043070} - {fileID: 1533000892} + - {fileID: 1265043070} - {fileID: 1024302432} - {fileID: 861767965} - {fileID: 848083143} @@ -11496,11 +11497,11 @@ MonoBehaviour: m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null m_FontData: - m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0} + m_Font: {fileID: 12800000, guid: e0e3a41abb6c4a8419def4e22a7aa35e, type: 3} m_FontSize: 24 - m_FontStyle: 1 + m_FontStyle: 0 m_BestFit: 0 - m_MinSize: 22 + m_MinSize: 2 m_MaxSize: 80 m_Alignment: 7 m_AlignByGeometry: 0 diff --git a/Assets/Scripts/Player Manager/GenericPlayerManager.cs b/Assets/Scripts/Player Manager/GenericPlayerManager.cs index 1c8667e..1455152 100644 --- a/Assets/Scripts/Player Manager/GenericPlayerManager.cs +++ b/Assets/Scripts/Player Manager/GenericPlayerManager.cs @@ -18,16 +18,17 @@ * - Reprodução * Quando não há acesso aos bundles dos sinais de pontuação, eles são ignorados. * Ç adicionado como TYPE_WORD. + * + * Log directory: http://docs.unity3d.com/Manual/LogFiles.html */ -//Log Dir http://docs.unity3d.com/Manual/LogFiles.html using UnityEngine; using System.Collections; using System.Collections.Generic; using System; using System.Threading; using UnityEngine.UI; -using LAViD.VLibras; +using LAViD.VLibras.Utils; public abstract class GenericPlayerManager : MonoBehaviour { @@ -220,7 +221,7 @@ public abstract class GenericPlayerManager : MonoBehaviour { return state; } catch (NullReferenceException nre) { - LAViD.VLibras.Utils.Logger.Log("'" + name + "' não foi encontrado!\n" + nre.ToString()); + PlayerLogger.Log("'" + name + "' não foi encontrado!\n" + nre.ToString()); } return null; @@ -245,21 +246,28 @@ public abstract class GenericPlayerManager : MonoBehaviour { /** * Returns the asset bundle named aniName. - * - * @return AssetBundle - se for encontrado. - * null - se ocorrer num erro. + * @return WWW - request. */ protected abstract WWW loadAssetBundle(string aniName); - /** - * Listen to changes in the playing status. + /** + * Called when a bundle request causes error. + * @param gloss - gloss been loaded. + * @param word - bundle requested. */ - protected abstract void onConnectionError(string gloss, string word); + public abstract void onConnectionError(string gloss, string word); - /** + /** * Listen to changes in the playing status. */ - protected abstract void onPlayingStateChange(); + public abstract void onPlayingStateChange(); + + /** + * Waits for response or time runs out. + * Check for WWW.isDone, true if success, false if timeout. + * @param www - request. + */ + protected abstract IEnumerator WaitForResponse(WWW www); protected abstract WWW getCheckConnectionRequest(); @@ -423,7 +431,7 @@ public abstract class GenericPlayerManager : MonoBehaviour { this.subtitles.updateLetterSpeed(); } - LAViD.VLibras.Utils.Logger.Log("Animação \"" + animName + "\" inexistente."); + PlayerLogger.Log("Animação \"" + animName + "\" inexistente."); } else { @@ -505,10 +513,10 @@ public abstract class GenericPlayerManager : MonoBehaviour { if (checkConnectionRequest.responseHeaders.Count > 0) { - LAViD.VLibras.Utils.Logger.Log(checkConnectionRequest.responseHeaders["STATUS"]); + PlayerLogger.Log(checkConnectionRequest.responseHeaders["STATUS"]); connected = checkConnectionRequest.responseHeaders["STATUS"].Contains("404"); } - else LAViD.VLibras.Utils.Logger.Log("No response headers.");*/ + else PlayerLogger.Log("No response headers.");*/ bool connected = true; bool playingStarted = false; @@ -523,21 +531,14 @@ public abstract class GenericPlayerManager : MonoBehaviour { if ( ! nonexistent && ! loaded && connected) { - WWW www = loadAssetBundle(aniName); - yield return www; + WWW bundleRequest = loadAssetBundle(aniName); + yield return WaitForResponse(bundleRequest); - LAViD.VLibras.Utils.Logger.Log("Bundle request done (" + aniName + ")."); + PlayerLogger.Log("GPM", "lAP", "Bundle request done (" + aniName + ")."); - if (www.error == null) + if (bundleRequest.isDone && bundleRequest.error == null) { - AssetBundle bundle = www.assetBundle; - - /*LAViD.VLibras.Utils.Logger.Log("count: " + www.responseHeaders.Count); - if (www.responseHeaders.Count > 0) - LAViD.VLibras.Utils.Logger.Log(www.responseHeaders["STATUS"]); - - // if (www.responseHeaders.Count > 0 && www.responseHeaders["STATUS"].EndsWith("200 OK")); - */ + AssetBundle bundle = bundleRequest.assetBundle; if (bundle != null && !String.IsNullOrEmpty(bundle.mainAsset.name)) { @@ -547,19 +548,22 @@ public abstract class GenericPlayerManager : MonoBehaviour { if (aniClip) { COMPONENT_ANIMATION.AddClip(aniClip, aniName); - yield return null; + if (playingStarted) yield return new WaitForEndOfFrame(); loadedAssetBundles.Add(aniName); loaded = true; - LAViD.VLibras.Utils.Logger.Log("Bundle \"" + aniName + "\" loaded!"); + PlayerLogger.Log("GPM", "lAP", "Bundle \"" + aniName + "\" loaded!"); } - else LAViD.VLibras.Utils.Logger.Log("Sinal \"" + aniName + "\" foi não carregado corretamente."); + else PlayerLogger.Log("GPM", "lAP", "Sign \"" + aniName + "\" wasn't loaded successfuly."); } + else PlayerLogger.Log("GPM", "lAP", "Bundle \"" + aniName + "\" wasn't loaded successfuly."); + + if ( ! loaded) nonexistentAssetBundles.Add(aniName); } else { - LAViD.VLibras.Utils.Logger.Log("Connection error"); + PlayerLogger.Log("GPM", "lAP", "Connection error."); onConnectionError(gloss, aniName); } } @@ -589,15 +593,7 @@ public abstract class GenericPlayerManager : MonoBehaviour { // Soletra palavra else { - // Se a animação não foi carregada e nem está marcada como não existente, - // adiciona ao set de animações não existentes - if ( ! nonexistent && connected) - { - LAViD.VLibras.Utils.Logger.Log("Non existent"); - nonexistentAssetBundles.Add(aniName); - } - - LAViD.VLibras.Utils.Logger.Log("~~ To spell: " + aniName); + PlayerLogger.Log("GPM", "lAP", "To spell: " + aniName); if (this.flags.Contains(aniName) || this.intervalAnimations.Contains(aniName)) { @@ -626,8 +622,7 @@ public abstract class GenericPlayerManager : MonoBehaviour { } } - if (playingStarted) - yield return new WaitForEndOfFrame(); + if (playingStarted) yield return new WaitForEndOfFrame(); } // Default diff --git a/Assets/Scripts/Player Manager/Logger.cs b/Assets/Scripts/Player Manager/Logger.cs deleted file mode 100644 index 10945c5..0000000 --- a/Assets/Scripts/Player Manager/Logger.cs +++ /dev/null @@ -1,28 +0,0 @@ -using UnityEngine; -using UnityEngine.UI; - -namespace LAViD.VLibras.Utils { - - public class Logger : MonoBehaviour { - - public static Logger instance; - - private Text textObj; - - void Start() - { - Logger.instance = this; - this.textObj = this.gameObject.GetComponent(); - } - - public static void Log(string text) - { - if (Logger.instance != null) - Logger.instance.textObj.text = text + "\n" + Logger.instance.textObj.text; - - Debug.Log(text); - } - - } - -} diff --git a/Assets/Scripts/Player Manager/Logger.cs.meta b/Assets/Scripts/Player Manager/Logger.cs.meta deleted file mode 100644 index aaad33c..0000000 --- a/Assets/Scripts/Player Manager/Logger.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: a9cc0ccbda0accb4ea816c19265b622f -timeCreated: 1475716239 -licenseType: Pro -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Scripts/Player Manager/PlayerLogger.cs b/Assets/Scripts/Player Manager/PlayerLogger.cs new file mode 100644 index 0000000..28ef731 --- /dev/null +++ b/Assets/Scripts/Player Manager/PlayerLogger.cs @@ -0,0 +1,32 @@ +using UnityEngine; +using UnityEngine.UI; + +namespace LAViD.VLibras.Utils { + + public abstract class PlayerLogger : MonoBehaviour { + + public static PlayerLogger instance; + + protected virtual void Start() + { + PlayerLogger.instance = this; + } + + protected abstract void write(string text); + + public static void Log(string text) + { + if (PlayerLogger.instance != null) + PlayerLogger.instance.write(text); + + Debug.Log(text); + } + + public static void Log(string classSign, string methodSign, string text) + { + PlayerLogger.Log(classSign + "." + methodSign + ": " + text); + } + + } + +} diff --git a/Assets/Scripts/Player Manager/PlayerLogger.cs.meta b/Assets/Scripts/Player Manager/PlayerLogger.cs.meta new file mode 100644 index 0000000..aaad33c --- /dev/null +++ b/Assets/Scripts/Player Manager/PlayerLogger.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: a9cc0ccbda0accb4ea816c19265b622f +timeCreated: 1475716239 +licenseType: Pro +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Player Manager/Utils.cs b/Assets/Scripts/Player Manager/Utils.cs index 4bee7aa..95a12de 100644 --- a/Assets/Scripts/Player Manager/Utils.cs +++ b/Assets/Scripts/Player Manager/Utils.cs @@ -10,12 +10,6 @@ namespace LAViD.VLibras.Utils { return new Color(color.r, color.g, color.b, alpha); } - public static void Log(this Debug debug, string text) - { - Debug.Log(text); - Logger.Log(text); - } - } } diff --git a/Assets/Scripts/PlayerManager.cs b/Assets/Scripts/PlayerManager.cs index cf439cd..c9e7a4e 100644 --- a/Assets/Scripts/PlayerManager.cs +++ b/Assets/Scripts/PlayerManager.cs @@ -1,17 +1,7 @@ -//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; -using System.Net; using LAViD.VLibras.Utils; public class PlayerManager : GenericPlayerManager { @@ -84,7 +74,7 @@ public class PlayerManager : GenericPlayerManager { public void playDict(string word) { - LAViD.VLibras.Utils.Logger.Log("Requesting dictionary: " + word); + PlayerLogger.Log("Requesting dictionary: " + word); this.dictWord = word; base.gloss = word; @@ -130,20 +120,20 @@ public class PlayerManager : GenericPlayerManager { protected override WWW loadAssetBundle(string aniName) { - LAViD.VLibras.Utils.Logger.Log("Requesting bundle: " + BASE_URL + regionPath + aniName); + PlayerLogger.Log("PM", "lAB", "Requesting bundle: " + BASE_URL + regionPath + aniName); return WWW.LoadFromCacheOrDownload(BASE_URL + regionPath + aniName, this.regionHash); } private System.Object LOCKER_STATE = new System.Object(); - protected override void onPlayingStateChange() + public override void onPlayingStateChange() { lock (LOCKER_STATE) { this.screenManager.changeStates(base.isPlaying(), base.isPaused(), ! String.IsNullOrEmpty(base.gloss)); } } - protected override void onConnectionError(string gloss, string word) + public override void onConnectionError(string gloss, string word) { if (gloss.Equals(this.dictWord)) { @@ -156,11 +146,11 @@ public class PlayerManager : GenericPlayerManager { // Called from microphone icon at main interface public void callVoiceRecognizer() { - LAViD.VLibras.Utils.Logger.Log("Requesting voice recognizer"); + PlayerLogger.Log("Requesting voice recognizer"); string gloss = voiceRecognizer.callRecognition(); this.translateScreenText.text = gloss; - LAViD.VLibras.Utils.Logger.Log("Voice recognizer answer: " + gloss); + PlayerLogger.Log("Voice recognizer answer: " + gloss); this.screenManager.switchScreen("translate"); } @@ -179,11 +169,11 @@ public class PlayerManager : GenericPlayerManager { if (connection.error == null) { if (connection.responseHeaders.Count > 0) - LAViD.VLibras.Utils.Logger.Log(connection.responseHeaders["STATUS"]); + PlayerLogger.Log(connection.responseHeaders["STATUS"]); else - LAViD.VLibras.Utils.Logger.Log("No STATUS"); + PlayerLogger.Log("No STATUS"); } - else LAViD.VLibras.Utils.Logger.Log("ERROR: " + connection.error); + else PlayerLogger.Log("ERROR: " + connection.error); return false;*/ @@ -199,7 +189,7 @@ public class PlayerManager : GenericPlayerManager { { if (e.Response != null) { - LAViD.VLibras.Utils.Logger.Log(((HttpWebResponse)e.Response).StatusCode); + PlayerLogger.Log(((HttpWebResponse)e.Response).StatusCode); return ((HttpWebResponse)e.Response).StatusCode == HttpStatusCode.NotFound; } } @@ -210,90 +200,95 @@ public class PlayerManager : GenericPlayerManager { return false;*/ } - private IEnumerator translate(string gloss) - { - bool returnSuccess = true; - bool timeout = false; + protected override IEnumerator WaitForResponse(WWW www) + { + PlayerLogger.Log("PM", "WFR", "Stating time check."); - LAViD.VLibras.Utils.Logger.Log("Requesting translator: " + gloss); +#if UNITY_ANDROID + const float timeoutLimit = 10f; +#elif UNITY_IOS + const float timeoutLimit = 3f; +#endif + + float timer = 0; + + while ( ! www.isDone) + { + if (timer > timeoutLimit) + { + PlayerLogger.Log("PM", "WFR", "Timeout."); + yield break; + } +#if UNITY_ANDROID + timer += Time.deltaTime; + yield return null; +#elif UNITY_IOS + timer += 0.1f; + yield return new WaitForSeconds(0.1f); +#endif + } + + PlayerLogger.Log("PM", "WFR", "Done."); + } + + private IEnumerator translate(string gloss) + { base.randomAnimations.lockFor("translate"); this.screenManager.setLoadingSnippetState(true); WWW glossRequest = new WWW(SERVER_URL + WWW.EscapeURL(gloss)); - LAViD.VLibras.Utils.Logger.Log("Translate: Request: " + SERVER_URL + WWW.EscapeURL(gloss)); - if (glossRequest != null) - { - const float timeoutLimit = 10f; - float timer = 0; - - LAViD.VLibras.Utils.Logger.Log("Translate: Stating time check."); + PlayerLogger.Log("PM", "t", "Gloss: " + gloss); + PlayerLogger.Log("PM", "t", "Request: " + SERVER_URL + WWW.EscapeURL(gloss)); + + yield return WaitForResponse(glossRequest); - while (!glossRequest.isDone) + try { + if ( ! glossRequest.isDone) { - if (timer > timeoutLimit) - { - timeout = true; - break; - } - - timer += Time.deltaTime; - yield return null; + this.screenManager.showConnectionErrorDialog( + PlayerManager.ERROR_STATUS_MESSAGE.CONNECTION_TIMEOUT_FAILURE); + + PlayerLogger.Log("PM", "t", "Timeout."); } + else if (glossRequest.error != null) + { + this.screenManager.showConnectionErrorDialog( + PlayerManager.ERROR_STATUS_MESSAGE.INTERNET_CONNECTION_FAILURE); - LAViD.VLibras.Utils.Logger.Log("Translate: Timeout check finished."); + PlayerLogger.Log("PM", "t", "(WWW) Error: " + glossRequest.error); + } + else if (glossRequest.responseHeaders.Count == 0 || !glossRequest.responseHeaders["STATUS"].EndsWith("200 OK")) + { + PlayerLogger.Log("PM", "t", "Unsuccessful answer."); - if (!timeout) + this.screenManager.showConnectionErrorDialog( + PlayerManager.ERROR_STATUS_MESSAGE.TRANSLATOR_CONNECTION_FAILURE); + } + else if (String.IsNullOrEmpty(glossRequest.text)) { - if (glossRequest.error == null) - { - LAViD.VLibras.Utils.Logger.Log("Translate: Request: count=" + glossRequest.responseHeaders.Count + ", status=" + glossRequest.responseHeaders["STATUS"]); - returnSuccess = glossRequest.responseHeaders.Count > 0 && glossRequest.responseHeaders["STATUS"].EndsWith("200 OK"); - - if (returnSuccess) - { - if (!String.IsNullOrEmpty(glossRequest.text)) - { - LAViD.VLibras.Utils.Logger.Log("Translator answer: " + glossRequest.text); - - base.gloss = glossRequest.text; - base.playNow(glossRequest.text); - this.screenManager.setLoadingSnippetState(false); - base.randomAnimations.unlockFor("translate"); - - yield break; - } - else LAViD.VLibras.Utils.Logger.Log("Error at PlayerManager.translate: empty answer."); - } - else LAViD.VLibras.Utils.Logger.Log("Error at PlayerManager.translate: unsuccessful answer."); - } - else LAViD.VLibras.Utils.Logger.Log("Error at PlayerManager.translate: (WWW) glosaRequest: " + glossRequest.error); + PlayerLogger.Log("PM", "t", "Empty answer."); } - else LAViD.VLibras.Utils.Logger.Log("Error at PlayerManager.translate: timeout."); - } - else LAViD.VLibras.Utils.Logger.Log ("Error at PlayerManager.translate: (WWW) glosaRequest is NULL."); + else + { + PlayerLogger.Log("PM", "t", "Answer: " + glossRequest.text); - base.gloss = gloss.ToUpper(); + gloss = glossRequest.text; - this.screenManager.setLoadingSnippetState(false); - base.randomAnimations.unlockFor("translate"); + base.gloss = gloss; + base.playNow(base.gloss); - if (returnSuccess) - { - this.screenManager.showConnectionErrorDialog( - PlayerManager.ERROR_STATUS_MESSAGE.TRANSLATOR_CONNECTION_FAILURE); + yield break; + } + + base.gloss = gloss.ToUpper(); } - else if (timeout) + finally { - this.screenManager.showConnectionErrorDialog( - PlayerManager.ERROR_STATUS_MESSAGE.CONNECTION_TIMEOUT_FAILURE); + this.screenManager.setLoadingSnippetState(false); + base.randomAnimations.unlockFor("translate"); } - else - { - this.screenManager.showConnectionErrorDialog( - PlayerManager.ERROR_STATUS_MESSAGE.INTERNET_CONNECTION_FAILURE); - } - } + } } diff --git a/Assets/Scripts/UI/ScreenManager.cs b/Assets/Scripts/UI/ScreenManager.cs index 7137b0f..49a4295 100644 --- a/Assets/Scripts/UI/ScreenManager.cs +++ b/Assets/Scripts/UI/ScreenManager.cs @@ -125,6 +125,12 @@ public class ScreenManager : MonoBehaviour { } } + private void pause() + { + playerManager.setPauseState(true); + setPauseMenuState(true); + } + public void switchScreen(GameObject screen) { bool active = screen.activeSelf; @@ -135,16 +141,13 @@ public class ScreenManager : MonoBehaviour { screen.SetActive(true); - if (playerManager.isPlayingIntervalAnimation()) - playerManager.stopAll(); + if (playerManager.isPlayingIntervalAnimation()) + playerManager.stopAll(); - else if (playerManager.isPlaying()) - { - playerManager.setPauseState(true); - setPauseMenuState(true); - } - - setAvatarColliderState(false); + else if (playerManager.isPlaying()) + pause(); + + setAvatarColliderState(false); randomAnimations.lockFor(LOCK_ID); if (screen == infoScreen) @@ -181,6 +184,9 @@ public class ScreenManager : MonoBehaviour { { settingsPanel.Animate(true); setPanelOpen(true); + + if (playerManager.isPlaying()) + pause(); } public void openRegionPanel() diff --git a/Assets/Scripts/VisualLogger.cs b/Assets/Scripts/VisualLogger.cs new file mode 100644 index 0000000..c030010 --- /dev/null +++ b/Assets/Scripts/VisualLogger.cs @@ -0,0 +1,31 @@ +using System.Collections.Generic; +using UnityEngine.UI; + +namespace LAViD.VLibras.Utils { + + public class VisualLogger : PlayerLogger { + + private Text textObj; + public int maximumLines = 20; + + private List logs = new List(); + + protected override void Start() + { + base.Start(); + this.textObj = this.gameObject.GetComponent(); + } + + protected override void write(string text) + { + this.logs.Insert(0, text); + + if (this.logs.Count > this.maximumLines) + this.logs.RemoveAt(this.logs.Count - 1); + + this.textObj.text = string.Join("\n", this.logs.ToArray()); + } + + } + +} \ No newline at end of file diff --git a/Assets/Scripts/VisualLogger.cs.meta b/Assets/Scripts/VisualLogger.cs.meta new file mode 100644 index 0000000..e5e3fda --- /dev/null +++ b/Assets/Scripts/VisualLogger.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 2f9320693b408af41867b25eefd59d32 +timeCreated: 1475762751 +licenseType: Pro +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: -- libgit2 0.21.2