Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.Video;
- using UnityEngine.UI;
- using UnityEngine.SceneManagement;
- public class WorldSpaceVideoLoading: MonoBehaviour {
- [Header("Загружаемая сцена")]
- public int sceneIndex;
- [Header("Остальные объекты")]
- public GameObject loadingScreen;
- //public GameObject main_menu;
- public Text progressText;
- public GameObject textLight;
- public GameObject textPrepare;
- [Header("Видеоклипы")]
- //[Tooltip("Кидаем сюда видео")]
- //public VideoClip[] videoClips;
- //[Space(10)]
- private VideoPlayer videoPlayer;
- private AudioSource audioSource;
- private int videoClipIndex;
- bool isDone;
- public bool isPrepared{ get{ return videoPlayer.isPrepared;}}
- void OnEnable(){
- videoPlayer.loopPointReached += loopPointReached;
- videoPlayer.prepareCompleted += prepareCompleted;
- }
- void OnDisable(){
- videoPlayer.loopPointReached -= loopPointReached;
- videoPlayer.prepareCompleted -= prepareCompleted;
- }
- void loopPointReached(VideoPlayer v){
- textLight.SetActive (false);
- StartCoroutine (StartCor (sceneIndex));
- }
- void prepareCompleted(VideoPlayer v){
- Debug.Log ("Video player finished preparing");
- isDone = false;
- }
- void Awake ()
- {
- videoPlayer = GetComponent<VideoPlayer> ();
- }
- void Start ()
- {
- audioSource = gameObject.AddComponent<AudioSource>();
- //videoPlayer.clip = videoClips[0];
- AudioPlay ();
- if (!isPrepared) {
- textPrepare.SetActive (true);
- return;
- } else {
- textPrepare.SetActive (false);
- videoPlayer.Play ();
- }
- }
- void Update ()
- {
- if (Input.anyKey) {
- StartCoroutine (StartCor (sceneIndex));
- }
- if (videoPlayer.isPlaying) {
- textLight.SetActive (true);
- AudioPlay ();
- } else {
- textLight.SetActive (false);
- }
- }
- public void AudioPlay(){
- videoPlayer.audioOutputMode = VideoAudioOutputMode.AudioSource;
- videoPlayer.EnableAudioTrack(0, true);
- videoPlayer.SetTargetAudioSource(0, audioSource);
- }
- IEnumerator StartCor(int sceneIndex)
- {
- AsyncOperation async = SceneManager.LoadSceneAsync(sceneIndex);
- loadingScreen.SetActive (true);
- while (!async.isDone)
- {
- float progress = async.progress / .9f;
- progressText.text = string.Format("Пожалуйста подождите... {0:0}%", progress * 100);
- yield return null;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement