//This will create texture from the pictue image path void LoadContactPictures(AddressBookContact[] _contactList) { m_contactPictures = new Texture[_contactList.Length]; for (int _i = 0; _i < _contactList.Length; _i++) { AddressBookContact _each = _contactList[_i]; if (!string.IsNullOrEmpty(_each.ImagePath)) { //Create callback receiver and save the index to pass to completion block. int _textureIndex = _i; DownloadTexture.Completion _onCompletion = (Texture2D _texture, string _error) => { if (!string.IsNullOrEmpty(_error)) { Console.LogError(Constants.kDebugTag, "[AddressBook] Contact Picture download failed " + _error); m_contactPictures[_textureIndex] = null; } else { m_contactPictures[_textureIndex] = _texture; } }; //Start the texture fetching _each.GetImageAsync(_onCompletion); } } }
/// <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(); }