100 lines
2.4 KiB
C#
100 lines
2.4 KiB
C#
|
using System.Collections;
|
|||
|
using System.Collections.Generic;
|
|||
|
using UnityEngine;
|
|||
|
using UnityEngine.UI;
|
|||
|
using UnityEngine.Video;
|
|||
|
|
|||
|
public class Tutorial : MonoBehaviour
|
|||
|
{
|
|||
|
|
|||
|
//Raw Image to Show Video Images [Assign from the Editor]
|
|||
|
public RawImage image;
|
|||
|
|
|||
|
public VideoClip count_tut;
|
|||
|
public VideoClip set_tut;
|
|||
|
public VideoClip add_tut;
|
|||
|
|
|||
|
private VideoPlayer vp;
|
|||
|
private VideoSource videoSource;
|
|||
|
|
|||
|
//Audio
|
|||
|
private AudioSource audioSource;
|
|||
|
|
|||
|
|
|||
|
// Update is called once per frame
|
|||
|
private void Start() {
|
|||
|
|
|||
|
StartCoroutine(playTutorial());
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
IEnumerator playTutorial()
|
|||
|
{
|
|||
|
//Add VideoPlayer to the GameObject
|
|||
|
vp = gameObject.AddComponent<VideoPlayer>();
|
|||
|
|
|||
|
//Add AudioSource
|
|||
|
audioSource = gameObject.AddComponent<AudioSource>();
|
|||
|
|
|||
|
//Disable Play on Awake for both Video and Audio
|
|||
|
vp.playOnAwake = false;
|
|||
|
audioSource.playOnAwake = false;
|
|||
|
|
|||
|
vp.source = VideoSource.VideoClip;
|
|||
|
|
|||
|
vp.audioOutputMode = VideoAudioOutputMode.AudioSource;
|
|||
|
//Assign the Audio from Video to AudioSource to be played
|
|||
|
vp.EnableAudioTrack(0, true);
|
|||
|
vp.SetTargetAudioSource(0, audioSource);
|
|||
|
|
|||
|
//We want to play from video clip not from url
|
|||
|
vp.clip = count_tut;
|
|||
|
|
|||
|
if (Gamestate.Instance.getGame() == "Set") {
|
|||
|
vp.clip = set_tut;
|
|||
|
}
|
|||
|
|
|||
|
if (Gamestate.Instance.getGame() == "Add") {
|
|||
|
vp.clip = add_tut;
|
|||
|
}
|
|||
|
|
|||
|
//Set video To Play then prepare Audio to prevent Buffering
|
|||
|
vp.Prepare();
|
|||
|
|
|||
|
//Wait until video is prepared
|
|||
|
while (!vp.isPrepared)
|
|||
|
{
|
|||
|
Debug.Log("Preparing Video");
|
|||
|
yield return null;
|
|||
|
}
|
|||
|
|
|||
|
Debug.Log("Done Preparing Video");
|
|||
|
|
|||
|
//Assign the Texture from Video to RawImage to be displayed
|
|||
|
image.texture = vp.texture;
|
|||
|
|
|||
|
//Play Video
|
|||
|
vp.Play();
|
|||
|
|
|||
|
//Play Sound
|
|||
|
audioSource.Play();
|
|||
|
|
|||
|
Debug.Log("Playing Video");
|
|||
|
while (vp.isPlaying)
|
|||
|
{
|
|||
|
Debug.LogWarning("Video Time: " + Mathf.FloorToInt((float)vp.time));
|
|||
|
yield return null;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
image.GetComponent<Animator>().SetBool("fadeout",true);//.Play("tutorial2", -1, 0f);
|
|||
|
|
|||
|
yield return new WaitForSeconds(0.8f);
|
|||
|
Debug.Log("Done Playing Video");
|
|||
|
|
|||
|
DontDestroyOnLoad(Gamestate.Instance);
|
|||
|
Gamestate.Instance.startGame();
|
|||
|
}
|
|||
|
|
|||
|
}
|