PlayerManager.cs
2.79 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
//Debug.Log Dir http://docs.unity3d.com/Manual/Debug.LogFiles.html
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System;
using System.IO;
using System.Text;
using System.Runtime.InteropServices;
using UnityEngine.UI;
public class PlayerManager : GenericPlayerManager {
//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 Button playButton;
public Sprite pauseSprite;
public Sprite playSprite;
public Button stopButton;
private Graphic stopButtonGraphic;
private Color enabledAlpha = new Color(1F, 1F, 1F, 1F);
private Color disabledAlpha = new Color(1F, 1F, 1F, 0.5F);
private string[] randomAnimationNames = new string[] {
"[OLA]",
//"[OI]",
"[IAE]"
};
//InputField INFIELD;
//Primeiro metodo que o player executa
public override void Start()
{
Debug.Log("Datapath: "+Application.dataPath);
//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()); }
stopButtonGraphic = stopButton.GetComponent<Graphic>();
stopButtonGraphic.color = disabledAlpha;
base.setRandomAnimations(new RandomAnimations(this, randomAnimationNames, 2, 1), randomAnimationNames);
base.Start();
}
//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 string catchGlosa()
{
return base.glosa = Marshal.PtrToStringAnsi ( coreExecute( ) );
}
public void start_local_play()
{
this.catchGlosa();
base.play();
}
public void start_local_play(string glosa)
{
if (base.isLoading() || base.isPlaying())
base.stop_animations();
base.play(glosa);
}
protected override WWW loadAssetBundle(string aniName)
{
string assetPath = Application.dataPath + "/Bundles/" + aniName;
if ( ! File.Exists(assetPath))
return null;
try {
WWW www = new WWW("file://" + assetPath);
return www;
} catch (Exception e) {
Debug.Log(e);
}
return null;
}
protected override void onPlayingStateChange()
{
if (base.isPlaying())
{
playButton.GetComponent<Image>().sprite = base.isPaused()
? playSprite : pauseSprite;
stopButtonGraphic.color = enabledAlpha;
}
else
{
playButton.GetComponent<Image>().sprite = playSprite;
stopButtonGraphic.color = disabledAlpha;
}
}
void OnApplicationQuit()
{
try {
Debug.Log("Finalizando: " + coreFinalize());
} catch (Exception e) {
Debug.Log(e.ToString());
}
}
}