ENFIN! Foutue vidéos

This commit is contained in:
Florent Guiotte 2018-03-14 22:50:45 +01:00
parent c94adb2d6c
commit 28750f4d94
5 changed files with 59 additions and 23 deletions

View File

@ -42,17 +42,24 @@ public class BikeManager : MonoBehaviour {
taco = gameObject.AddComponent<RAWTachometer>(); taco = gameObject.AddComponent<RAWTachometer>();
taco.SetPlayer(playerID); taco.SetPlayer(playerID);
normalSpeed = distanceToRun / gm.GetRaceNormalTime(); normalSpeed = distanceToRun / gm.GetRaceNormalTime();
} }
// Update is called once per frame // Update is called once per frame
void Update () { void Update () {
Speed = taco.GetSpeed(); if (taco.GetDistanceRun() < distanceToRun) {
vm.speed = Speed / normalSpeed; Speed = taco.GetSpeed();
vm.speed = Speed / normalSpeed;
} else {
// Player finished
vm.speed = 1f;
}
} }
public bool LoadingComplete() {
return vm.setUp;
}
void FixedUpdate() { void FixedUpdate() {
} }

View File

@ -5,8 +5,10 @@ using UnityEngine.SceneManagement;
public enum States { public enum States {
Menu = 0, Menu = 0,
RaceSetup = 1, LoadingScene = 5,
Race = 2 LoadingVideo = 10,
RaceSetup = 15,
Race = 20
} }
public class GameManager : MonoBehaviour { public class GameManager : MonoBehaviour {
@ -33,9 +35,10 @@ public class GameManager : MonoBehaviour {
if (_instance != null && _instance != this) { if (_instance != null && _instance != this) {
Debug.Log("WARNING: Other instance of GameManager found."); Debug.Log("WARNING: Other instance of GameManager found.");
Destroy(gameObject); Destroy(gameObject);
} else { return;
_instance = this; }
}
_instance = this;
// Don't destroy when loading new scene // Don't destroy when loading new scene
DontDestroyOnLoad(transform.gameObject); DontDestroyOnLoad(transform.gameObject);
@ -112,20 +115,29 @@ public class GameManager : MonoBehaviour {
// TODO: Remove once menus are ok // TODO: Remove once menus are ok
void Update() { void Update() {
if (Input.GetButtonDown("SubmitP1")) { if (Input.GetButtonDown("SubmitP1")) {
SetSkins(1, 0); SetSkins(0, 1);
LaunchRace(); LaunchRace();
} }
if (_status == States.LoadingVideo) {
Debug.Log(bm1.LoadingComplete() + " " + bm2.LoadingComplete());
if (bm1.LoadingComplete() && bm2.LoadingComplete()) {
Debug.Log("Videos are set up and ready to go!");
_status = States.RaceSetup;
StartCoroutine(SetupRace());
}
}
} }
public void LaunchRace() { public void LaunchRace() {
_status = States.RaceSetup; _status = States.LoadingScene;
StartCoroutine(LoadGameScene()); StartCoroutine(LoadGameScene());
} }
void OnLevelFinishedLoading(Scene scene, LoadSceneMode mode) { void OnLevelFinishedLoading(Scene scene, LoadSceneMode mode) {
// TODO: Check game status if (_status == States.LoadingScene) {
if (_status == States.RaceSetup) { Debug.Log("Loading videos");
StartCoroutine(SetupRace()); _status = States.LoadingVideo;
} }
} }

View File

@ -7,14 +7,17 @@ public class VideoManager : MonoBehaviour {
private VideoPlayer videoPlayer; private VideoPlayer videoPlayer;
public float speed {get; set; } public float speed {get; set; }
public bool setUp = false;
private int skinID;
public void SetSkin(int playerID) { public void SetSkin(int playerID) {
videoPlayer = gameObject.AddComponent<VideoPlayer>(); videoPlayer = gameObject.AddComponent<VideoPlayer>();
var gm = GameManager.Instance; var gm = GameManager.Instance;
int id = gm.GetSkins(playerID); skinID = gm.GetSkins(playerID);
videoPlayer.url = Application.streamingAssetsPath + "/" + id + ".webm"; videoPlayer.url = Application.streamingAssetsPath + "/" + skinID + ".webm";
Debug.Log("Video Stats:" + Debug.Log("Video Stats:" +
" canSetTime: " + videoPlayer.canSetTime + " canSetTime: " + videoPlayer.canSetTime +
@ -23,11 +26,25 @@ public class VideoManager : MonoBehaviour {
videoPlayer.skipOnDrop = true; videoPlayer.skipOnDrop = true;
videoPlayer.isLooping = false; videoPlayer.isLooping = false;
videoPlayer.playOnAwake = false; videoPlayer.playOnAwake = false;
videoPlayer.prepareCompleted += VideoReady;
videoPlayer.Prepare(); videoPlayer.Prepare();
}
float startTime = gm.GetVideoEnd(id) - gm.GetRaceNormalTime(); void VideoReady(VideoPlayer source) {
Debug.Log("Ok ima set");
videoPlayer.prepareCompleted -= VideoReady;
var gm = GameManager.Instance;
float startTime = gm.GetVideoEnd(skinID) - gm.GetRaceNormalTime();
videoPlayer.seekCompleted += VideoSetup;
videoPlayer.time = startTime; videoPlayer.time = startTime;
}
void VideoSetup(VideoPlayer source) {
videoPlayer.seekCompleted -= VideoSetup;
videoPlayer.Play(); videoPlayer.Play();
setUp = true;
} }
void Update () { void Update () {

View File

@ -7,8 +7,8 @@
NombreDeCapteurs: Le nombre de capteurs placés sur la roue du vélo NombreDeCapteurs: Le nombre de capteurs placés sur la roue du vélo
", ",
"Course": { "Course": {
"Distance": 400, "Distance": 200,
"TempsNormal": 30 "TempsNormal": 15
}, },
"Vélos": { "Vélos": {
"Joueur1": { "Joueur1": {
@ -21,7 +21,7 @@
} }
}, },
"Vidéos": { "Vidéos": {
0: {"Fin": 25}, 0: {"Fin": 67},
1: {"Fin": 25}, 1: {"Fin": 25},
2: {"Fin": 25}, 2: {"Fin": 25},
3: {"Fin": 25}, 3: {"Fin": 25},

View File

@ -5,12 +5,12 @@ EditorBuildSettings:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
serializedVersion: 2 serializedVersion: 2
m_Scenes: m_Scenes:
- enabled: 1
path: Assets/Scenes/Menus.unity
guid: 14eaf8d7877bf4d50a0bed2739d2bf96
- enabled: 1 - enabled: 1
path: Assets/Scenes/GameManagerTest.unity path: Assets/Scenes/GameManagerTest.unity
guid: 3bf6872fcde3f48108b47c2eaa97b6f7 guid: 3bf6872fcde3f48108b47c2eaa97b6f7
- enabled: 1
path: Assets/Scenes/Menus.unity
guid: 14eaf8d7877bf4d50a0bed2739d2bf96
- enabled: 1 - enabled: 1
path: Assets/Scenes/GameScene.unity path: Assets/Scenes/GameScene.unity
guid: 8541a1132a4264d69b949d040e7244a4 guid: 8541a1132a4264d69b949d040e7244a4