diff --git a/Assets/Scripts/RemoteScript.cs b/Assets/Scripts/RemoteScript.cs new file mode 100644 index 0000000..213f3a4 --- /dev/null +++ b/Assets/Scripts/RemoteScript.cs @@ -0,0 +1,350 @@ +//Log Dir http://docs.unity3d.com/Manual/LogFiles.html +using UnityEngine; +using System.Collections; +using System.Collections.Generic; +using System; +using System.Runtime.InteropServices; + + + +public class RemoteScript : MonoBehaviour { + + + + public Animator ANIMATOR; + + public Texture + play, stop, + fast, slow, + box, menu, + captions, captionsActive, captionsInactive, + resize, resolucao, + settings, settingsActive, settingsInactive; + + public float initVarX, initVarY; + public float hSliderValue; + + Boolean isSettingsActive = false; + Boolean isCaptionsActive = true; + + string alfabeto = "0123456789,ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + string stringPre; string[] stringPos; + string aniName = ""; AnimationClip aniClip; + + + string GetCurrentPlayingAnimationClip( ){ + + if(isCaptionsActive){ + + foreach(AnimationState anim in GetComponent()){ + + //Debug.Log(anim.name); + + + if( GetComponent().IsPlaying( anim.name ) ){ + + if(anim.name.Split(' ')[0].Equals("_default")) + return null; + + return anim.name.Split(' ')[0]; + // return anim.name.Split(' '); + + } + + }//foreach + + } + + return null; + + } + + + + void loadIcons(){ + + captions = (Texture) Resources.Load("buttons/Subtitle", typeof(Texture)); + play = (Texture) Resources.Load("buttons/Play", typeof(Texture)); + stop = (Texture) Resources.Load("buttons/Stop", typeof(Texture)); + fast = (Texture) Resources.Load("buttons/Fast", typeof(Texture)); + slow = (Texture) Resources.Load("buttons/Slow", typeof(Texture)); + + settings = (Texture) Resources.Load("buttons/Settings", typeof(Texture)); + settingsActive = (Texture) Resources.Load("buttons/SettingsActive", typeof(Texture)); + settingsInactive = (Texture) Resources.Load("buttons/Settings", typeof(Texture)); + + box = (Texture) Resources.Load("buttons/_Barra", typeof(Texture)); + + menu = (Texture) Resources.Load("buttons/MenuConfig", typeof(Texture)); + captions = (Texture) Resources.Load("buttons/Subtitle", typeof(Texture)); + resize = (Texture) Resources.Load("buttons/Resolution", typeof(Texture)); + resolucao = (Texture) Resources.Load("buttons/Resolucao", typeof(Texture)); + captionsActive = (Texture) Resources.Load("buttons/CaptionsActive", typeof(Texture)); + captionsInactive = (Texture) Resources.Load("buttons/CaptionsInactive", typeof(Texture)); + + initVarX = ((Screen.width/2)-(box.width/2)); + initVarY = ((Screen.height)-(box.height)-10); + + } + + void Start( ){ + + Caching.CleanCache(); + + ANIMATOR = GetComponent(); + + hSliderValue = 1.0f; + loadIcons(); + addAlpha( ); + + + } + + void addAlpha( ){ + + foreach( char letter in alfabeto ){ + + aniClip = Resources.Load ("alpha/"+letter); + if( aniClip ) GetComponent().AddClip(aniClip, ""+letter); + else Debug.Log("Anim "+aniName+" not found"); + + } + }//addAlpha + + + + void animStop( ){ + + GetComponent().Stop( ); + aniClip = Resources.Load("anims/_default"); + GetComponent().CrossFadeQueued("_default", 0.6F, QueueMode.CompleteOthers, PlayMode.StopAll ); + + + } + + void Update( ){ + + foreach(AnimationState anim in GetComponent()) anim.speed = hSliderValue; + + } + + + public string glosa; + + + void playFromFile(){ Debug.Log("ReadFromFile");// ClearConsole(); + + //while( GetComponent() != null) + // GetComponent().Dequeue(); + //GetComponent().Clear(); + //GetComponent().CrossFadeQueued( PlayMode.StopAll ); + + GetComponent().Stop( ); + + + + stringPre = + " _default " + //+"ABRIL ACADEMIA" + +glosa + +" _default "; + + stringPos = stringPre.Split(' '); + + foreach( string aniName in stringPos ){ + + aniClip = Resources.Load("anims/"+aniName); + + if( aniClip ){ + + GetComponent().AddClip(aniClip, aniName); + GetComponent().CrossFadeQueued( aniName, 0.6F, QueueMode.CompleteOthers );//0.4 + + GetComponent().RemoveClip( aniName ); + + }else + foreach(char letter in aniName) + GetComponent().CrossFadeQueued(""+letter, 0.6F, QueueMode.CompleteOthers); + + }//foreach string aniName + + aniClip = Resources.Load("anims/_default"); + GetComponent().AddClip(aniClip, "_default"); + + } + + + + void OnGUI() { /* GUI.backgroundColor = Color.clear; */ + /* Box onde ficarao os botoes; */ GUI.Box( new Rect ( initVarX, initVarY, box.width, box.height), box, "" ); + + + + + + if( GUI.Button (new Rect(initVarX+(box.height/4)+10 , initVarY+(play.width/2), play.width, play.height), new GUIContent("", play, "play"), "" )) + playFromFile(); + + glosa = GUI.TextArea ( new Rect (120, 10,400, 50), glosa, 400); + + + + + + + + + + + if( GUI.Button ( new Rect( initVarX+(box.height)+15, initVarY+(stop.width/2), stop.height, stop.height ), stop, "" ) ) + animStop( ); + + + + { //INIT_SPEED + + GUI.DrawTexture(new Rect( initVarX+(box.height)*2, initVarY+(slow.width/2), slow.height, slow.height ), slow); + + hSliderValue = GUI.HorizontalSlider ( new Rect( initVarX+(box.height)*2+(slow.width), initVarY+(slow.width/2)+(slow.width/3), box.height*3, box.height/4 ), hSliderValue, 0.0F, 2.0F ); + + GUI.DrawTexture(new Rect( initVarX+(box.height)*5+(slow.width), initVarY+(fast.width/2), fast.height, fast.height ), fast); + + } //FINISH_SPEED + + + + + + + /** + * + * BOTAO DE LEGENDA + * + **/ + if (GUI.Button(new Rect(initVarX+(box.height)*6+15, initVarY+(slow.width/2), settings.width, settings.height), captions, "")){ + + isCaptionsActive = !isCaptionsActive; + + } + + + /** + * + * BOTAO DE CONFIGURAÇOES + * + **/ + if (GUI.Button(new Rect(initVarX+(box.height)*7, initVarY+(slow.width/2), settings.width, settings.height), settings, "")){ + + isSettingsActive = !isSettingsActive; + + if(isSettingsActive) settings = settingsActive; + else settings = settingsInactive; + + } + + if(isSettingsActive){ + + GUI.Box(new Rect(initVarX+(box.height)*6, initVarY-menu.width, menu.width, menu.height), menu, ""); + + GUI.Button ( new Rect( initVarX+(box.height)*6+10, initVarY-captions.width-20, captions.width, captions.height ), captions, "" ); + + if( isCaptionsActive ){ + if( GUI.Button ( new Rect( initVarX+(box.height)*6+50, initVarY-captions.width-10, captionsActive.width, captionsActive.height ), captionsActive, "" ) ){ + isCaptionsActive = !isCaptionsActive; + } + }else{ + if( GUI.Button ( new Rect( initVarX+(box.height)*6+50, initVarY-captions.width-10, captionsInactive.width, captionsInactive.height ), captionsInactive, "" )){ + isCaptionsActive = !isCaptionsActive; + } + } + + + //if( GUI.Button ( new Rect( 10, 10, resize.width, resize.height ), resize, "" ) ){ + GUI.Button ( new Rect( initVarX+(box.height)*6+resize.width+20, (initVarY-captions.width*2-45+(resolucao.height)), resolucao.width, resolucao.height ), resolucao, "" ); + if( GUI.Button ( new Rect( initVarX+(box.height)*6+10, (initVarY-captions.width*2-40), resize.width, resize.height ), resize, "" ) ){ + + switch(Screen.width){ + + case 640: + Screen.SetResolution(800, 600, false); break; + case 800: + Screen.SetResolution(1024, 768, false); break; + case 1024: + Screen.SetResolution(640, 480, false); break; + default: + Screen.SetResolution(640, 480, false); break; + + } + + //initVarX = ((Screen.width/2)-(box.width/2)); + //initVarY = ((Screen.height)-(box.height)-10); + + } + + + } + + + + + + + { //INIT_CAPTIONS + + GUIStyle myLabelStyle = new GUIStyle(GUI.skin.label); + myLabelStyle.fontSize = 30; + myLabelStyle.alignment = TextAnchor.UpperCenter; + + + ShadowAndOutline.DrawOutline( new Rect(0, initVarY-35, Screen.width, Screen.height), GetCurrentPlayingAnimationClip( ), myLabelStyle, Color.black, Color.yellow, 3); + + } //FINISH_CAPTIONS + + + + + + if( GUI.Button ( new Rect( 10, 10, 100, 50 ), "DEBUGGER" ) ){//BOTAO DE TESTE + + int version = 1; + + StartCoroutine( bundleCatch(glosa.ToLower(), version) ); + //StartCoroutine( bundleCatch("abacate", version) ); + + + }//BOTAO DE TESTE + + }//onGui + + + + + IEnumerator bundleCatch( String token, int version ){ string BaseURL = "http://192.168.0.108:8000/"; + + WWW www = WWW.LoadFromCacheOrDownload(BaseURL+token, version); + yield return www; + if (www.error != null) throw new Exception("Erro no WWW! Se liga nego: " + www.error); + + UnityEngine.Object[] bundleBaixado = www.assetBundle.LoadAllAssets(); + + foreach(UnityEngine.Object animacao in bundleBaixado){ + + GetComponent().AddClip(animacao as AnimationClip, animacao.name); + + Debug.Log(animacao.name+" - "+animacao.GetType()); + + GetComponent().CrossFadeQueued(animacao.name, 0.6f, QueueMode.CompleteOthers); + + } + + + + //playFromFile(); +// AssetBundle bundle = www.assetBundle.LoadAsset(bundleBaixado[0].name); + + + + } + + +} \ No newline at end of file diff --git a/Assets/Scripts/RemoteScript.cs.meta b/Assets/Scripts/RemoteScript.cs.meta new file mode 100644 index 0000000..ebf268f --- /dev/null +++ b/Assets/Scripts/RemoteScript.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 413fd4185617d03479da29306f1017ea +timeCreated: 1435591608 +licenseType: Pro +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/WebScript.cs b/Assets/Scripts/WebScript.cs new file mode 100644 index 0000000..087d035 --- /dev/null +++ b/Assets/Scripts/WebScript.cs @@ -0,0 +1,237 @@ +//Log Dir http://docs.unity3d.com/Manual/LogFiles.html +using UnityEngine; +using System.Collections; +using System.Collections.Generic; +using System; +using System.Runtime.InteropServices; + + +public class WebScript : MonoBehaviour { + +public string hover; + + public Texture + play, stop, repeat, + fast, slow, + box, menu, + captions, captionsActive, captionsInactive, + resize, resolucao; + + + public float initVarX, initVarY; + public float hSliderValue; + + Boolean isCaptionsActive = false; + + string alfabeto = "0123456789,ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + string stringPre; string[] stringPos; + string aniName = ""; AnimationClip aniClip; + + + string GetCurrentPlayingAnimationClip( ){ + + if(isCaptionsActive){ + + foreach(AnimationState anim in GetComponent()){ + + //Debug.Log(anim.name); + + + if( GetComponent().IsPlaying( anim.name ) ){ + + if(anim.name.Split(' ')[0].Equals("_default")) + return null; + + return anim.name.Split(' ')[0]; + // return anim.name.Split(' '); + + } + + }//foreach + + } + + return null; + + } + + + + void loadIcons(){ + + captions = (Texture) Resources.Load("buttons/Subtitle", typeof(Texture)); + //play = (Texture) Resources.Load("buttons/Play", typeof(Texture)); + repeat = (Texture) Resources.Load("buttons/Repeat", typeof(Texture)); + stop = (Texture) Resources.Load("buttons/Stop", typeof(Texture)); + fast = (Texture) Resources.Load("buttons/Fast", typeof(Texture)); + slow = (Texture) Resources.Load("buttons/Slow", typeof(Texture)); + + box = (Texture) Resources.Load("buttons/_Barra", typeof(Texture)); + + menu = (Texture) Resources.Load("buttons/MenuConfig", typeof(Texture)); + captions = (Texture) Resources.Load("buttons/Subtitle", typeof(Texture)); + resize = (Texture) Resources.Load("buttons/Resolution", typeof(Texture)); + resolucao = (Texture) Resources.Load("buttons/Resolucao", typeof(Texture)); + captionsActive = (Texture) Resources.Load("buttons/CaptionsActive", typeof(Texture)); + captionsInactive = (Texture) Resources.Load("buttons/CaptionsInactive", typeof(Texture)); + + initVarX = ((Screen.width/2)-(box.width/2)); + initVarY = ((Screen.height)-(box.height)-10); + + } + + void Start( ){ + + hSliderValue = 1.7f; + loadIcons(); + addAlpha( ); + Application.ExternalCall("onLoadPlayer"); + + } + + + void addAlpha( ){ + + foreach( char letter in alfabeto ){ + + aniClip = Resources.Load ("alpha/"+letter); + if( aniClip ) GetComponent().AddClip(aniClip, ""+letter); + else Debug.Log("Anim "+aniName+" not found"); + + } + }//addAlpha + + + + void animStop( ){ + + GetComponent().Stop( ); + aniClip = Resources.Load("anims/_default"); + GetComponent().CrossFadeQueued("_default", 0.6F, QueueMode.CompleteOthers, PlayMode.StopAll ); + + + } + + + void updateGuiElements(){ + + initVarX = ((Screen.width/2)-(box.width/2)); + initVarY = ((Screen.height)-(box.height)-10); + + } + + void Update( ){ + +// if( hover == "play" ) +// Debug.Log( hover ); + + updateGuiElements(); + foreach(AnimationState anim in GetComponent()) anim.speed = hSliderValue; + + } + + + public string glosa; + + public void catchGlosa( String glosa ){ + + animStop( ); + this.glosa = " _default "+glosa+" _default "; + playFromWEB(); + + } + + void playFromWEB(){ + + Debug.Log( "Running on "+Application.platform ); //if( Application.platform == RuntimePlatform.OS ) + + GetComponent().Stop( ); + + stringPos = glosa.Split(' '); + + foreach( string aniName in stringPos ){ + aniClip = Resources.Load("anims/"+aniName); + + if( aniClip ){ + + GetComponent().AddClip(aniClip, aniName); + GetComponent().CrossFadeQueued( aniName, 0.6F, QueueMode.CompleteOthers );//0.4 + GetComponent().RemoveClip( aniName ); + + }else + foreach(char letter in aniName) + GetComponent().CrossFadeQueued(""+letter, 0.6F, QueueMode.CompleteOthers); + + }//foreach string aniName + + aniClip = Resources.Load("anims/_default"); + GetComponent().AddClip(aniClip, "_default"); + + } + + + + void OnGUI() { /* GUI.backgroundColor = Color.clear; */ + /* Box onde ficarao os botoes; */ GUI.Box( new Rect ( initVarX, initVarY, box.width, box.height), box, "" ); + + + if( GUI.Button (new Rect(initVarX+(box.height/4)+10 , initVarY+(repeat.width/2), repeat.width, repeat.height), new GUIContent("", repeat, "repeat"), "" )){ + + playFromWEB(); + } + + + //hover = GUI.tooltip; + + + if( GUI.Button ( new Rect( initVarX+(box.height)+15, initVarY+(stop.width/2), stop.height, stop.height ), stop, "" ) ) + animStop( ); + + + { //INIT_SPEED + + GUI.DrawTexture(new Rect( initVarX+(box.height)*2, initVarY+(slow.width/2), slow.height, slow.height ), slow); + + hSliderValue = GUI.HorizontalSlider ( new Rect( initVarX+(box.height)*2+(slow.width)+5, initVarY+(slow.width/2)+(slow.width/3), box.height*3.5f, box.height/4 ), hSliderValue, 0.0F, 2.0F ); + + GUI.DrawTexture(new Rect( initVarX+(box.height)*6+15, initVarY+(fast.width/2), fast.height, fast.height ), fast); + + } //FINISH_SPEED + + + + /** + * + * BOTAO DE LEGENDA + * + **/ + if (GUI.Button(new Rect(initVarX+(box.height)*7, initVarY+(slow.width/2), captions.width, captions.height), captions, "")){ + + isCaptionsActive = !isCaptionsActive; + + } + + + { //INIT_CAPTIONS + + GUIStyle myLabelStyle = new GUIStyle(GUI.skin.label); + myLabelStyle.fontSize = 30; + myLabelStyle.alignment = TextAnchor.UpperCenter; + + + ShadowAndOutline.DrawOutline( new Rect(0, initVarY-35, Screen.width, Screen.height), GetCurrentPlayingAnimationClip( ), myLabelStyle, Color.black, Color.yellow, 3); + + } //FINISH_CAPTIONS + + + //if( GUI.Button ( new Rect( 10, 10, 100, 100 ), "DEBUGGER" ) ){//BOTAO DE TESTE }//BOTAO DE TESTE + + + + }//onGui + + void OnApplicationQuit() { + + } + +} \ No newline at end of file diff --git a/Assets/Scripts/WebScript.cs.meta b/Assets/Scripts/WebScript.cs.meta new file mode 100644 index 0000000..bed8c56 --- /dev/null +++ b/Assets/Scripts/WebScript.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 1028c034d96246149ad30dbf7eed6258 +timeCreated: 1435591608 +licenseType: Pro +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: -- libgit2 0.21.2