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.

97 lines
2.0 KiB

using UnityEngine;
using System.Collections;
using UnityEngine.EventSystems;
using System;
public class TouchMovie : MonoBehaviour, IPointerDownHandler {
//public Texture texture;
DShowMoviePlayer movie;
[SerializeField]
private int MaxFrameCount = 0;
private bool isTouch = false;
[SerializeField]
private float MoviePlayInterval = 30;
private float playtime;
[SerializeField]
AudioSource audioSource;
void Awake()
{
//audioSource = GetComponent<AudioSource>();
movie = GetComponent<DShowMoviePlayer>();
}
// Use this for initialization
void Start () {
playtime = MoviePlayInterval;
}
// Update is called once per frame
void Update () {
if (playtime > 0)
playtime -= Time.deltaTime;
if(playtime<=0)
{
playtime = MoviePlayInterval;
movie.Play();
isTouch = true;
}
if(!isTouch)
{
if(MaxFrameCount!=0)
{
if (movie.Frame >= MaxFrameCount)
movie.Frame = 0;
}
if (audioSource != null)
{
if (audioSource.isPlaying)
audioSource.Stop();
}
}
else
{
if (MaxFrameCount != 0)
{
if (movie.Frame >= MaxFrameCount)
{
if (audioSource != null)
{
if (!audioSource.isPlaying)
audioSource.Play();
}
}
}
}
if(movie.IsFinished)
{
isTouch = false;
if(!movie.Loop)
{
movie.Pause();
movie.Frame = 0;
isTouch = false;
}
}
}
public void OnPointerDown(PointerEventData eventData)
{
if (!movie)
return;
movie.Play();
isTouch = true;
playtime = MoviePlayInterval;
}
}