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.
108 lines
2.9 KiB
108 lines
2.9 KiB
using System.Runtime.InteropServices;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using System;
|
|
using System.IO;
|
|
#if UNITY_EDITOR
|
|
using UnityEditor;
|
|
#endif
|
|
|
|
[ExecuteInEditMode]
|
|
public class DShowMoviePlayer : MoviePlayerBase
|
|
{
|
|
//////////////////////////////////////////////////////////////////////////
|
|
public bool LoadOnAwake = false;
|
|
public bool PlayOnStart = false;
|
|
|
|
[SerializeField]
|
|
private bool Looping = false;
|
|
|
|
[Range(0.0f,1.0f)]
|
|
public float AudioVolume = 1.0f;
|
|
|
|
DShowPlayer _player = null;
|
|
public DShowPlayer player
|
|
{
|
|
get { if (_player == null) _player = new DShowPlayer(); return _player; }
|
|
}
|
|
bool should_ignore
|
|
{
|
|
get
|
|
{
|
|
#if UNITY_EDITOR
|
|
if (EditorApplication.isPlaying == false)
|
|
return true;
|
|
#endif
|
|
return false;
|
|
}
|
|
}
|
|
|
|
private void Awake()
|
|
{
|
|
if (LoadOnAwake || should_ignore)
|
|
Load(VideoAsset);
|
|
|
|
}
|
|
private void Start()
|
|
{
|
|
if (should_ignore)
|
|
{
|
|
Play();
|
|
Pause();
|
|
}
|
|
else if (PlayOnStart)
|
|
{
|
|
Play();
|
|
}
|
|
}
|
|
public void Load()
|
|
{
|
|
Load(VideoAsset);
|
|
}
|
|
public void Update()
|
|
{
|
|
if (IsLoaded == false)
|
|
return;
|
|
if (Loop != player.Loop)
|
|
player.Loop = Loop;
|
|
if (AudioVolume != player.AudioVolume)
|
|
player.AudioVolume = AudioVolume;
|
|
player.updateTexture();
|
|
}
|
|
private void OnDisable()
|
|
{
|
|
Pause();
|
|
}
|
|
private void OnDestroy()
|
|
{
|
|
player.release();
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
#region MoviePlayerBase
|
|
|
|
// virtual function
|
|
public override bool Load(DShowClip path)
|
|
{
|
|
VideoAsset = path;
|
|
return player.Load(path);
|
|
}
|
|
public override void Play() { player.Play(); }
|
|
public override void Pause(){ player.Pause(); }
|
|
public override void Stop() { player.Stop(); }
|
|
|
|
// virtual property
|
|
public override bool Loop { set{Looping = value;}get{return Looping;}}
|
|
public override Texture Texture { get { return player.Texture; } }
|
|
public override uint Frame { set { player.Frame = value; } get { return player.Frame; } }
|
|
public override bool IsPaused { get { return !player.IsPlaying; } }
|
|
public override bool IsLoaded { get { return player.IsLoaded; } }
|
|
public override bool IsPlaying { get { return player.IsPlaying; } }
|
|
public override bool IsFinished { get { return player.IsFinished; } }
|
|
public override uint TotalNumFrames { get { return player.TotalNumFrames; } }
|
|
public override float GetDuration { get { return player.GetDuration; } }
|
|
public override float GetCurrentTime { get { return player.GetCurrentTime; } }
|
|
|
|
#endregion
|
|
}
|
|
|