public override void OnGetGraphic(ImagePackage package, FilePath path)
        {
            // Already resized?
            ResizedImage resized = ResizedImages.Get(path.Path);

            if (resized != null)
            {
                // Sure is!
                package.GotGraphic(resized.Image);

                return;
            }

            if (Callback.WillDelay)
            {
                // Buffer this call until later - we're not on the main thread.

                // Create the callback:
                ResourcesProtocolCallback callback = new ResourcesProtocolCallback(package, path);

                // Hook up the protocol handler for speed later:
                callback.Protocol = this;

                // Request it to run:
                callback.Go();

                return;
            }

            if (path.Filetype == "spa")
            {
                // Animated.

                // Load the binary file - Note: the full file should be called file.spa.bytes for this to work in Unity.
                byte[] binary = ((TextAsset)Resources.Load(path.Path)).bytes;

                if (binary != null)
                {
                    // Apply it now:
                    package.GotGraphic(new SPA(path.Url, binary));
                    return;
                }
            }
            else
            {
                // Image
                Texture2D image = (Texture2D)Resources.Load(path.Directory + path.Filename);

                // Resize the image:
                resized = ResizedImages.Add(path.Path, image);

                if (image != null)
                {
                    package.GotGraphic(resized.Image);
                    return;
                }
            }

            package.GotGraphic("Image not found in resources (" + path.Directory + path.Filename + " from URL '" + path.Url + "').");
        }
		public override void OnGetGraphic(ImagePackage package,FilePath path){
			
			// Already resized?
			ResizedImage resized=ResizedImages.Get(path.Path);
			
			if(resized!=null){
				
				// Sure is!
				package.GotGraphic(resized.Image);
				
				return;
				
			}
			
			if(Callback.WillDelay){
				
				// Buffer this call until later - we're not on the main thread.
				
				// Create the callback:
				ResourcesProtocolCallback callback=new ResourcesProtocolCallback(package,path);
				
				// Hook up the protocol handler for speed later:
				callback.Protocol=this;
				
				// Request it to run:
				callback.Go();
				
				return;
			}
			
			if(path.Filetype=="spa"){
				// Animated.
				
				// Load the binary file - Note: the full file should be called file.spa.bytes for this to work in Unity.
				byte[] binary=((TextAsset)Resources.Load(path.Path)).bytes;
				
				if(binary!=null){
					// Apply it now:
					package.GotGraphic(new SPA(path.Url,binary));
					return;
				}
				
			}else{
				// Image
				Texture2D image=(Texture2D)Resources.Load(path.Directory+path.Filename);
				
				// Resize the image:
				resized=ResizedImages.Add(path.Path,image);
				
				if(image!=null){
					package.GotGraphic(resized.Image);
					return;
				}
				
			}
			
			package.GotGraphic("Image not found in resources ("+path.Directory+path.Filename+" from URL '"+path.Url+"').");
			
		}
		/// <summary>Attempts to get a graphic from the given location using this protocol.</summary>
		/// <param name="package">The image request. GotGraphic must be called on this when the protocol is done.</param>
		/// <param name="path">The location of the file to retrieve using this protocol.</param>
		public override void OnGetGraphic(ImagePackage package,FilePath path){
			if(path.Filetype=="spa"){
				// Grab a runtime SPA:
				package.GotGraphic(SPA.Get(path.Path));
				return;
			}
			
			package.GotGraphic(ImageCache.Get(path.Path));
		}
		public override void OnGetGraphic(ImagePackage package,FilePath path){
			
			if(Callback.WillDelay){
				
				// Buffer this call until later - we're not on the main thread.
				
				// Create the callback:
				ResourcesProtocolCallback callback=new ResourcesProtocolCallback(package,path);
				
				// Hook up the protocol handler for speed later:
				callback.Protocol=this;
				
				// Request it to run:
				callback.Go();
				
				return;
			}
			
			if(path.Filetype=="spa"){
				// Animated.
				// Load the binary file - Note: the full file should be called file.spa.bytes for this to work in Unity.
				byte[] binary=((TextAsset)Resources.Load(path.Path)).bytes;
				
				if(binary!=null){
					// Apply it now:
					package.GotGraphic(new SPA(path.Url,binary));
					return;
				}
				
			#if !MOBILE
			}else if(ContentType.IsVideo(path.Filetype)){
				// Video
				MovieTexture movie=(MovieTexture)Resources.Load(path.Directory+path.Filename,typeof(MovieTexture));
				
				if(movie!=null){
					package.GotGraphic(movie);
					return;
				}
				
			#endif
			}else{
				// Image
				Texture2D image=(Texture2D)Resources.Load(path.Directory+path.Filename);
				
				if(image!=null){
					package.GotGraphic(image);
					return;
				}
				
			}
			
			package.GotGraphic("Image not found in resources ("+path.Directory+path.Filename+" from URL '"+path.Url+"').");
			
		}
Example #5
0
        /// <summary>Attempts to get a graphic from the given location using this protocol.</summary>
        /// <param name="package">The image request. GotGraphic must be called on this when the protocol is done.</param>
        /// <param name="path">The location of the file to retrieve using this protocol.</param>
        public override void OnGetGraphic(ImagePackage package, FilePath path)
        {
            if (path.Filetype == "spa")
            {
                // Grab a runtime SPA:
                package.GotGraphic(SPA.Get(path.Path));
                return;
            }

            package.GotGraphic(ImageCache.Get(path.Path));
        }
Example #6
0
        private void GotGraphicResult(HttpRequest request)
        {
            ImagePackage package = (ImagePackage)request.ExtraData;

            if (request.Errored)
            {
                package.GotGraphic(request.Error);
            }

            // Cache it:
            AddToCache(request.Url, package);

            string url = request.Url.ToLower();

            // Split by dot for the type:
            string[] pieces = url.Split('.');

            // Grab the type:
            string type = pieces[pieces.Length - 1];


            if (type == "spa")
            {
                // Animation
                package.GotGraphic(new SPA(request.Url, request.Bytes));
                        #if !MOBILE
            }
            else if (ContentType.IsVideo(type))
            {
                // Video
                package.GotGraphic(request.Video);
                        #endif
            }
            else if (request.Image != null)
            {
                // Image
                package.GotGraphic(request.Image);
            }
            else
            {
                package.GotGraphic(request.Text);
            }
        }
        /// <summary>Attempts to get a graphic from the given location using this protocol.</summary>
        /// <param name="package">The image request. GotGraphic must be called on this when the protocol is done.</param>
        /// <param name="path">The location of the file to retrieve using this protocol.</param>
        public override void OnGetGraphic(ImagePackage package,FilePath path){
			
			// Create it:
            Texture2D tex = new Texture2D(0,0);
			
			// Load it:
            tex.LoadImage(System.IO.File.ReadAllBytes(path.Path));
			
			// Let the package know:
            package.GotGraphic(tex);
        }
        /// <summary>Attempts to get a graphic from the given location using this protocol.</summary>
        /// <param name="package">The image request. GotGraphic must be called on this when the protocol is done.</param>
        /// <param name="path">The location of the file to retrieve using this protocol.</param>
        public override void OnGetGraphic(ImagePackage package, FilePath path)
        {
            // Create it:
            Texture2D tex = new Texture2D(0, 0);

            // Load it:
            tex.LoadImage(System.IO.File.ReadAllBytes(path.Path));

            // Let the package know:
            package.GotGraphic(tex);
        }
        public override void OnGetGraphic(ImagePackage package)
        {
            // Already resized?
            ResizedImage resized = ResizedImages.Get(package.location.Path);

            if (resized != null)
            {
                // Sure is!
                package.GotGraphic(resized.Image);

                return;
            }

            // Main thread only:
            Callback.MainThread(delegate(){
                // Try loading from resources:
                string resUrl = package.location.Directory + package.location.Filename;

                if (resUrl.Length > 0 && resUrl[0] == '/')
                {
                    resUrl = resUrl.Substring(1);
                }

                // Get the image:
                UnityEngine.Object resource = Resources.Load(resUrl);

                if (resource == null)
                {
                    // Note: the full file should be called something.bytes for this to work in Unity.
                    resource = Resources.Load(package.location.Path);
                }

                if (!package.Contents.LoadFromAsset(resource, package))
                {
                    return;
                }

                PictureFormat pict = package.Contents as PictureFormat;

                if (pict != null)
                {
                    // Resize the image:
                    resized = ResizedImages.Add(package.location.Path, pict.Image as Texture2D);

                    // Apply:
                    pict.Image = resized.Image;
                }

                // Great, stop there:
                package.Done();
            });
        }
Example #10
0
 public override void OnGetGraphic(ImagePackage package, FilePath path)
 {
     package.GotGraphic(DynamicTexture.Get(path.Path));
 }
		public override void OnGetGraphic(ImagePackage package,FilePath path){
			package.GotGraphic(DynamicTexture.Get(path.Path));
		}