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.
193 lines
6.6 KiB
193 lines
6.6 KiB
using System.Runtime.InteropServices;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using System;
|
|
using UnityEngine.UI;
|
|
using System.IO;
|
|
|
|
#if UNITY_EDITOR
|
|
using UnityEditor;
|
|
#endif
|
|
[ExecuteInEditMode]
|
|
public class DShowListMoviePlayer : MoviePlayerBase
|
|
{
|
|
Animator animator;
|
|
|
|
public List<DShowMoviePlayer> PlayerList = new List<DShowMoviePlayer>();
|
|
|
|
DShowMoviePlayer currentPlayer = null;
|
|
|
|
//int currentIndex = 0;
|
|
//public int GetMovieIndex { get { return currentIndex; } }
|
|
//////////////////////////////////////////////////////////////////////////
|
|
Texture transparentTexture;
|
|
private void Awake()
|
|
{
|
|
Texture2D tex = new Texture2D(2, 2, TextureFormat.ARGB32, false);
|
|
Color c = new Color(0, 0, 0, 0);
|
|
tex.SetPixel(0, 0, c);
|
|
tex.SetPixel(1, 0, c);
|
|
tex.SetPixel(0, 1, c);
|
|
tex.SetPixel(1, 1, c);
|
|
tex.Apply();
|
|
transparentTexture = tex;
|
|
|
|
TryFindAnimator();
|
|
}
|
|
|
|
void TryFindAnimator()
|
|
{
|
|
if (animator == null)
|
|
{
|
|
if (GetComponent<Animator>() == null)
|
|
{
|
|
Debug.LogError(gameObject.name + " is not have animator!");
|
|
gameObject.SetActive(false);
|
|
return;
|
|
}
|
|
animator = GetComponent<Animator>();
|
|
}
|
|
CheckInitailDShowPlayer();
|
|
}
|
|
|
|
void CheckInitailDShowPlayer()
|
|
{
|
|
RuntimeAnimatorController ac = animator.runtimeAnimatorController;
|
|
for (int i = 0; i < ac.animationClips.Length; i++)
|
|
{
|
|
//ChildAnimatorState state = sm.states[i];
|
|
//AnimationClip n_animation = state.state.motion as AnimationClip;
|
|
AnimationClip n_animation = ac.animationClips[i];
|
|
|
|
foreach (AnimationEvent m_event in n_animation.events)
|
|
{
|
|
if(m_event.functionName == "Play")
|
|
{
|
|
InitialPlayer((DShowClip)m_event.objectReferenceParameter, n_animation.isLooping);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//this is for animation clip event
|
|
void InitialPlayer() { }
|
|
|
|
void InitialPlayer(DShowClip clip, bool loop)
|
|
{
|
|
if(FindPlayer(clip) == null)
|
|
{
|
|
GameObject n_obj = new GameObject();
|
|
n_obj.transform.parent = this.transform;
|
|
n_obj.name = clip.name;
|
|
DShowMoviePlayer player = n_obj.AddComponent<DShowMoviePlayer>();
|
|
player.LoadOnAwake = true;
|
|
player.VideoAsset = clip;
|
|
player.Load();
|
|
player.Loop = loop;
|
|
PlayerList.Add(player);
|
|
}
|
|
}
|
|
|
|
DShowMoviePlayer FindPlayer(DShowClip clip)
|
|
{
|
|
DShowMoviePlayer[] clips = GetComponentsInChildren<DShowMoviePlayer>();
|
|
foreach(var c in clips)
|
|
{
|
|
if (c.VideoAsset == clip)
|
|
return c;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
|
|
}
|
|
public void Update()
|
|
{
|
|
#if UNITY_EDITOR
|
|
if(!Application.isPlaying)
|
|
{
|
|
TryFindAnimator();
|
|
}
|
|
#endif
|
|
if (IsLoaded == false)
|
|
return;
|
|
|
|
//if (AudioVolume != PlayerList[currentIndex].AudioVolume)
|
|
//PlayerList[currentIndex].AudioVolume = AudioVolume;
|
|
//updateTexture();
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
//StopNative(id);
|
|
currentPlayer = null;
|
|
Pause();
|
|
}
|
|
private void OnDestroy()
|
|
{
|
|
for(int i=0;i< PlayerList.Count;i++)
|
|
{
|
|
PlayerList[i].player.release();
|
|
}
|
|
}
|
|
/*
|
|
public bool currentVideoFinished()
|
|
{
|
|
return PlayerList[currentIndex].IsFinished;
|
|
}
|
|
*/
|
|
//////////////////////////////////////////////////////////////////////////
|
|
#region MoviePlayerBase
|
|
|
|
public void Play(DShowClip clip)
|
|
{
|
|
DShowMoviePlayer newPlayer = FindPlayer(clip);
|
|
if(currentPlayer != newPlayer && newPlayer != null)
|
|
{
|
|
if (currentPlayer != null)
|
|
{
|
|
currentPlayer.Stop();
|
|
currentPlayer.Frame = 0;
|
|
}
|
|
currentPlayer = newPlayer;
|
|
VideoAsset = currentPlayer.VideoAsset;
|
|
currentPlayer.Play();
|
|
}
|
|
}
|
|
#if false
|
|
//public override void Play() { if (PlayerList[currentIndex] != null) PlayerList[currentIndex].Pause(); PlayerList[currentIndex].Frame = 0; PlayerList[currentIndex].Play(); }
|
|
public override void Pause() { if(currentPlayer != null) currentPlayer.Pause(); }
|
|
public override void Stop() { if(currentPlayer != null) currentPlayer.Stop(); }
|
|
|
|
// virtual property
|
|
public override Texture Texture { get { return currentPlayer ? currentPlayer.Texture : transparentTexture; } }
|
|
public override uint Frame { set { if (currentPlayer != null) currentPlayer.Frame = value; } get { return currentPlayer ? currentPlayer.Frame : 0; } }
|
|
|
|
public override uint TotalNumFrames { get { return currentPlayer ? currentPlayer.TotalNumFrames : 0; } }
|
|
public override float GetDuration { get { return currentPlayer ? currentPlayer.GetDuration : 0; } }
|
|
public override float GetCurrentTime { get { return currentPlayer ? currentPlayer.GetCurrentTime : 0; } }
|
|
#else
|
|
//public virtual bool Load(DShowClip path) { return true; }
|
|
//public virtual void Play() { }
|
|
public override void Pause() { if (currentPlayer != null) currentPlayer.Pause(); }
|
|
public override void Stop() { if (currentPlayer != null) currentPlayer.Stop(); currentPlayer = null; }
|
|
|
|
// virtual property
|
|
//public virtual bool Loop { set { } get { return true; } }
|
|
public override Texture Texture { get { return currentPlayer ? currentPlayer.Texture : transparentTexture; } }
|
|
public override uint Frame { set { if (currentPlayer != null) currentPlayer.Frame = value; } get { return currentPlayer ? currentPlayer.Frame : 0; } }
|
|
public override bool IsPaused { get { return currentPlayer ? currentPlayer.IsPaused : false; } }
|
|
public override bool IsLoaded { get { return currentPlayer ? currentPlayer.IsLoaded : true; } }
|
|
//public virtual bool IsPlaying { get { return !IsPaused; } }
|
|
public override bool IsFinished { get { return currentPlayer ? currentPlayer.IsFinished : true; } }
|
|
public override uint TotalNumFrames { get { return currentPlayer ? currentPlayer.TotalNumFrames : 0; } }
|
|
//public virtual float Volume { get { return 0; } set { } }
|
|
public override float GetDuration { get { return currentPlayer ? currentPlayer.GetDuration : 0; } }
|
|
public override float GetCurrentTime { get { return currentPlayer ? currentPlayer.GetCurrentTime : 0; } }
|
|
#endif
|
|
|
|
#endregion
|
|
}
|
|
|