54 lines
1.4 KiB
C#
54 lines
1.4 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.Video;
|
|
|
|
public class VideoManager : MonoBehaviour {
|
|
|
|
private VideoPlayer videoPlayer;
|
|
public float speed {get; set; }
|
|
public bool setUp = false;
|
|
|
|
private int skinID;
|
|
|
|
public void SetSkin(int playerID) {
|
|
videoPlayer = gameObject.AddComponent<VideoPlayer>();
|
|
|
|
var gm = GameManager.Instance;
|
|
|
|
skinID = gm.GetSkins(playerID);
|
|
videoPlayer.url = Application.streamingAssetsPath + "/" + skinID + ".webm";
|
|
|
|
Debug.Log("Video Stats:" +
|
|
" canSetTime: " + videoPlayer.canSetTime +
|
|
" canSetSkipOnDrop: " + videoPlayer.canSetSkipOnDrop);
|
|
|
|
videoPlayer.skipOnDrop = true;
|
|
videoPlayer.isLooping = false;
|
|
videoPlayer.playOnAwake = false;
|
|
videoPlayer.prepareCompleted += VideoReady;
|
|
videoPlayer.Prepare();
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
void VideoSetup(VideoPlayer source) {
|
|
videoPlayer.seekCompleted -= VideoSetup;
|
|
videoPlayer.Play();
|
|
setUp = true;
|
|
}
|
|
|
|
void Update () {
|
|
videoPlayer.playbackSpeed = speed;
|
|
}
|
|
}
|