protected void PickImageFinished (string _imagePath, ePickImageFinishReason _finishReason) { // Resume unity player this.ResumeUnity(); Console.Log(Constants.kDebugTag, "[MediaLibrary] Finishing pick image, Path=" + _imagePath + " Reason=" + _finishReason); if (OnPickImageFinished != null) { // Failed opertation if (_finishReason != ePickImageFinishReason.SELECTED) { OnPickImageFinished(_finishReason, null); return; } // Download image from given path URL _imagePathURL = URL.FileURLWithPath(_imagePath); DownloadTexture _newDownload = new DownloadTexture(_imagePathURL, true, true); _newDownload.OnCompletion = (Texture2D _texture, string _error)=>{ if (string.IsNullOrEmpty(_error)) { OnPickImageFinished(ePickImageFinishReason.SELECTED, _texture); } else { Console.LogError(Constants.kDebugTag, "[MediaLibrary] Texture download failed, URL=" + _imagePathURL.URLString); OnPickImageFinished(ePickImageFinishReason.FAILED, null); } }; // Start download _newDownload.StartRequest(); } }
protected void PickImageFinished(string _imagePath, ePickImageFinishReason _finishReason) { // Resume unity player this.ResumeUnity(); Console.Log(Constants.kDebugTag, "[MediaLibrary] Finishing pick image, Path=" + _imagePath + " Reason=" + _finishReason); if (OnPickImageFinished != null) { // Failed opertation if (_finishReason != ePickImageFinishReason.SELECTED) { OnPickImageFinished(_finishReason, null); return; } // Download image from given path URL _imagePathURL = URL.FileURLWithPath(_imagePath); DownloadTexture _newDownload = new DownloadTexture(_imagePathURL, true, true); _newDownload.OnCompletion = (Texture2D _texture, string _error) => { if (string.IsNullOrEmpty(_error)) { OnPickImageFinished(ePickImageFinishReason.SELECTED, _texture); } else { Console.LogError(Constants.kDebugTag, "[MediaLibrary] Texture download failed, URL=" + _imagePathURL.URLString); OnPickImageFinished(ePickImageFinishReason.FAILED, null); } }; // Start download _newDownload.StartRequest(); } }
public override void GetImageAsync(DownloadTexture.Completion _onCompletion) { if (_onCompletion != null) { if (string.IsNullOrEmpty(m_imagePath)) { VoxelBusters.DebugPRO.Console.LogError(Constants.kDebugTag, "[GameServices] No Achievement image for " + m_title); _onCompletion(null, "Texture not found."); } else if (m_image != null) //If already cached { _onCompletion(m_image, null); } else { URL _imagePathURL = URL.URLWithString(m_imagePath); // Download DownloadTexture _newDownload = new DownloadTexture(_imagePathURL, true, true); _newDownload.OnCompletion = (Texture2D _texture, string _error) => { if (string.IsNullOrEmpty(_error)) { _onCompletion(_texture, null); } else { VoxelBusters.DebugPRO.Console.LogError(Constants.kDebugTag, "[GameServices] Texture download for Achievement failed, URL=" + _imagePathURL.URLString); _onCompletion(null, "Texture not found."); } }; _newDownload.StartRequest(); } } }
/// <summary> /// Helper for getting Texture from image path. /// </summary> /// <param name="_onCompletion">Callback to be triggered after downloading the image.</param> public void GetImageAsync(DownloadTexture.Completion _onCompletion) { // Use cached information if (m_image != null || m_imageDownloadError != null) { _onCompletion(m_image, m_imageDownloadError); return; } else if (string.IsNullOrEmpty(ImagePath)) { _onCompletion(GetDefaultImage(), null); return; } // Download image from given path URL _imagePathURL = URL.FileURLWithPath(ImagePath); DownloadTexture _newDownload = new DownloadTexture(_imagePathURL, true, true); _newDownload.OnCompletion = (Texture2D _newTexture, string _error) => { // Set properties m_image = _newTexture; m_imageDownloadError = _error; // Send callback if (_onCompletion != null) { _onCompletion(_newTexture, _error); } }; // Start download _newDownload.StartRequest(); }
/// <summary> /// Shares the image at path. /// </summary> /// <param name="_message">Message to share.</param> /// <param name="_imagePath">Path where image exists that needs to be shared.</param> /// <param name="_excludedOptions">List of sharing services to exclude while sharing.</param> /// <param name="_onCompletion">Callback to be triggered when sharing action completes.</param> public void ShareImageAtPath(string _message, string _imagePath, eShareOptions[] _excludedOptions, SharingCompletion _onCompletion) { if (!File.Exists(_imagePath)) { Console.LogWarning(Constants.kDebugTag, "[Sharing] ShareImageAtPath, path is invalid"); ShareImage(_message, null, _excludedOptions, _onCompletion); return; } // Download image from given path URL _imagePathURL = URL.FileURLWithPath(_imagePath); DownloadTexture _newDownload = new DownloadTexture(_imagePathURL, true, false); _newDownload.OnCompletion = (Texture2D _texture, string _error) => { // Download went wrong if (!string.IsNullOrEmpty(_error)) { Console.LogWarning(Constants.kDebugTag, "[Sharing] ShareImageAtPath, failed to download texture. Error=" + _error); } ShareImage(_message, _texture, _excludedOptions, _onCompletion); }; // Start download _newDownload.StartRequest(); }
public void StartDownload() { URL _URL; // Check type of url if (m_URLString.StartsWith("http")) { _URL = URL.URLWithString(m_URLString); } else { _URL = URL.FileURLWithPath(m_URLString); } // Download image from given path DownloadTexture _newDownload = new DownloadTexture(_URL, true, true); _newDownload.OnCompletion = (Texture2D _texture, string _error) => { if (string.IsNullOrEmpty(_error)) { m_renderer.sharedMaterial.mainTexture = _texture; } else { Debug.LogError("[DownloadTextureDemo] Error=" + _error); } }; // Start download _newDownload.StartRequest(); }
/// <summary> /// Helper for getting Texture from image path. /// </summary> /// <param name="_onCompletion">Callback to be triggered after downloading the image.</param> public void GetImageAsync(DownloadTexture.Completion _onCompletion) { URL _imagePathURL = URL.FileURLWithPath(ImagePath); // Download image from given path DownloadTexture _newDownload = new DownloadTexture(_imagePathURL, true, true); _newDownload.OnCompletion = _onCompletion; // Start download _newDownload.StartRequest(); }
private void OnReceivingProfilePicture(string _requestID, string _path) { //Remove from history DownloadTexture.Completion _callback = m_profilePictureDownloadRequests[_requestID]; m_profilePictureDownloadRequests.Remove(_requestID); if (!string.IsNullOrEmpty(_path)) { URL _pathURL; bool _isFileURL = !_path.ToLower().StartsWith("http"); if (!_isFileURL) { _pathURL = URL.URLWithString(_path); } else { _pathURL = URL.FileURLWithPath(_path); } // Download DownloadTexture _newDownload = new DownloadTexture(_pathURL, true, true); _newDownload.OnCompletion = (Texture2D _texture, string _error) => { if (string.IsNullOrEmpty(_error)) { if (_isFileURL) { FileOperations.Delete(_path); } //Call callback here with _texture if (_callback != null) { _callback(_texture, _error); } } else { VoxelBusters.DebugPRO.Console.LogError(Constants.kDebugTag, "[AndroidUserProfile] Texture download failed, URL=" + _pathURL.URLString); _callback(_texture, "Error loading texture!"); } }; _newDownload.StartRequest(); } else { //Call callback here directly with null as texture _callback(null, "Error loading texture!"); } }
public void LoadProfilePicture(string _path, DownloadTexture.Completion _onCompletion) { string _newRequestID = System.Guid.NewGuid().ToString(); m_profilePictureDownloadRequests.Add(_newRequestID, _onCompletion); if(_path.ToLower().StartsWith("http")) { OnReceivingProfilePicture(_newRequestID, _path); } else { Plugin.Call(AndroidNativeInfo.Methods.LOAD_PROFILE_PICTURE, _newRequestID, _path); } }
/// <summary> /// Asynchronously loads the image. /// </summary> /// <param name="_onCompletion">Callback to be triggered after loading the image.</param> public virtual void GetImageAsync (DownloadTexture.Completion _onCompletion) { // Cache callback DownloadImageFinishedEvent = _onCompletion; // Using cached information if (m_image != null) { DownloadImageFinishedEvent(m_image, null); return; } // Request for image RequestForImage(); }
protected void RequestForImageFinished(URL _imagePathURL, string _error) { if (_error != null) { DownloadImageFinished(null, _error); return; } else { DownloadTexture _newRequest = new DownloadTexture(_imagePathURL, true, true); _newRequest.OnCompletion = (Texture2D _image, string _downloadError) => { // Invoke handler DownloadImageFinished(_image, _downloadError); }; _newRequest.StartRequest(); } }
/// <summary> /// Saves an image from the specified url to gallery/media library of the users device. /// \note The path needs to be absolute path if its local file. Take care of the path on multiple platforms as the file structure will be different. /// </summary> /// <param name="_URL">URL to pick the source from. This can be a file url existing on local storage or a web url at remote location.</param> /// <param name="_onCompletion">Callback triggered once save to gallery is done.</param> public void SaveImageToGallery(URL _URL, SaveImageToGalleryCompletion _onCompletion) { // Download texture from given URL DownloadTexture _newDownload = new DownloadTexture(_URL, true, false); _newDownload.OnCompletion = (Texture2D _texture, string _error) => { // Save downloaded texture if (!string.IsNullOrEmpty(_error)) { Console.LogError(Constants.kDebugTag, "[MediaLibrary] Texture download failed, URL=" + _URL.URLString); } // Save image SaveImageToGallery(_texture, _onCompletion); }; // Start download _newDownload.StartRequest(); }
protected void PickImageFinished(string _imagePath, ePickImageFinishReason _finishReason) { // Resume unity player this.ResumeUnity(); DebugUtility.Logger.Log(Constants.kDebugTag, "[MediaLibrary] Finishing pick image, Path=" + _imagePath + " Reason=" + _finishReason); if (OnPickImageFinished != null) { // Failed opertation if (_finishReason != ePickImageFinishReason.SELECTED) { OnPickImageFinished(_finishReason, null); return; } // Download image from given path URL _imagePathURL = URL.FileURLWithPath(_imagePath); DownloadTexture _newDownload = new DownloadTexture(_imagePathURL, Application.platform != RuntimePlatform.Android, true); //On Android, we consider the exif orientation in native code for performance. _newDownload.ScaleFactor = m_scaleFactor; _newDownload.OnCompletion = (Texture2D _texture, string _error) => { #if !UNITY_EDITOR // Delete the file if (!string.IsNullOrEmpty(_imagePath)) { FileOperations.Delete(_imagePath); } #endif if (string.IsNullOrEmpty(_error)) { OnPickImageFinished(ePickImageFinishReason.SELECTED, _texture); } else { DebugUtility.Logger.LogError(Constants.kDebugTag, "[MediaLibrary] Texture download failed, URL=" + _imagePathURL.URLString); OnPickImageFinished(ePickImageFinishReason.FAILED, null); } }; // Start download _newDownload.StartRequest(); } }
protected void StopAsyncRequests() { if (m_downloadTexture != null) { // Abort request m_downloadTexture.Abort(); // Reset m_downloadTexture = null; } if (m_takeScreenShotCoroutine != null) { // Stop coroutine NPBinding.Instance.StopCoroutine(m_takeScreenShotCoroutine); // Reset m_takeScreenShotCoroutine = null; } }
/// <summary> /// Adds the specified image for sharing. /// </summary> /// <param name="_imagePath">Path of the image to be shared.</param> public void AttachImageAtPath(string _imagePath) { // Stop existing requests StopAsyncRequests(); // Mark async operation in progress ImageAsyncDownloadInProgress = true; // Start downloading URL _imagePathURL = URL.FileURLWithPath(_imagePath); m_downloadTexture = new DownloadTexture(_imagePathURL, true, false); m_downloadTexture.OnCompletion = (Texture2D _texture, string _error) => { // Share image AttachImage(_texture); // Set properties ImageAsyncDownloadInProgress = false; }; m_downloadTexture.StartRequest(); }
public void AttachImageAtPath (string _imagePath) { // Stop existing requests StopAsyncRequests(); // Mark async operation in progress ImageAsyncDownloadInProgress = true; // Start downloading URL _imagePathURL = URL.FileURLWithPath(_imagePath); m_downloadTexture = new DownloadTexture(_imagePathURL, true, false); m_downloadTexture.OnCompletion = (Texture2D _texture, string _error)=>{ // Share image AttachImage(_texture); // Set properties ImageAsyncDownloadInProgress = false; }; m_downloadTexture.StartRequest(); }
public void StartDownload() { URL _URL; // Check type of url if (m_URLString.StartsWith("http")) _URL = URL.URLWithString(m_URLString); else _URL = URL.FileURLWithPath(m_URLString); // Download image from given path DownloadTexture _newDownload = new DownloadTexture(_URL, true, true); _newDownload.OnCompletion = (Texture2D _texture, string _error)=>{ if (string.IsNullOrEmpty(_error)) m_renderer.sharedMaterial.mainTexture = _texture; else Debug.LogError("[DownloadTextureDemo] Error=" + _error); }; // Start download _newDownload.StartRequest(); }
public void ShareImageAtPath (string _message, string _imagePath, eShareOptions[] _excludedOptions, SharingCompletion _onCompletion) { if (!File.Exists(_imagePath)) { DebugPRO.Console.LogWarning(Constants.kDebugTag, "[Sharing] ShareImageAtPath, path is invalid"); ShareImage(_message, null, _excludedOptions, _onCompletion); return; } // Download image from given path URL _imagePathURL = URL.FileURLWithPath(_imagePath); DownloadTexture _newDownload = new DownloadTexture(_imagePathURL, true, false); _newDownload.OnCompletion = (Texture2D _texture, string _error)=>{ // Download went wrong if (!string.IsNullOrEmpty(_error)) { DebugPRO.Console.LogWarning(Constants.kDebugTag, "[Sharing] ShareImageAtPath, failed to download texture. Error=" + _error); } ShareImage(_message, _texture, _excludedOptions, _onCompletion); }; // Start download _newDownload.StartRequest(); }
protected void StopAsyncRequests () { if (m_downloadTexture != null) { // Abort request m_downloadTexture.Abort(); // Reset m_downloadTexture = null; } if (m_takeScreenShotCoroutine != null) { // Stop coroutine NPBinding.Instance.StopCoroutine(m_takeScreenShotCoroutine); // Reset m_takeScreenShotCoroutine = null; } }
public override void GetImageAsync (DownloadTexture.Completion _onCompletion) { if (_onCompletion != null) { if (string.IsNullOrEmpty(m_imagePath)) { VoxelBusters.DebugPRO.Console.LogError(Constants.kDebugTag, "[GameServices] No profile image for " + Name); _onCompletion(null, "Texture not found."); } else if(m_imageTexture != null) //If already cached { _onCompletion(m_imageTexture, null); } else { AndroidUserProfilesManager _userManager = ((GameServicesAndroid)(NPBinding.GameServices)).UserProfilesManager; _userManager.LoadProfilePicture(m_imagePath, (Texture2D _texture, string _error)=>{ m_imageTexture = _texture; if(_onCompletion != null && _onCompletion.Target != null) { _onCompletion(_texture, _error); } }); } } }
protected void RequestForImageFinished (URL _imagePathURL, string _error) { if (_error != null) { DownloadImageFinished(null, _error); return; } else { DownloadTexture _newRequest = new DownloadTexture(_imagePathURL, true, true); _newRequest.OnCompletion = (Texture2D _image, string _downloadError)=>{ // Invoke handler DownloadImageFinished(_image, _downloadError); }; _newRequest.StartRequest(); } }
private void OnReceivingProfilePicture(string _requestID, string _path) { //Remove from history DownloadTexture.Completion _callback = m_profilePictureDownloadRequests[_requestID]; m_profilePictureDownloadRequests.Remove(_requestID); if(!string.IsNullOrEmpty(_path)) { URL _pathURL; bool _isFileURL = !_path.ToLower().StartsWith("http"); if(!_isFileURL) { _pathURL = URL.URLWithString(_path); } else { _pathURL = URL.FileURLWithPath(_path); } // Download DownloadTexture _newDownload = new DownloadTexture(_pathURL, true, true); _newDownload.OnCompletion = (Texture2D _texture, string _error)=>{ if (string.IsNullOrEmpty(_error)) { if(_isFileURL) { FileOperations.Delete(_path); } //Call callback here with _texture if(_callback != null) { _callback(_texture, _error); } } else { VoxelBusters.DebugPRO.Console.LogError(Constants.kDebugTag, "[AndroidUserProfile] Texture download failed, URL=" + _pathURL.URLString); _callback(_texture, "Error loading texture!"); } }; _newDownload.StartRequest(); } else { //Call callback here directly with null as texture _callback(null, "Error loading texture!"); } }
public override void GetImageAsync (DownloadTexture.Completion _onCompletion) { if (_onCompletion != null) { if (string.IsNullOrEmpty(m_imagePath)) { VoxelBusters.DebugPRO.Console.LogError(Constants.kDebugTag, "[GameServices] No Achievement image for " + m_title); _onCompletion(null, "Texture not found."); } else if(m_image != null) //If already cached { _onCompletion(m_image, null); } else { URL _imagePathURL = URL.URLWithString(m_imagePath); // Download DownloadTexture _newDownload = new DownloadTexture(_imagePathURL, true, true); _newDownload.OnCompletion = (Texture2D _texture, string _error)=>{ if (string.IsNullOrEmpty(_error)) { _onCompletion(_texture, null); } else { VoxelBusters.DebugPRO.Console.LogError(Constants.kDebugTag, "[GameServices] Texture download for Achievement failed, URL=" + _imagePathURL.URLString); _onCompletion(null, "Texture not found."); } }; _newDownload.StartRequest(); } } }
/// <summary> /// Saves an image from the specified url to gallery/media library of the users device. /// \note The path needs to be absolute path if its local file. Take care of the path on multiple platforms as the file structure will be different. /// </summary> /// <param name="_URL">URL to pick the source from. This can be a file url existing on local storage or a web url at remote location.</param> /// <param name="_onCompletion">Callback triggered once save to gallery is done.</param> public void SaveImageToGallery (URL _URL, SaveImageToGalleryCompletion _onCompletion) { // Download texture from given URL DownloadTexture _newDownload = new DownloadTexture(_URL, true, false); _newDownload.OnCompletion = (Texture2D _texture, string _error)=>{ // Save downloaded texture if (!string.IsNullOrEmpty(_error)) { Console.LogError(Constants.kDebugTag, "[MediaLibrary] Texture download failed, URL=" + _URL.URLString); } // Save image SaveImageToGallery(_texture, _onCompletion); }; // Start download _newDownload.StartRequest(); }
/// <summary> /// Helper for getting Texture from image path. /// </summary> /// <param name="_onCompletion">Callback to be triggered after downloading the image.</param> public void GetImageAsync (DownloadTexture.Completion _onCompletion) { // Use cached information if (m_image != null || m_imageDownloadError != null) { _onCompletion(m_image, m_imageDownloadError); return; } else if (string.IsNullOrEmpty(ImagePath)) { _onCompletion(GetDefaultImage(), null); return; } // Download image from given path URL _imagePathURL = URL.FileURLWithPath(ImagePath); DownloadTexture _newDownload = new DownloadTexture(_imagePathURL, true, true); _newDownload.OnCompletion = (Texture2D _newTexture, string _error)=>{ // Set properties m_image = _newTexture; m_imageDownloadError = _error; // Send callback if (_onCompletion != null) _onCompletion(_newTexture, _error); }; // Start download _newDownload.StartRequest(); }
public override void GetImageAsync (DownloadTexture.Completion _onCompletion) { if (m_user == null) { if (_onCompletion != null) _onCompletion(null, Constants.kGameServicesUserAuthMissingError); return; } m_user.GetImageAsync(_onCompletion); }