Ejemplo n.º 1
0
        } //END Start


        //---------------------------------//
        private IEnumerator DownloadTexture( string url )
        //---------------------------------//
        {
            if( url.Contains( "StreamingAssets" ) )
            {
                url = DatabaseStringHelper.CreateStreamingAssetsPath( url.Replace( "StreamingAssets/", "" ), DatabaseStringHelper.StringStyle.WithEscapeUriAndSystemPathCombine );
            }

            WWW www = new WWW( url );

            while( !www.isDone )
            {
                yield return new WaitForSeconds( .1f );
            }

            if( string.IsNullOrEmpty( www.error ) )
            {
                //Debug.Log( "DownloadTexture() url = " + url + ", Works! Width = " + www.textureNonReadable.width + ", Height = " + www.textureNonReadable.height );

                Texture2D texture = new Texture2D( www.textureNonReadable.width, www.textureNonReadable.height, WWWHelper.GetPlatformPreferredTextureFormat(), false );
                texture = www.textureNonReadable;

                if( material != null ) { material.mainTexture = texture; }
                if( rawImage != null ) { rawImage.texture = texture; }
            }
            else
            {
                //Debug.Log( "DownloadTexture() url = " + url + ", error = " + www.error );
            }

        } //END DownloadTexture
Ejemplo n.º 2
0
        } //END SaveImageUsingUnityCameraEvent


        //--------------------------------//
        public void DeleteLocalStorageEvent()
        //--------------------------------//
        {

            //Delete all of the videos and photos at our persistent local storage
            if( Directory.Exists( DatabaseStringHelper.CreatePersistentDataPath( "RecordedMedia" ) ) )
            {
                DeleteRecordedOrCapturedFiles( new DirectoryInfo( DatabaseStringHelper.CreatePersistentDataPath( "RecordedMedia" ) ) );
            }
            
            //Find all of the BlockEventRecorders in the scene and wipe their lists of saved photos and videos
            if( GameObject.FindObjectsOfType<BlockEventRecorder>() != null && GameObject.FindObjectsOfType<BlockEventRecorder>().Length > 1 )
            {
                List<BlockEventRecorder> recorders = GameObject.FindObjectsOfType<BlockEventRecorder>().ToList();

                foreach( BlockEventRecorder recorder in recorders )
                {
                    if( recorder != null )
                    {
                        recorder.ClearListsOfLocalStorageFiles();
                    }
                }
            }

            //There is only this BlockEventRecorder, wipe its lists
            else
            {
                ClearListsOfLocalStorageFiles();
            }

        } //END DeleteLocalStorageEvent
Ejemplo n.º 3
0
        } //END CallStopRecordingEvent

        //--------------------------------//
        public void SaveImageEvent( Texture tex )
        //--------------------------------//
        {
            if( tex != null )
            {
                //If our PersistentDataPath/ImageRecordings path does not exist, create it now
                if( !Directory.Exists( DatabaseStringHelper.CreatePersistentDataPath("ImageRecordings") ) )
                {
                    Directory.CreateDirectory( DatabaseStringHelper.CreatePersistentDataPath("ImageRecordings") );
                }

                string path = DatabaseStringHelper.CreatePersistentDataPath("ImageRecordings/" + fileName + ".png" );

                if( UseGeneratedPath() )
                {
                    path = DatabaseStringHelper.CreatePersistentDataPath("ImageRecordings/photo" + DateTime.Now.ToString( "dd-mm-yyyy-hh-mm-ss" ) + ".png" );
                }

                if( showDebug ) { Debug.Log( "BlockEventRecorder.cs SaveImageEvent() path = " + path ); }
                File.WriteAllBytes( path, ( tex as Texture2D ).EncodeToPNG() );

                //Add our image path to our list of saved images
                if( capturedPhotos == null ) { capturedPhotos = new List<string>(); }

                capturedPhotos.Add( path );

                //If there's an action to perform after saving this image, then do it
                if( onActionCompleted != null ) { onActionCompleted.Invoke(); }
            }

        } //END SaveImageEvent
Ejemplo n.º 4
0
        } //END CallStartRecordingBlockEventExternalCamera

        //-------------------------------//
        private void OnRecordingComplete( string path )
        //-------------------------------//
        {
            //If our PersistentDataPath/VideoRecordings path does not exist, create it now
            if( !Directory.Exists( DatabaseStringHelper.CreatePersistentDataPath("VideoRecordings") ) )
            {
                Directory.CreateDirectory( DatabaseStringHelper.CreatePersistentDataPath("VideoRecordings") );
            }

            //Move the recording into the PersistentData folder under the 'VideoRecordings' subfolder
            if ( File.Exists( path ) )
            {
                FileInfo fileInfo = new FileInfo( path );

                if( fileInfo != null )
                {
                    File.Move( path, DatabaseStringHelper.CreatePersistentDataPath("VideoRecordings/" + fileInfo.Name ) );
                    path = DatabaseStringHelper.CreatePersistentDataPath("VideoRecordings/" + fileInfo.Name );
                }
            }

            if( showDebug ) { Debug.Log( "BlockEventRecorder.cs OnRecordingComplete() adding path to list of captured videos = " + path ); }

            //Add our path to our list of recorded videos
            if( recordedVideos == null ) { recordedVideos = new List<string>(); }

            recordedVideos.Add( path );

#if NATCORDER
            //If we were capturing images from a passed in camera, dispose of the cameraRecorder at this time to free up memory
            if( cameraRecorder != null )
            {
                cameraRecorder.Dispose();
                cameraRecorder = null;
            }
#endif

            //If we were capturing audio samples from an AudioListener or AudioSource, destroy the AudioGetter.cs helper script attached to it
            if( audioGetter != null )
            {
                Destroy( audioGetter );
                audioGetter = null;
            }

#if NATCORDER
            //If we were capturing audio from the app, dispose of the audioRecorder at this time
            if( audioRecorder != null )
            {
                audioRecorder.Dispose();
                audioRecorder = null;
            }
#endif

            if( onRecordingCompleted != null ) { onRecordingCompleted.Invoke( path ); }

        } //END OnRecordingComplete
Ejemplo n.º 5
0
        } //END OnSampleRecieved

        //------------------------------------------------//
        private void OnRecordToFileComplete( string path )
        //------------------------------------------------//
        {
            
            //If our PersistentDataPath/MicrophoneRecordings path does not exist, create it now
            if (!Directory.Exists( DatabaseStringHelper.CreatePersistentDataPath("MicrophoneRecordings") ))
            {
                Directory.CreateDirectory( DatabaseStringHelper.CreatePersistentDataPath("MicrophoneRecordings") );
            }

            //Move the recording into the PersistentData folder under the 'MicrophoneRecordings' subfolder
            if( File.Exists(path) )
            {
                FileInfo fileInfo = new FileInfo(path);

                if (fileInfo != null)
                {
                    string name = fileInfo.Name;

                    if( IsFileNameAutomaticallyGenerated() )
                    {
                        name = DateTime.Now.ToString("dd-mm-yyyy-hh-mm-ss") + ".wav";
                    }
                    else if( IsFileNameCustom() && customFileName != "" )
                    {
                        name = customFileName + ".wav";
                    }

                    File.Move(path, DatabaseStringHelper.CreatePersistentDataPath("MicrophoneRecordings/" + name));
                    path = DatabaseStringHelper.CreatePersistentDataPath("MicrophoneRecordings/" + name);
                }
            }

            //Store the final path of the audio file for reference
            if ( audioRecordingsInLocalStorage == null ) { audioRecordingsInLocalStorage = new List<string>(); }

            audioRecordingsInLocalStorage.Add( path );

            //Let other system know that the recording has completed
            if( onRecordToFileComplete != null) { onRecordToFileComplete.Invoke( path ); }

        } //END OnRecordToFileComplete
Ejemplo n.º 6
0
        } //END SetResourcesLoadedTexture

        //-----------------------------//
        private IEnumerator SetTextureFromStreamingAssetsBytes( CameraType cameraType, CubeSide cubeSide, ImageType imageType )
        //-----------------------------//
        {
            if( showDebug ) { Debug.Log( "ImageFactory.cs SetStreamingAssetsLoadedTexture() start" ); }

            WWW www;

            //First we need to get the actual image files that are stored in the StreamingAssets folder as byte files
            string texturePath = DatabaseStringHelper.CreateStreamingAssetsPath( "Textures/" + imageType.ToString() + "/" + cameraType.ToString() + "/" + cubeSide.ToString() + ".bytes", DatabaseStringHelper.StringStyle.WithEscapeUriAndSystemPathCombine );
            string existsPath = DatabaseStringHelper.CreateStreamingAssetsPathForFileExistsCheck( "Textures/" + imageType.ToString() + "/" + cameraType.ToString() + "/" + cubeSide.ToString() + ".bytes" );


            bool exists = false;

            //Check if the image exists as bytes, this check is different by platform
            if( Application.platform == RuntimePlatform.Android )
            {
                //Android can only check using www
                www = new WWW( existsPath );

                yield return www;

                exists = string.IsNullOrEmpty( www.error );
            }
            else
            {
                //All other platforms can check using System.IO
                exists = System.IO.File.Exists( existsPath );
            }



            //If the texture does not exist in bytes format, try to load it as a .jpg file
            if( !exists )
            {
                //Debug.Log( "ImageFactory.cs image does not exist as bytes, trying as jpg... existsPath = " + existsPath );
                texturePath = "Textures/" + imageType.ToString() + "/" + cameraType.ToString() + "/" + cubeSide.ToString() + ".jpg";
                texturePath = DatabaseStringHelper.CreateStreamingAssetsPath( texturePath, DatabaseStringHelper.StringStyle.WithEscapeUriAndSystemPathCombine );
            }
            else
            {
                //Debug.Log( "ImageFactory.cs image exists as bytes! ... existsPath = " + existsPath );
            }

            //Download the image bytes from the StreamingAssets folder
            www = new WWW( texturePath );

            //Continue with the main thread until this finishes
            while( !www.isDone )
            {
                yield return www;
            }

            //Setup the appropriate amount of texture memory for the bytes
            SetLoadedTextureScaleAndSettings( cameraType, cubeSide, WWWHelper.GetPlatformPreferredTextureFormat(), false, www.textureNonReadable.width, www.textureNonReadable.height );

            //The bytes are loaded and the texture memory is set, let's turn the bytes into a texture in OpenGL
            if( cameraType == CameraType.Left )
            {
                if( cubeSide == CubeSide.front )
                {
                    texture_Left_front = www.textureNonReadable;
                }
                else if( cubeSide == CubeSide.back )
                {
                    texture_Left_back = www.textureNonReadable;
                }
                else if( cubeSide == CubeSide.left )
                {
                    texture_Left_left = www.textureNonReadable;
                }
                else if( cubeSide == CubeSide.right )
                {
                    texture_Left_right = www.textureNonReadable;
                }
                else if( cubeSide == CubeSide.top )
                {
                    texture_Left_top = www.textureNonReadable;
                }
                else if( cubeSide == CubeSide.bottom )
                {
                    texture_Left_bottom = www.textureNonReadable;
                }
            }
            else if( cameraType == CameraType.Right )
            {
                if( cubeSide == CubeSide.front )
                {
                    texture_Right_front = www.textureNonReadable;
                }
                else if( cubeSide == CubeSide.back )
                {
                    texture_Right_back = www.textureNonReadable;
                }
                else if( cubeSide == CubeSide.left )
                {
                    texture_Right_left = www.textureNonReadable;
                }
                else if( cubeSide == CubeSide.right )
                {
                    texture_Right_right = www.textureNonReadable;
                }
                else if( cubeSide == CubeSide.top )
                {
                    texture_Right_top = www.textureNonReadable;
                }
                else if( cubeSide == CubeSide.bottom )
                {
                    texture_Right_bottom = www.textureNonReadable;
                }
            }

            //Clear the existing bytes from memory
            www.Dispose();

            //Now that the texture is set in OpenGL, make sure the textures are set to Clamped (Hides seams between textures)
            SetLoadedTextureWrapMode( cameraType, cubeSide, TextureWrapMode.Clamp );



            //The texture is now loaded! Set the appropriate boolean to true
            SetLoadedBool( cameraType, cubeSide, true );

        } //END SetStreamingAssetsLoadedTexture
        } //END Start



        //---------------------------------------------//
        public IEnumerator CopyVideoToPersistentDataPath( string urlWithPath )
        //---------------------------------------------//
        {

            string fileName = DatabaseStringHelper.GetFileNameWithExtension( urlWithPath );
            string persistentPath = DatabaseStringHelper.CreatePersistentDataPath( fileName );

            string streamingPath = urlWithPath;
            if( urlWithPath.Contains( "StreamingAssets" ) ) { streamingPath = DatabaseStringHelper.CreateStreamingAssetsPath( urlWithPath.Replace( "StreamingAssets/", "" ), DatabaseStringHelper.StringStyle.WithEscapeUriAndSystemPathCombine ); }


            if( ShowDebug ) Debug.Log( "CopyVideoToPersistent( " + urlWithPath + " ) ... filename = " + fileName + ", persistentPath = " + persistentPath + ", streamingPath = " + streamingPath );


            //If the video does not exist in the persistent data path folder, we need to copy all of it's bytes over
            if( !File.Exists( persistentPath ) )
            {
                WWW www = new WWW( streamingPath );

                while( !www.isDone ) { yield return new WaitForSeconds( .1f ); }

                if( string.IsNullOrEmpty( www.error ) )
                {
                    if( ShowDebug ) Debug.Log( "CopyVideoToPersistent( " + urlWithPath + " ) we found the video in StreamingAssetsPath = " + streamingPath );

                    if( www.bytes != null && www.bytes.Length > 0 )
                    {
                        if( ShowDebug ) Debug.Log( "CopyVideoToPersistent( " + urlWithPath + " ) we found the www.bytes = " + www.bytes.Length.ToString() );


                        //We found the video, copy it's data over over time (not all at once to prevent a crash)
                        Stream stream = new MemoryStream( www.bytes );

                        using( FileStream output = new FileStream( persistentPath, FileMode.Create, FileAccess.Write ) )
                        {
                            byte[] buffer = new byte[ 32 * 1024 ]; //a 32KB-sized buffer is the most efficient
                            int bytesRead;

                            while( ( bytesRead = stream.Read( buffer, 0, buffer.Length ) ) > 0 )
                            {
                                output.Write( buffer, 0, bytesRead );
                            }

                            output.Flush();
                        }

                        //We found the video, copy it's data over
                        //File.WriteAllBytes( persistentPath, www.bytes );

                    }
                    else
                    {
                        if( ShowDebug ) Debug.Log( "CopyVideoToPersistent( " + urlWithPath + " ) we couldn't find any www.bytes = " + www.bytes.Length.ToString() );
                    }
                }
                else
                {
                    if( ShowDebug ) Debug.Log( "CopyVideoToPersistent( " + urlWithPath + " ) Getting the video from StreamingAssets had an error = " + www.error + ", streamingAssetsPath = " + streamingPath );
                }

                www.Dispose();
                www = null;
            }
            else
            {
                if( ShowDebug ) Debug.Log( "CopyVideoToPersistent( " + urlWithPath + " ) the video already exists" );
            }

        } //END CopyVideoToPersistentDataPath