WebScript.cs
5.76 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
//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<Animation>()){
//Debug.Log(anim.name);
if( GetComponent<Animation>().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<AnimationClip> ("alpha/"+letter);
if( aniClip ) GetComponent<Animation>().AddClip(aniClip, ""+letter);
else Debug.Log("Anim "+aniName+" not found");
}
}//addAlpha
void animStop( ){
GetComponent<Animation>().Stop( );
aniClip = Resources.Load<AnimationClip>("anims/_default");
GetComponent<Animation>().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<Animation>()) 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<Animation>().Stop( );
stringPos = glosa.Split(' ');
foreach( string aniName in stringPos ){
aniClip = Resources.Load<AnimationClip>("anims/"+aniName);
if( aniClip ){
GetComponent<Animation>().AddClip(aniClip, aniName);
GetComponent<Animation>().CrossFadeQueued( aniName, 0.6F, QueueMode.CompleteOthers );//0.4
GetComponent<Animation>().RemoveClip( aniName );
}else
foreach(char letter in aniName)
GetComponent<Animation>().CrossFadeQueued(""+letter, 0.6F, QueueMode.CompleteOthers);
}//foreach string aniName
aniClip = Resources.Load<AnimationClip>("anims/_default");
GetComponent<Animation>().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() {
}
}