public override void OnGetGraphic(ImagePackage package) { // Main thread only: Callback.MainThread(delegate(){ 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. resUrl = package.location.Path; if (resUrl.Length > 0 && resUrl[0] == '/') { resUrl = resUrl.Substring(1); } resource = Resources.Load(resUrl); } // Try loading from the asset: if (package.Contents.LoadFromAsset(resource, package)) { package.Done(); } }); }
/// <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) { // Get from cache and apply to package: package.Contents = ImageCache.Get(package.location.Path); // Ok! package.Done(); }
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(); }); }
/// <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) { LoadBundle(package.location, delegate(AssetBundle bundle){ // Pull an image from the bundle using the hash as our hierarchy: UnityEngine.Object asset = bundle.LoadAsset(package.location.hash); // Try loading from the asset: if (package.Contents.LoadFromAsset(asset, package)) { // Ok! package.Done(); } }); }
public override void OnGetGraphic(ImagePackage package) { // Apply as camera format: string path = package.location.Path; CameraFormat cmf = package.Contents as CameraFormat; if (cmf == null) { cmf = new CameraFormat(); package.Contents = cmf; } // Update path: cmf.SetPath(path); // Ready: package.Done(); }