You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
132 lines
3.9 KiB
132 lines
3.9 KiB
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class AvProMovieState : MonoBehaviour {
|
|
|
|
[System.Serializable]
|
|
public class MovieState
|
|
{
|
|
public string StateName;
|
|
public bool StateMovieIsloop;
|
|
public int StartFrame;
|
|
public int EndFrame;
|
|
public delegate void StateBehaiver();
|
|
public StateBehaiver Doing;
|
|
}
|
|
|
|
[SerializeField]
|
|
protected List<MovieState> StateList;
|
|
|
|
[SerializeField]
|
|
protected MovieState currentMovieSate;
|
|
|
|
protected DShowMoviePlayer movie;
|
|
|
|
protected uint MovieFrame { set { movie.Frame = value; } get { return movie.Frame; } }
|
|
|
|
protected Coroutine DoCurrentFramesCor = null;
|
|
|
|
// Update is called once per frame
|
|
protected void Update () {
|
|
|
|
if (currentMovieSate.Doing != null)
|
|
currentMovieSate.Doing();
|
|
|
|
DoCurrentMovieFrame();
|
|
}
|
|
|
|
protected void SetState(MovieState movieState)
|
|
{
|
|
if (currentMovieSate == movieState)
|
|
return;
|
|
|
|
if (DoCurrentFramesCor != null)
|
|
StopCoroutine(DoCurrentFramesCor);
|
|
|
|
currentMovieSate = movieState;
|
|
|
|
MovieFrame = (uint)currentMovieSate.StartFrame;
|
|
if (MovieFrame != currentMovieSate.StartFrame)
|
|
{
|
|
DoCurrentFramesCor = StartCoroutine(DoCurrentStartFrame(currentMovieSate.StartFrame, MovieFrame > currentMovieSate.StartFrame));
|
|
}
|
|
|
|
movie.Play();
|
|
}
|
|
|
|
protected void DoCurrentMovieFrame()
|
|
{
|
|
if (currentMovieSate == null)
|
|
return;
|
|
if (MovieFrame >= currentMovieSate.EndFrame)
|
|
{
|
|
if (currentMovieSate.StateMovieIsloop)
|
|
{
|
|
MovieFrame = (uint)currentMovieSate.StartFrame;
|
|
if (MovieFrame != currentMovieSate.StartFrame)
|
|
{
|
|
if (DoCurrentFramesCor != null)
|
|
StopCoroutine(DoCurrentFramesCor);
|
|
DoCurrentFramesCor = StartCoroutine(DoCurrentStartFrame(currentMovieSate.StartFrame, MovieFrame > currentMovieSate.StartFrame));
|
|
}
|
|
}
|
|
else
|
|
{
|
|
movie.Pause();
|
|
MovieFrame = (uint)currentMovieSate.EndFrame;
|
|
}
|
|
}
|
|
if (MovieFrame < currentMovieSate.StartFrame)
|
|
{
|
|
MovieFrame = (uint)currentMovieSate.StartFrame;
|
|
if (MovieFrame != currentMovieSate.StartFrame)
|
|
{
|
|
if (DoCurrentFramesCor != null)
|
|
StopCoroutine(DoCurrentFramesCor);
|
|
DoCurrentFramesCor = StartCoroutine(DoCurrentStartFrame(currentMovieSate.StartFrame, MovieFrame > currentMovieSate.StartFrame));
|
|
}
|
|
}
|
|
|
|
if (!currentMovieSate.StateMovieIsloop)
|
|
return;
|
|
|
|
if (!movie.IsPlaying)
|
|
{
|
|
movie.Play();
|
|
}
|
|
}
|
|
|
|
IEnumerator DoCurrentStartFrame(int currentFrame, bool isBigger)
|
|
{
|
|
float adjust_frame = 0;
|
|
if (isBigger)
|
|
{
|
|
while (MovieFrame > (uint)(currentFrame + adjust_frame))
|
|
{
|
|
adjust_frame++;
|
|
MovieFrame = (uint)(currentFrame + adjust_frame);
|
|
if ((currentFrame + adjust_frame) > currentMovieSate.EndFrame)
|
|
{
|
|
yield break;
|
|
}
|
|
yield return new WaitForSeconds(3.0f * movie.GetDuration / movie.TotalNumFrames);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
while (MovieFrame < (uint)(currentFrame + adjust_frame))
|
|
{
|
|
adjust_frame++;
|
|
MovieFrame = (uint)(currentFrame + adjust_frame);
|
|
if ((currentFrame + adjust_frame) > currentMovieSate.EndFrame)
|
|
{
|
|
yield break;
|
|
}
|
|
|
|
yield return new WaitForSeconds(3.0f * movie.GetDuration / movie.TotalNumFrames);
|
|
}
|
|
}
|
|
yield return null;
|
|
}
|
|
}
|
|
|