Beispiel #1
0
        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);
                        }
                    });
                }
            }
        }
Beispiel #2
0
        /// <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();
        }
Beispiel #3
0
        //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);
                }
            }
        }
Beispiel #4
0
        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();
                }
            }
        }
Beispiel #5
0
        /// <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();
        }
Beispiel #6
0
        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!");
            }
        }
Beispiel #7
0
        public override void GetImageAsync(DownloadTexture.Completion _onCompletion)
        {
            if (m_user == null)
            {
                if (_onCompletion != null)
                {
                    _onCompletion(null, Constants.kGameServicesUserAuthMissingError);
                }

                return;
            }

            m_user.GetImageAsync(_onCompletion);
        }
Beispiel #8
0
 public override void GetImageAsync(DownloadTexture.Completion _onCompletion)
 {
     if (_onCompletion != null)
     {
         if (m_image == null)
         {
             _onCompletion(null, "Texture not found.");
         }
         else
         {
             _onCompletion(m_image, null);
         }
     }
 }
Beispiel #9
0
 public override void GetImageAsync(DownloadTexture.Completion _onCompletion)
 {
     if (_onCompletion != null)
     {
         if (m_user != null)
         {
             m_user.GetImageAsync(_onCompletion);
         }
         else
         {
             _onCompletion(null, "Local user not found. Authenticate first.");
         }
     }
 }
        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);
            }
        }
Beispiel #11
0
        /// <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();
        }
Beispiel #12
0
 /// <summary>
 /// Asynchronously loads the image.
 /// </summary>
 /// <param name="_onCompletion">Callback to be triggered after loading the image.</param>
 public abstract void GetImageAsync(DownloadTexture.Completion _onCompletion);