Falls wer einen weg sucht in der Unity Free (Basic) Version Filme über eine GUI darzustellen hab ich ne kleine lösung gebaut.
Es ist ein kleines Script was der Camera als Komponente angehängt werden kann und minimale konfiguration benötigt.
Das Tool benötigt eine Image Sequence (EinzelBilder) und eine Wav/Mp3 als Ton Spur.
Die Bilder müssen im "Resources" ordner "Resources/DeinMovieOrdner..." abgelegt sein um sie @Runtime laden zu können.
Der Beispiel Webplayer Unten nuzt einen Kino Trailer mit 3033 Bildern bei 25 Bildern pro Sekunde.
Die Einzelbilder der Sequence müssen mit 4 Digits angeben sein.
Beispielsweise Frame0000 - Frame3033 damit sie koreckt geladen werden können.
Ein Beispiel pfad wäre "DeinMovieOrdner/Frame".
Im Pfad selber dürfen die NumDigits nicht mit angegeben sein da diese @Runtime automatisch angehängt werden.
Die Maximale PlayTime ist derzeit 5.55 minuten das entspricht 9999 einzelbildern.
Optionen im Player sind derzeit, Play, Pause, Stop und ein TimeSlider.
Beispiel Webplayer Link:
http://www.flatter.s...Version1_0.html
Hir ein Bild wie die konfiguration des beispiel videos ausieht:
Und hir das Script:
// This program is free software. It comes without any warranty, to
// the extent permitted by applicable law. You can redistribute it
// and/or modify it under the terms of the TMG To Public License,
// Version 1, as published by Team Mongo Games.
// See http://www.teammongogames.kilu.de/License for more details.
using UnityEngine;
using System.Collections;
public class TMGMovieGUITexture : MonoBehaviour {
public string FramePath;
public int numframes;
public float FPS;
public AudioClip audioClip;
private AudioSource audioSource;
private float nextFrameTime;
private int aktiveFrame;
private Texture2D[] AllFrames;
private bool FramesLoaded;
private bool Play;
private GUITexture AktiveFrameGUITexture;
private bool IsPlaying;
private float PlayLength;
private float playTime;
private float nextPlayTime;
void Awake() {
AllFrames = new Texture2D[numframes];
InitializeFrames();
audioSource = gameObject.AddComponent<AudioSource>();
audioSource.clip = audioClip;
}
private void InitializeFrames(){
int Counter = 0;
string framename = "";
for(int i=0;i<numframes;i++) {
framename = FramePath + Counter.ToString("0000");
AllFrames[Counter] = (Texture2D)Resources.Load(framename);
Counter++;
}
AktiveFrameGUITexture = new GUITexture();
gameObject.AddComponent(AktiveFrameGUITexture.GetType());
FramesLoaded = true;
PlayLength = (1.0f / FPS) * numframes;
}
void Start ()
{
gameObject.guiTexture.transform.position = new Vector3(0.5f, 0.5f, 0.0f);
IsPlaying = false;
}
void OnGUI ()
{
if(FramesLoaded) {
if(GUI.Button(new Rect(10,10,100,30), "Play")) {
StartPlayMovie();
}
if(GUI.Button(new Rect(10,50,100,30), "Pause")) {
PauseMovie();
}
if(GUI.Button(new Rect(10,90,100,30), "Stop")) {
StopMovie();
}
nextPlayTime = GUI.HorizontalSlider(new Rect(Screen.width/2-300, Screen.height - 50, 600, 30), playTime, 0.0F, PlayLength);
}
}
void StartPlayMovie() {
if(!Play) {
Play = true;
if(!IsPlaying) {
nextFrameTime = (PlayLength/numframes);
IsPlaying = true;
}
}
}
void PauseMovie() {
if(Play) {
Play = false;
audioSource.Pause();
}
}
void StopMovie() {
Play = false;
audioSource.Stop();
aktiveFrame = 0;
gameObject.guiTexture.texture = AllFrames[aktiveFrame];
nextFrameTime = 0.0f;
IsPlaying = false;
playTime = 0.0f;
}
void Update () {
if(Play) {
if(!audioSource.isPlaying) {
audioSource.Play();
}
PlayMovie();
}
}
void PlayMovie () {
if(playTime != nextPlayTime) {
aktiveFrame = (numframes - Mathf.RoundToInt((PlayLength-nextPlayTime) / (1.0f / FPS)));
aktiveFrame = Mathf.Clamp(aktiveFrame, 0 , numframes - 1);
playTime = nextPlayTime;
nextFrameTime = (PlayLength/numframes) * (aktiveFrame + 1);
}
if(playTime >= nextFrameTime) {
gameObject.guiTexture.texture = AllFrames[aktiveFrame];
nextFrameTime = (PlayLength/numframes) * (aktiveFrame + 1);
if(aktiveFrame < numframes-1) {
aktiveFrame++;
} else {
StopMovie();
}
}
playTime += Time.deltaTime;
SyncSound();
}
void SyncSound() {
if(playTime - audioSource.time > 0.02f || playTime - audioSource.time < -0.02f) {
audioSource.time = playTime;
}
}
}
Die dauer des Compilierens steigt mit der anzahl der Frames allso sollte man bei langen videos gedult haben^^
Vieleicht baue ich später eine Version die Bilder aus einer Zip datei oder direckt aus einem Video Contäner liest, was die Compilier zeit stark reduzieren würde.
Grüsse.