Advertisement
Creativeeart

Untitled

Mar 1st, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.40 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.Video;
  5. using UnityEngine.UI;
  6. using UnityEngine.SceneManagement;
  7. public class WorldSpaceVideoLoading: MonoBehaviour {
  8.     [Header("Загружаемая сцена")]
  9.     public int sceneIndex;
  10.     [Header("Остальные объекты")]
  11.     public GameObject loadingScreen;
  12.     //public GameObject main_menu;
  13.     public Text progressText;
  14.     public GameObject textLight;
  15.     public GameObject textPrepare;
  16.     [Header("Видеоклипы")]
  17.     //[Tooltip("Кидаем сюда видео")]
  18.     //public VideoClip[] videoClips;
  19.     //[Space(10)]
  20.     private VideoPlayer videoPlayer;
  21.     private AudioSource audioSource;
  22.     private int videoClipIndex;
  23.     bool isDone;
  24.     public bool isPrepared{ get{ return videoPlayer.isPrepared;}}
  25.     void OnEnable(){
  26.         videoPlayer.loopPointReached += loopPointReached;
  27.         videoPlayer.prepareCompleted += prepareCompleted;
  28.     }
  29.     void OnDisable(){
  30.         videoPlayer.loopPointReached -= loopPointReached;
  31.         videoPlayer.prepareCompleted -= prepareCompleted;
  32.     }
  33.     void loopPointReached(VideoPlayer v){
  34.         textLight.SetActive (false);
  35.         StartCoroutine (StartCor (sceneIndex));
  36.     }
  37.     void prepareCompleted(VideoPlayer v){
  38.         Debug.Log ("Video player finished preparing");
  39.         isDone = false;
  40.     }
  41.     void Awake ()
  42.     {
  43.         videoPlayer = GetComponent<VideoPlayer> ();
  44.     }
  45.  
  46.     void Start ()
  47.     {
  48.         audioSource = gameObject.AddComponent<AudioSource>();
  49.         //videoPlayer.clip = videoClips[0];
  50.         AudioPlay ();
  51.         if (!isPrepared) {
  52.             textPrepare.SetActive (true);
  53.             return;
  54.         } else {
  55.             textPrepare.SetActive (false);
  56.             videoPlayer.Play ();
  57.         }
  58.     }
  59.  
  60.     void Update ()
  61.     {
  62.         if (Input.anyKey) {
  63.             StartCoroutine (StartCor (sceneIndex));
  64.         }
  65.         if (videoPlayer.isPlaying) {
  66.             textLight.SetActive (true);
  67.             AudioPlay ();
  68.         } else {
  69.             textLight.SetActive (false);
  70.         }
  71.     }
  72.  
  73.  
  74.     public void AudioPlay(){
  75.         videoPlayer.audioOutputMode = VideoAudioOutputMode.AudioSource;
  76.         videoPlayer.EnableAudioTrack(0, true);
  77.         videoPlayer.SetTargetAudioSource(0, audioSource);
  78.     }
  79.  
  80.     IEnumerator StartCor(int sceneIndex)
  81.     {
  82.         AsyncOperation async = SceneManager.LoadSceneAsync(sceneIndex);
  83.         loadingScreen.SetActive (true);
  84.         while (!async.isDone)
  85.         {
  86.             float progress = async.progress / .9f;
  87.             progressText.text = string.Format("Пожалуйста подождите... {0:0}%", progress * 100);
  88.             yield return null;
  89.         }
  90.  
  91.     }
  92.  
  93.  
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement