Incorporating videos / image sequences into free Unity games

Hi. Is there a way to bring videos or image sequences into games with the free version of Unity 3.1? Say someone enters a region or opens a certain door and I want to play a twenty second video clip and then return to the game.

Thanks

20 Seconds might be a bit long for this technique, but you can scroll the UVs on a material and or switch up the texture at regular intervals

sample code

float lastFrame;
float timePerFrame = 0.03333f;//30 frames / second
float spacePerSquare = 0.125f;//an 8 by 8 grid of images
float rowVal;
float colVal;

void Update() {
    float timer = Time.time;
    if(timer > lastFrame + timePerFrame){
        lastFrame = timer;
        rowVal += spacePerSquare;

        if(rowVal > 1-spacePerSquare){
            rowVal = 0;
            colVal += spacePerSquare;

            if(colVal > 1-spacePerSquare){
                colVal = 0;
                ///renderer.material.mainTexture = next texture i want to assign in order;

            }
        }
        renderer.material.mainTextureOffset = Vector2 (rowVal, colVal);

    }//end of frame

}

I didn't test this, but you get the general idea. You create an image sequence laid out as a grid, and scroll through it. You obviously won't be able to do large videos that way, for that you need unity pro.

yoyo… count me as one who would like to see your stuff posted to the wiki… im still not sure if i want to invest into pro yet. been a torque user for over 6 years and just now considering they are going nowhere slowly. Time for a change!! However, one of my primary ventures with torque included the video launches upon triggers… thanks

Use any c# library which can give access to the webcam like ‘opencv sharp’. This will help you and then get the image data in Color32 format and render for each as given above.

for e.g;

  1. Read the camera capture by Opencv sharp by CvCapture
  2. then Read frame by frame Image and Save it in IplImage.
  3. then Convert IplImage.imageData as it was in IntPtr by marshal function by MarshaCopy(IntPtr , 0 , 3Imagewidthimageheight) to byte array.
  4. now convert the byte array into color32 array, the first 3 byte is responsible for single pixel so copy like this

byte data contains the data of IplImage converted from Intptr

byte data = new byte[3imagewidthimageheight];
IntPtr p = img.ImageData ; //img is the perframe IplImage
Marshal.Copy(p , data , 0 , 3
imagewidth**imageheight);

Color32 color = new Color32[Imagewidth**Imageheight];
int temp = 0;
for(int i=0; i < imagewidth
imageheight ;i++)
{
color = new Color(data[temp] , data[temp+1] , data[temp+2] , 0) //last zero for alpha factor of color32
temp+=3;
}