PlayerManager.cs
4.51 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
//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 PlayerManager : MonoBehaviour {
public InputField INFIELD;
public static float hSliderValue = 1.1f;
public static string alphabet = "0123456789,ABCDEFGHIJKLMNOPQRSTUVWXYZ";
public static String[] stringPos = {"_default"};//vetor que sera usado para quebrar a glosa
// Guarda os nomes das palavras ja carregadas
HashSet<string> loadedAssetBundles = new HashSet<string>();
// Guarda os nomes das palavras que nao tem assetbundle
HashSet<string> nonexistentAssetBundles = new HashSet<string>();
// Contem todos os nomes das anims na ordem que serao reproduzidas
public static Queue<string> playList = new Queue<string>();
AnimationClip aniClip;
public string glosa = " _default ";
GameObject AVATAR;
Animation COMPONENT_ANIMATION;
//Primeiro metodo que o player executa
void Start( ){
Application.ExternalCall("onLoadPlayer");//var onLoadPlayer = function(){}
AVATAR = GameObject.FindGameObjectWithTag("avatar");//referencia para o avatar
COMPONENT_ANIMATION = AVATAR.GetComponent<Animation>();//referencia para o componente animador do avatar
addAlpha( );//executa o metodo que adiciona alfabeto e numerais
}
void Update(){
if(COMPONENT_ANIMATION.isPlaying)
foreach(AnimationState anim in COMPONENT_ANIMATION)
anim.speed = hSliderValue;
}
//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 alphabet ){
aniClip = Resources.Load<AnimationClip> ("ANIMS/"+letter);
if( aniClip ) COMPONENT_ANIMATION.AddClip(aniClip, ""+letter);
else Debug.Log("Anim "+letter+" not found");
}
}//addAlpha
public void stop_animations( ){
COMPONENT_ANIMATION.Stop();
aniClip = Resources.Load<AnimationClip>("ANIMS/_default");
COMPONENT_ANIMATION.CrossFade("_default", 0.6F, PlayMode.StopAll );
}
public void catchGlosa(){
this.glosa = " _default "+glosa+" _default ";
}
public void start_inputfield_web_play( ){
int version = 1;
StartCoroutine(webPlay(INFIELD.text.ToUpper(), version));
}
public void start_web_play( ){
catchGlosa();
int version = 1;
StartCoroutine(webPlay(INFIELD.text.ToUpper(), version));
}
IEnumerator webPlay(String glosa, int version) {
stop_animations( );
Subtitles.WORDS.Clear();
foreach( char letter in alphabet ) Subtitles.WORDS.Add(""+letter);
stringPos = glosa.Split(' ');
String BaseURL = "http://150.165.205.9/anims/WEBGL/";
//aniClip = www.assetBundle.mainAsset as AnimationClip;
COMPONENT_ANIMATION.CrossFadeQueued("_default", 0.6F, QueueMode.CompleteOthers);
foreach(string aniName in stringPos){
try{
if (String.IsNullOrEmpty(aniName)) continue;
}catch(Exception e){ Debug.Log(e+" :: NotNullNotEmpty"); }
// Se ja estiver carregado: reproduz animaçao
if (loadedAssetBundles.Contains(aniName)){
Subtitles.WORDS.Add(aniName);
COMPONENT_ANIMATION.CrossFadeQueued(aniName, 0.6F, QueueMode.CompleteOthers);
}else if (nonexistentAssetBundles.Contains(aniName)){//se nao estiver, soletra
foreach (char letter in aniName)
COMPONENT_ANIMATION.CrossFadeQueued(""+letter, 0.6F, QueueMode.CompleteOthers);
}else{
WWW www = WWW.LoadFromCacheOrDownload(BaseURL+aniName, version);
yield return www;
if (www.error != null){//soletra se o ww inexistir
//throw new Exception("Erro no WWW: " + www.error);
Debug.Log("Sinal nao disponivel em banco de sinais. SOLETRANDO "+aniName);
foreach (char letter in aniName)
COMPONENT_ANIMATION.CrossFadeQueued(""+letter, 0.6F, QueueMode.CompleteOthers);
nonexistentAssetBundles.Add(aniName);
continue;
}else{
//Debug.Log (www.assetBundle.name);
aniClip = www.assetBundle.mainAsset as AnimationClip;
if (aniClip){
COMPONENT_ANIMATION.AddClip(aniClip, aniName);
COMPONENT_ANIMATION.CrossFadeQueued(aniName, 0.6F, QueueMode.CompleteOthers); // 0.4
Subtitles.WORDS.Add(aniName); loadedAssetBundles.Add(aniName);
}else{
foreach (char letter in aniName)
COMPONENT_ANIMATION.CrossFadeQueued("" + letter, 0.6F, QueueMode.CompleteOthers);
}
}
}//else
}//foreach
COMPONENT_ANIMATION.CrossFadeQueued("_default", 0.6F, QueueMode.CompleteOthers);
}
}