Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

animated "video" GUI texture

Discussion in 'Immediate Mode GUI (IMGUI)' started by radiolobito, Jul 24, 2009.

  1. radiolobito

    radiolobito

    Joined:
    Jun 12, 2009
    Posts:
    117
    I want to make a short cicle animated texture to simulate a Talking Briefing.

    How can i make it?

    Somebody help me please
     
  2. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    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.
     
  3. radiolobito

    radiolobito

    Joined:
    Jun 12, 2009
    Posts:
    117
    Thanks a lot!
     
  4. HiggyB

    HiggyB

    Unity Product Evangelist

    Joined:
    Dec 8, 2006
    Posts:
    6,183
    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.
     
  5. radiolobito

    radiolobito

    Joined:
    Jun 12, 2009
    Posts:
    117
    how can i do this on Pro?

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

    but i need the code
     
  6. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    just set the video as maintexture of the material and then call its play function
     
  7. filmcraft

    filmcraft

    Joined:
    May 26, 2006
    Posts:
    109
    Is there any way now (with iphone advanced 1.7) to render to a movie texture on the ipad?
     
  8. HiggyB

    HiggyB

    Unity Product Evangelist

    Joined:
    Dec 8, 2006
    Posts:
    6,183
    AFAIK, no... :(
     
  9. DarrenHollywood

    DarrenHollywood

    Joined:
    Mar 2, 2010
    Posts:
    27
    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?
     
  10. HiggyB

    HiggyB

    Unity Product Evangelist

    Joined:
    Dec 8, 2006
    Posts:
    6,183
    Put the model in front of a camera and render that camera to a texture that's shown in the GUI (requires Pro).
     
  11. andeeeee

    andeeeee

    Joined:
    Jul 19, 2005
    Posts:
    8,768
    Just to note here, there is a script on the Unify wiki that can help with some texture animation tasks like this.
     
  12. HiggyB

    HiggyB

    Unity Product Evangelist

    Joined:
    Dec 8, 2006
    Posts:
    6,183
    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!
     
  13. stevan

    stevan

    Joined:
    Jul 8, 2009
    Posts:
    10
    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.
     
  14. andeeeee

    andeeeee

    Joined:
    Jul 19, 2005
    Posts:
    8,768
    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.
     
  15. menneske

    menneske

    Joined:
    Jan 23, 2009
    Posts:
    44
    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 :)

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. [System.Serializable]
    6. public class GUIAnimatedTexture {
    7.     public Texture2D texture;
    8.     public Vector2 firstFrameOffset;
    9.     public int frames;
    10.     public int frames_per_row;
    11.     public float duration;
    12.    
    13.     private float p_frameDuration = -1;
    14.     public float frameDuration {
    15.         get {
    16.             if( p_frameDuration < 0 )
    17.                 p_frameDuration = duration / frames;
    18.             return p_frameDuration;
    19.         }
    20.     }
    21.    
    22.     private int p_curFrame = 0;
    23.     private float p_curFrameTime = 0;
    24.     public int curFrame {
    25.         get {
    26.             if( Time.time - p_curFrameTime > frameDuration )
    27.             {
    28.                 p_curFrameTime += frameDuration;
    29.                 p_curFrame++;
    30.                 if( p_curFrame >= frames ) p_curFrame = 0;
    31.             }
    32.             return p_curFrame;
    33.         }
    34.     }
    35.    
    36.     public void Initialize() { p_curFrameTime = Time.time; p_curFrame = 0; }
    37. }
    38.  
    39. [System.Serializable]
    40. public class GUIAnimatedItem {
    41.     public GUIAnimatedTexture texture;
    42.    
    43.     public Rect animationPosition;
    44.     public RectOffset padding;
    45.    
    46.     public Rect big {
    47.         get {
    48.             return padding.Add(animationPosition);
    49.         }
    50.     }
    51. }
    52.  
    53. static public class GUIAnimated {
    54.  
    55.     // DrawTexture
    56.     static public void DrawTexture( GUIAnimatedItem item )  {
    57.         DrawTexture( item.animationPosition, item.texture.texture, item.texture.curFrame, item.texture.frames, item.texture.frames_per_row, item.texture.firstFrameOffset );
    58.     }
    59.     static public bool Button( GUIAnimatedItem item ) {
    60.         bool ret = GUI.Button( item.big, "" );
    61.         DrawTexture( item );
    62.         return ret;    
    63.     }
    64.    
    65.     static public void DrawTexture( Rect position, Texture2D image, int frame, int total_frames, int frames_per_row, Vector2 first_frame_offset )
    66.     {
    67.         GUI.BeginGroup( position );
    68.         {          
    69.             // how big is our frame
    70.             float fWidth = position.width;
    71.             float fHeight = position.height;
    72.            
    73.             // how big is our offset
    74.             Rect rOffset = new Rect
    75.                 (   -(first_frame_offset.x + (frame % frames_per_row) * fWidth),
    76.                     -(first_frame_offset.y + (frame / frames_per_row) * fHeight),
    77.                     image.width, image.height );
    78.            
    79.             // Render it
    80.             GUI.DrawTexture( rOffset, image );
    81.         }
    82.         GUI.EndGroup();
    83.     }
    84. }
    85.  
     
  16. April

    April

    Joined:
    Dec 14, 2009
    Posts:
    62
    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?
     
  17. jmpp

    jmpp

    Joined:
    Jun 1, 2010
    Posts:
    93
    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!
     
    Last edited: Dec 7, 2010
  18. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    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
     
  19. gjanko

    gjanko

    Joined:
    Oct 7, 2010
    Posts:
    6
    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!