using System.Collections.Generic; using uc; using UnityEngine; using UnityEngine.UI; [RequireComponent(typeof(RawImage))] public class MoviePlayerCanvas : ActivityBase { //public List filenames; public List filenames; public bool loop; RawImage raw_image; Texture origin_tex; List movies; int index = -1; MoviePlayerBase current_movie { get { return (index < 0) ? null : movies[index]; } } void Awake() { raw_image = GetComponent(); origin_tex = raw_image.mainTexture; movies = new List(); } void Start() { if (filenames.Count == 0 && origin_tex != null) { //filenames.Add(origin_tex.name + ".mov"); } foreach (var fs in filenames) { movies.Add(MoviePlayerPool.Singleton.GetMoviePlayer(fs, false)); } if (movies.Count > 0) { var m = movies[movies.Count - 1]; m.Loop = loop; } } private void OnEnable() { index = -1; } protected override void OnEnter() { } protected override void OnUpdate() { if (IsEntering == false) return; if (movies.Count > 0) { if (index < 0) { index = 0; if (current_movie != null) { current_movie.Play(); current_movie.Frame = 0; } } else { if (current_movie != null) { bool is_stopped = current_movie.IsPaused; if (is_stopped) { if (index < movies.Count - 1) { //print("next movie"); movies[++index].Play(); is_stopped = false; } } raw_image.texture = current_movie.IsLoaded ? current_movie.Texture : origin_tex; if (current_movie.Loop == false) IsFinished = is_stopped && (index == movies.Count - 1); } } if (IsFinished) { Finish(); } } } void OnDisable() { if (movies.Count > 0) { if (index > -1) { foreach (var m in movies) { m.Stop(); m.Frame = 0; } } } } protected override void OnLeave() { } protected override void OnKilled() { } }