InspectorScript_old.cs
7.29 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
//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<Animation>();//referencia para o componente animador do avatar
INFIELD = gameObject.GetComponent<InputField>();//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<AnimationClip> ("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<AnimationClip>("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<AnimationClip>("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<AnimationClip>("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<AnimationClip>("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<AnimationClip>("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());}
}
}