예제 #1
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
예제 #2
0
        } //END SetDictionaryLoadedTexture


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

            //Set the scale of the texture to grab based on whether this device can support high end textures
            int scale = 2048;
            string size = "Large";

            if( PlatformHelper.IsLowEndDevice() )
            {
                scale = 1024;
                size = "Small";
            }

            //Get the texture from the Resources folder
            string path = "Textures/Images/" + size.ToString() + "/" + imageType.ToString() + "/" + cameraType.ToString() + "/" + cubeSide.ToString();

            //If the texture doesn't exist, change the path to the opposite camera (allows us to use Mono images instead of Stereo)
            if( Resources.Load<Texture2D>( path ) == null )
            {
                CameraType camera = CameraType.Left;
                if( cameraType == CameraType.Left ) { camera = CameraType.Right; }
                path = "Textures/Images/" + size.ToString() + "/" + imageType.ToString() + "/" + camera.ToString() + "/" + cubeSide.ToString();
            }

            if( showDebug ) { Debug.Log( "ImageFactory.cs SetTextureFromResourcesTexture() path = " + path ); }


            //Create a new texture variable with the appropriate scale and settings
            SetLoadedTextureScaleAndSettings( cameraType, cubeSide, WWWHelper.GetPlatformPreferredTextureFormat(), false, scale, scale );

            //Set the texture's wrapping mode to clamped, which prevents seeing the edges of the skybox's cubemap
            SetLoadedTextureWrapMode( cameraType, cubeSide, TextureWrapMode.Clamp );

            //Set the bytes to the appropriate texture
            if( cameraType == CameraType.Left )
            {
                if( cubeSide == CubeSide.front )
                {
                    texture_Left_front = Resources.Load<Texture2D>( path );
                }
                else if( cubeSide == CubeSide.back )
                {
                    texture_Left_back = Resources.Load<Texture2D>( path );
                }
                else if( cubeSide == CubeSide.left )
                {
                    texture_Left_left = Resources.Load<Texture2D>( path );
                }
                else if( cubeSide == CubeSide.right )
                {
                    texture_Left_right = Resources.Load<Texture2D>( path );
                }
                else if( cubeSide == CubeSide.top )
                {
                    texture_Left_top = Resources.Load<Texture2D>( path );
                }
                else if( cubeSide == CubeSide.bottom )
                {
                    texture_Left_bottom = Resources.Load<Texture2D>( path );
                }
            }
            else if( cameraType == CameraType.Right )
            {
                if( cubeSide == CubeSide.front )
                {
                    texture_Right_front = Resources.Load<Texture2D>( path );
                }
                else if( cubeSide == CubeSide.back )
                {
                    texture_Right_back = Resources.Load<Texture2D>( path );
                }
                else if( cubeSide == CubeSide.left )
                {
                    texture_Right_left = Resources.Load<Texture2D>( path );
                }
                else if( cubeSide == CubeSide.right )
                {
                    texture_Right_right = Resources.Load<Texture2D>( path );
                }
                else if( cubeSide == CubeSide.top )
                {
                    texture_Right_top = Resources.Load<Texture2D>( path );
                }
                else if( cubeSide == CubeSide.bottom )
                {
                    texture_Right_bottom = Resources.Load<Texture2D>( path );
                }
            }

            //This texture is loaded, set the appropriate bool
            SetLoadedBool( cameraType, cubeSide, true );

        } //END SetTextureFromResourcesTexture
예제 #3
0
        } //END SetTextureFromResourcesTexture

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

            //First we need to know how big the image scale is (width, height), we store a text file for each image
            //  at each image's parent folder (EX: Resources/Textures/Astronaut/scale) ... Resources calls don't use file format extension (EX: .jpg, .txt, .bytes )
            ResourceRequest request = Resources.LoadAsync<TextAsset>( "Textures/" + imageType.ToString() + "/scale" );


            //Wait until the file has been read
            while( !request.isDone )
            {
                yield return request;
            }

            //Now that the file has been read, turn it into a TextAsset, and from that we can read it as a string
            TextAsset textAsset = request.asset as TextAsset;

            //We have the scale text file, grab the x and y scale as ints
            string[] scales = textAsset.text.Split( new char[] { 'x' } );
            int scaleX = int.Parse( scales[ 0 ] );
            int scaleY = int.Parse( scales[ 1 ] );

            //When we're done, make sure we unload anything we grabbed from Resources
            Resources.UnloadAsset( textAsset );



            //Get the bytes from the Resources folder
            string bytesPath = "Textures/" + imageType.ToString() + "/" + cameraType.ToString() + "/" + cubeSide.ToString();

            //This has to be done as a TextAsset, and from there we can grab the bytes
            request = Resources.LoadAsync<TextAsset>( bytesPath );

            //Wait until the file has been read
            while( !request.isDone )
            {
                yield return request;
            }

            //Now that the file has been read, turn it into a TextAsset, and from that we can turn it into a .bytes
            textAsset = request.asset as TextAsset;

            //Create a new texture variable with the appropriate scale and settings
            SetLoadedTextureScaleAndSettings( cameraType, cubeSide, WWWHelper.GetPlatformPreferredTextureFormat(), false, scaleX, scaleY );

            //Set the texture's wrapping mode to clamped, which prevents seeing the edges of the skybox's cubemap
            SetLoadedTextureWrapMode( cameraType, cubeSide, TextureWrapMode.Clamp );

            //Set the bytes to the appropriate texture
            if( cameraType == CameraType.Left )
            {
                if( cubeSide == CubeSide.front )
                {
                    texture_Left_front.LoadImage( textAsset.bytes );
                }
                else if( cubeSide == CubeSide.back )
                {
                    texture_Left_back.LoadImage( textAsset.bytes );
                }
                else if( cubeSide == CubeSide.left )
                {
                    texture_Left_left.LoadImage( textAsset.bytes );
                }
                else if( cubeSide == CubeSide.right )
                {
                    texture_Left_right.LoadImage( textAsset.bytes );
                }
                else if( cubeSide == CubeSide.top )
                {
                    texture_Left_top.LoadImage( textAsset.bytes );
                }
                else if( cubeSide == CubeSide.bottom )
                {
                    texture_Left_bottom.LoadImage( textAsset.bytes );
                }
            }
            else if( cameraType == CameraType.Right )
            {
                if( cubeSide == CubeSide.front )
                {
                    texture_Right_front.LoadImage( textAsset.bytes );
                }
                else if( cubeSide == CubeSide.back )
                {
                    texture_Right_back.LoadImage( textAsset.bytes );
                }
                else if( cubeSide == CubeSide.left )
                {
                    texture_Right_left.LoadImage( textAsset.bytes );
                }
                else if( cubeSide == CubeSide.right )
                {
                    texture_Right_right.LoadImage( textAsset.bytes );
                }
                else if( cubeSide == CubeSide.top )
                {
                    texture_Right_top.LoadImage( textAsset.bytes );
                }
                else if( cubeSide == CubeSide.bottom )
                {
                    texture_Right_bottom.LoadImage( textAsset.bytes );
                }
            }

            //When we're done, make sure we unload anything we grabbed from Resources
            Resources.UnloadAsset( textAsset );

            //This texture is loaded, set the appropriate bool
            SetLoadedBool( cameraType, cubeSide, true );

        } //END SetResourcesLoadedTexture
예제 #4
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