//Log Dir http://docs.unity3d.com/Manual/LogFiles.html using UnityEngine; using System.Collections; using System.Collections.Generic; using System; using System.IO; using System.Runtime.InteropServices; using UnityEngine.UI; public class InspectorScript_old : MonoBehaviour { //Importacao de metodos de instancia do core via DLLs [DllImport ("CorePlugin")] public static extern int coreInitialize(); [DllImport ("CorePlugin")] private static extern IntPtr coreExecute(); [DllImport ("CorePlugin")] public static extern int coreFinalize(); public static float hSliderValue = 1.1f; public Boolean isCaptionsActive = true; string alfabeto = "0123456789,ABCDEFGHIJKLMNOPQRSTUVWXYZ"; public static string[] stringPos = {"_default"};//vetor que sera usado para quebrar a glosa AnimationClip aniClip; public string glosa = " _default "; InputField INFIELD; GameObject ICARO; Animation COMPONENT_ANIMATION; //Primeiro metodo que o player executa void Start( ){ //seta a resolucao inicial da tela Screen.SetResolution(640, 480, false); //metodo que puxa as dlls do core try{ Debug.Log("Inicializando: "+coreInitialize( )); }catch(Exception e){ Debug.Log (e.ToString());} ICARO = GameObject.FindGameObjectWithTag("avatar");//referencia para o avatar COMPONENT_ANIMATION = ICARO.GetComponent();//referencia para o componente animador do avatar INFIELD = gameObject.GetComponent();//campo de texto para digitar a glosa pra testes addAlpha( );//executa o metodo que adiciona alfabeto e numerais } //define a velocidade das animacoes com base no slider da GUI public void setSlider( float x ){ hSliderValue = x; } //adiciona alfabeto e numerais ao componente animador do avatar void addAlpha( ){ foreach( char letter in alfabeto ){ aniClip = Resources.Load ("ANIMS/alpha/"+letter); if( aniClip ) COMPONENT_ANIMATION.AddClip(aniClip, ""+letter); else Debug.Log("Anim "+letter+" not found"); } }//addAlpha //este metodo altera a velocidade de todas as animacoes durante a execucao do player void Update( ){ foreach(AnimationState anim in COMPONENT_ANIMATION) anim.speed = hSliderValue; } public void animStop( ){ COMPONENT_ANIMATION.Stop(); aniClip = Resources.Load("ANIMS/anims/_default"); //COMPONENT_ANIMATION.CrossFadeQueued("_default", 0.6F, QueueMode.CompleteOthers, PlayMode.StopAll ); COMPONENT_ANIMATION.CrossFade("_default", 0.6F, PlayMode.StopAll ); } //Aqui, a primeira glosa serve para gerar players para as plataformas suportadas *desktop // a segunda serve para testes com o botao play do canvas // a terceira, para testes com a textbox public void catchGlosa(){ //glosa = " _default "+Marshal.PtrToStringAnsi ( coreExecute( ) )+" _default "; //glosa = " _default "+"ABACATE ABAJUR"+" _default "; glosa = " _default "+INFIELD.text.ToString().ToUpper()+" _default "; } public void corePlay(){ Debug.Log("ReadFromDLL"); Debug.Log( "Running on "+Application.platform ); //if( Application.platform == RuntimePlatform.OS ) animStop(); catchGlosa( ); stringPos = glosa.Split(' '); foreach( string aniName in stringPos ){ aniClip = Resources.Load("ANIMS/anims/"+aniName); if( aniClip ){ COMPONENT_ANIMATION.AddClip(aniClip, aniName); COMPONENT_ANIMATION.CrossFadeQueued( aniName, 0.6F, QueueMode.CompleteOthers );//0.4 //COMPONENT_ANIMATION.CrossFade(aniName, 0.6F ); //COMPONENT_ANIMATION.RemoveClip( aniName ); }else foreach(char letter in aniName) COMPONENT_ANIMATION.CrossFadeQueued(""+letter, 0.6F, QueueMode.CompleteOthers); //COMPONENT_ANIMATION.CrossFade(""+aniName, 0.6F ); }//foreach string aniName aniClip = Resources.Load("ANIMS/anims/_default"); COMPONENT_ANIMATION.AddClip(aniClip, "_default"); } public void closedCaptions( ){ isCaptionsActive = !isCaptionsActive; } void localPlay(){ animStop(); catchGlosa( ); stringPos = glosa.Split(' '); foreach( string aniName in stringPos ){ // Aqui o cara vai carregar o bundle correspondente a aniName da pasta // o nome da pasta deve ser passado por uma URL Application.DataPath < pesquisar isso // ex: catar o bundle para descompactar na url no estilo // catarBundle(String: "Application.DataPath/bundles"+aniName) // depois descompacta como AnimationState e adiciona ao objeto animador, similar ao que era feito e ao que e feito la no // metodo que "funciona" pro web // a pasta deve conter os bundles que estão em 150.165.205.9/anims // SUBSTITUIR ISSO //aniClip = Resources.Load("ANIMS/anims/"+aniName); // isso aqui retorna true se ele realmente carregar o bundle como animationClip if( aniClip ){//e se for verdade deve adicionar tudo ao componente animador onde // aniclip = arquivo carregado de dentro do bundle // aniname = nome do arquivo referente ao sinal COMPONENT_ANIMATION.AddClip(aniClip, aniName); //essas linhas dauqi pra baixo só executam as animacoes. Isso aqui eh equivalente ao metodo GO COMPONENT_ANIMATION.CrossFadeQueued( aniName, 0.6F, QueueMode.CompleteOthers );//0.4 //COMPONENT_ANIMATION.CrossFade(aniName, 0.6F ); //COMPONENT_ANIMATION.RemoveClip( aniName ); }else //NISSO NAO PRECISA MEXER, pois se o bundle nao for encontrado, ainda assim tera que soletrar //e esta abordagem nao sera alterada (por enquanto). foreach(char letter in aniName) COMPONENT_ANIMATION.CrossFadeQueued(""+letter, 0.6F, QueueMode.CompleteOthers); //COMPONENT_ANIMATION.CrossFade(""+aniName, 0.6F ); }//foreach string aniName // aqui so adiciona a pose padrao ao final da glosa. aniClip = Resources.Load("ANIMS/anims/_default"); COMPONENT_ANIMATION.AddClip(aniClip, "_default"); }//metodo exemplo //Daqui pra baixo foi como funcionou o esquema do web public void play( ){ int version = 1; StartCoroutine( bundleCatch(INFIELD.text.ToString().ToUpper(), version) ); } //TOMAR COMO EXEMPLO, esse faz requisicao web IEnumerator bundleCatch( String token, int version ){ string BaseURL = "http://150.165.205.9/anims/"; //esta versao do loop funciona com cache web //por isso tanta enrolacao if(!Caching.IsVersionCached(token, version)){ WWW www = WWW.LoadFromCacheOrDownload(BaseURL+token, version); yield return www;//aguarda terminar o download do www if (www.error != null) throw new Exception("Erro no WWW: " + www.error); UnityEngine.Object[] bundleBaixado = www.assetBundle.LoadAllAssets(); foreach(UnityEngine.Object animacao in bundleBaixado){ //TOKEN EH DIFERENTE DE ANIMACAO.NAME POR CAUSA DO SHARED CACHE COMPONENT_ANIMATION.AddClip(animacao as AnimationClip, token); //repare no AS ANIMATIONCLIP Debug.Log ("adding "+animacao.name+" = "+token); } Debug.Log("nao tinha"); }else Debug.Log("ja tinha"); Debug.Log(token); GO(token); } public void GO(string tok ){ foreach(AnimationState anim in COMPONENT_ANIMATION) Debug.Log(anim.name); COMPONENT_ANIMATION.CrossFadeQueued(tok, 0.6f, QueueMode.CompleteOthers); COMPONENT_ANIMATION.CrossFadeQueued("_default", 0.6f, QueueMode.CompleteOthers); } void OnApplicationQuit() { try{ Debug.Log("Finalizando: "+ coreFinalize( )); }catch(Exception e){Debug.Log(e.ToString());} } }