Documentation for the Unity C# Library
Loading...
Searching...
No Matches
VideoLoader.cs
Go to the documentation of this file.
1using System;
2using System.Collections;
3using System.Collections.Generic;
4using UnityEngine;
5using UnityEngine.Events;
6using UnityEngine.Video;
7
8namespace PixoVR.Login
9{
10 [RequireComponent(typeof(VideoPlayer))]
11 public class VideoLoader : MonoBehaviour
12 {
13 [SerializeField] private VideoPlayer videoPlayer;
14 [SerializeField] private bool autoFocus = true;
15 public UnityEvent OnFinish = new UnityEvent();
16 private Transform canvas;
17 [SerializeField] private GameObject loginscreen;
18
19 IEnumerator Start()
20 {
21 yield return new WaitForSeconds(2f);
23 canvas = transform.GetChild(0);
24 if (autoFocus)
25 {
26 Vector3 pos = Camera.main.transform.forward * 5 + Camera.main.transform.position +
27 Camera.main.transform.up * 1.5f;
28 pos.y = 1.5f;
29 this.transform.position = pos;
30 transform.LookAt(Camera.main.transform);
31 Quaternion rot = this.transform.rotation;
32 rot.eulerAngles = new Vector3(0, rot.eulerAngles.y, 0);
33 this.transform.rotation = rot;
34 loginscreen.transform.SetPositionAndRotation(this.transform.position, this.transform.rotation);
35 }
36
37 canvas.gameObject.SetActive(true);
38 if (!videoPlayer)
39 {
40 videoPlayer = GetComponent<VideoPlayer>();
41 }
42
43 OnFinish.AddListener(() => { loginscreen.SetActive(true); });
44
45 StartCoroutine(VideoDelay(() => { OnFinish.Invoke(); }));
46 }
47
48 private IEnumerator VideoDelay(Action onPromoEnded)
49 {
50 videoPlayer.Prepare();
51 while (!videoPlayer.isPrepared)
52 {
53 yield return null;
54 }
55
56 videoPlayer.Play();
57 while (videoPlayer.isPlaying)
58 {
59 yield return null;
60 }
61
62 onPromoEnded?.Invoke();
63 canvas.gameObject.SetActive(false);
64 Destroy(this.gameObject, 2);
65 }
66 }
67}
bool autoFocus
[SerializeField]
IEnumerator VideoDelay(Action onPromoEnded)
GameObject loginscreen
[SerializeField]
VideoPlayer videoPlayer
[SerializeField]