animated "video" GUI texture

I want to make a short cicle animated texture to simulate a Talking Briefing.

How can i make it?

Somebody help me please

You would have a texture that contains an image strip, 4 to 12 images that show the different phases of the turning.
Then you would write a component that alters the UV on the texture accordingly at given times to make it look like its animated.

Thanks a lot!

Or, if you’re using Pro you can apply a MovieTexture. But dreamora’s suggestion is available in Indie, Pro and on the iPhone, and may ultimately prove a bit more light-weight if it’s just a short animation cycle.

how can i do this on Pro?

In the work they have pro, and i have indie,

but i need the code

just set the video as maintexture of the material and then call its play function

Is there any way now (with iphone advanced 1.7) to render to a movie texture on the ipad?

AFAIK, no… :frowning:

I want to show some animated models based on what the user has selected. What’s the best way to approach this?

Moving through an Image Strip seems to messy. It would be alot of images.
Also, I’m using Indie so I can’t make use of Movie Textures.

Is there an easy way to display a 3d asset in the GUI?

Put the model in front of a camera and render that camera to a texture that’s shown in the GUI (requires Pro).

Just to note here, there is a script on the Unify wiki that can help with some texture animation tasks like this.

FWIW, while that script doesn’t help Darren with his particular need of rendering a 3D model as part of the GUI, it is a great script for tiled texture animation so good call Andy!

This also does not help with GUI textures, since I cannot find a way to get the UV indexing method to work with a GUI.DrawTexture call. As I am trying to do an animated scoreboard, this is quite difficult without locking a camera pointed at a 2D or 3D scoreboard object. Since the game is pushing the limits on (iPhone) polygons, I don’t want to pay the rendering price of having multiple cameras.

If there is a way to do the UV offset on a GUI texture, I would love to hear about it.

You can draw a texture inside a group and it will be clipped to the group rectangle. Elements drawn within a group have coordinates which are relative to the group rectangle. It is possible to pass negative coordinates to clip the image on the left or top side. With the right sized rectangle and the right negative coordinates, you can extract any part of a texture this way.

Thanks Andy, that’s pretty cool (see for yourself here)!
(borrowed the tiled flames from the Animating Tiled textue script on the wiki)

Download the animated gui project here :slight_smile:

using UnityEngine;
using System.Collections;

[System.Serializable]
public class GUIAnimatedTexture {
	public Texture2D texture;
	public Vector2 firstFrameOffset;
	public int frames;
	public int frames_per_row;
	public float duration;
	
	private float p_frameDuration = -1;
	public float frameDuration {
		get {
			if( p_frameDuration < 0 )
				p_frameDuration = duration / frames;
			return p_frameDuration;
		}
	}
	
	private int p_curFrame = 0;
	private float p_curFrameTime = 0;
	public int curFrame {
		get {
			if( Time.time - p_curFrameTime > frameDuration )
			{
				p_curFrameTime += frameDuration;
				p_curFrame++;
				if( p_curFrame >= frames ) p_curFrame = 0;
			}
			return p_curFrame;
		}
	}
	
	public void Initialize() { p_curFrameTime = Time.time; p_curFrame = 0; }
}

[System.Serializable]
public class GUIAnimatedItem {
	public GUIAnimatedTexture texture;
	
	public Rect animationPosition;
	public RectOffset padding;
	
	public Rect big {
		get {
			return padding.Add(animationPosition);
		}
	}
}

static public class GUIAnimated {

	// DrawTexture
	static public void DrawTexture( GUIAnimatedItem item )	{
		DrawTexture( item.animationPosition, item.texture.texture, item.texture.curFrame, item.texture.frames, item.texture.frames_per_row, item.texture.firstFrameOffset );
	}
	static public bool Button( GUIAnimatedItem item ) {
		bool ret = GUI.Button( item.big, "" );
		DrawTexture( item );
		return ret;		
	}
	
	static public void DrawTexture( Rect position, Texture2D image, int frame, int total_frames, int frames_per_row, Vector2 first_frame_offset )
	{
		GUI.BeginGroup( position );
		{			
			// how big is our frame
			float fWidth = position.width;
			float fHeight = position.height;
			
			// how big is our offset
			Rect rOffset = new Rect
				(	-(first_frame_offset.x + (frame % frames_per_row) * fWidth),
					-(first_frame_offset.y + (frame / frames_per_row) * fHeight),
					image.width, image.height );
			
			// Render it
			GUI.DrawTexture( rOffset, image );
		}
		GUI.EndGroup();
	}
}

Hi, Just wondering if www.movie also works for movies of the .mov, .mpg, .mpeg, .mp4, .avi, .asf format? Or do we need to convert them first to ogg theora format?

Hey Higgy! I ran into this exact issue just yesterday… I was ready to download my game to my iPod Touch and could only conclude MovieTextures not being supported on iOS as the only source of the flurry of errors in my otherwise cleanly compiling code. Is there any reason why MovieTextures are not supported on iOS? Resource constraints? How about Android? Thanks for the info!

The machines are too slow.
The only case where you get hardware accelerated video playback on iOS is when you use the movieplayer which is what you do when you use playmovie

anything else is pure cpu decode

As sort of a continuation of this discussion - I’m working on an iPhone / iPad game that will require about 200 very short “video” clips. Each clip will be of a face clearly enunciating a word - like “yesterday”. None of the clips should be more than a few seconds. The face will have to be synched to the speech. I’ll need to be able to bring up a clip as needed. They won’t just run continuously.

The question(s) is, am I better off doing this with recorded video or with animation and a sound recording? Which one will use fewer resources and give better performance? What would be the best way to store the clips to give the best overall performance?

Thanks!