Example #1
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);
                }
            }
        }
Example #2
0
        private void LoadContactsImageAtIndex(int _index)
        {
            AddressBookContact _contactInfo = m_contactsInfo[_index];

            _contactInfo.GetImageAsync((Texture2D _texture, string _error) => {
                if (!string.IsNullOrEmpty(_error))
                {
                    DebugUtility.Logger.LogError(Constants.kDebugTag, "[AddressBook] Contact Picture download failed " + _error);
                    m_contactPictures[_index] = null;
                }
                else
                {
                    m_contactPictures[_index] = _texture;
                }
            });
        }
        public override void OnEnter()
        {
#if USES_ADDRESS_BOOK
            try
            {
                AddressBookContact _contactInfo = AddressBookUtils.contactsInfoList[atIndex.Value];

                // Update properties
                firstName.Value       = _contactInfo.FirstName;
                lastName.Value        = _contactInfo.LastName;
                phoneNumberList.Value = (_contactInfo.PhoneNumberList == null) ? null : string.Join(";", _contactInfo.PhoneNumberList);
                emailList.Value       = (_contactInfo.EmailIDList == null) ? null : string.Join(";", _contactInfo.EmailIDList);

                // If required, download the image
                if (loadImage.Value)
                {
                    _contactInfo.GetImageAsync((Texture2D _image, string _error) => {
                        // Update image property value
                        image.Value = _image;

                        OnActionDidFinish();

                        return;
                    });
                }
                else
                {
                    // Update image property value
                    image.Value = null;

                    OnActionDidFinish();

                    return;
                }
            }
            catch (System.Exception _exception)
            {
                Debug.Log(_exception.Message);

                OnActionDidFail();

                return;
            }
#endif
        }
        private void DoAction()
        {
#if USES_ADDRESS_BOOK
            int _startIndex        = startIndex.Value;
            int _endIndex          = _startIndex + count.Value - 1;
            int _totalContacts     = AddressBookUtils.GetContactsCount();
            int _imagesToLoad      = count.Value;
            int _loadedImagesCount = 0;

            if (_startIndex < 0 || _startIndex >= _totalContacts)
            {
                OnActionDidFail();

                return;
            }

            if (_endIndex < _startIndex || _endIndex >= _totalContacts)
            {
                OnActionDidFail();

                return;
            }

            // Start downloading contacts image
            for (int _iter = _startIndex; _iter <= _endIndex; _iter++)
            {
                AddressBookContact _currentContact = AddressBookUtils.contactsInfoList[_iter];

                _currentContact.GetImageAsync((Texture2D _image, string _error) => {
                    // Update download completed count
                    _loadedImagesCount++;

                    // Check if we are done with downloading
                    if (_loadedImagesCount == _imagesToLoad)
                    {
                        OnActionDidFinish();

                        return;
                    }
                });
            }
#endif
        }