示例#1
0
 protected virtual void HandleOnImageLoaded(ExternImgFile p_image)
 {
     if ((string.IsNullOrEmpty(Key) && (p_image == null || string.IsNullOrEmpty(p_image.Url))) ||
         (p_image != null && string.Equals(p_image.Url, Key)))
     {
         if (ImageComponent != null && !string.IsNullOrEmpty(Key) && (p_image.Sprite != null || string.IsNullOrEmpty(p_image.Error)))
         {
             Sprite = p_image.Sprite;
         }
         if (Sprite == null || !string.IsNullOrEmpty(p_image.Error))
         {
             ApplyDefaultSpriteInImageComponent();
         }
         if (OnApplyImageCallback != null)
         {
             OnApplyImageCallback.Invoke();
         }
         if (!_canUnregisterOnDisable)
         {
             _canUnregisterOnDisable = true;
             if (!gameObject.activeInHierarchy || !gameObject.activeSelf || !enabled)
             {
                 UnregisterEvents();
             }
         }
         _isDirty = false;
     }
     else if (Sprite == null && DefaultSprite != null)
     {
         ApplyDefaultSpriteInImageComponent();
     }
 }
示例#2
0
        protected void Hide_Internal(ExternImgFile result, bool forceCallEventIfFailed, bool callHide)
        {
            if (callHide)
            {
                Hide();
            }

            UnregisterEvents();
            if (result != null && !string.IsNullOrEmpty(result.Url))
            {
                if (_onPickerSucessCallback != null)
                {
                    _onPickerSucessCallback(result);
                }
                _onPickerSucessCallback = null;
                if (OnPickerSucess != null)
                {
                    OnPickerSucess.Invoke(result);
                }
            }
            else
            {
                if (forceCallEventIfFailed)
                {
                    CrossPickerServices.CallPickerFinishEvent(result);
                }
                if (_onPickerFailedCallback != null)
                {
                    _onPickerFailedCallback();
                }
                _onPickerFailedCallback = null;
                OnPickerFailed.Invoke();
            }
            base.Hide();
        }
示例#3
0
 public virtual void SetExternImgFile(ExternImgFile p_externImg)
 {
     if (p_externImg != null)
     {
         Key    = p_externImg.Url;
         Sprite = p_externImg.Sprite;
     }
 }
示例#4
0
        private ExternImgFile GetImageFromPath(string p_key, System.Action <ExternImgFile> p_callback)
        {
            ExternImgFile v_wwwImage = CreateImageStruct(p_key);

            if (p_callback != null)
            {
                p_callback(v_wwwImage);
            }
            return(v_wwwImage);
        }
示例#5
0
 protected virtual void HandleOnPickerFinish(ExternImgFile result)
 {
     CrossPickerServices.OnPickerFinish -= HandleOnPickerFinish;
     if (m_ExternalResources != null)
     {
         m_ExternalResources.Key = result != null ? result.Url : "";
         m_ExternalResources.TryApply();
     }
     Hide_Internal(result, false, true);
 }
示例#6
0
        protected internal static void CallPickerFinishEvent(ExternImgFile p_file)
        {
            if (p_file != null)
            {
                ExternalResources.AddImageIntoCache(p_file);
            }

            if (OnPickerFinish != null)
            {
                OnPickerFinish(p_file);
            }
        }
示例#7
0
        protected internal static void CallPickerFinishEvent(string p_key, Sprite p_spriteReturned)
        {
            ExternImgFile v_callback = null;

            if (p_spriteReturned != null && p_spriteReturned.texture != null)
            {
                v_callback         = new ExternImgFile();
                v_callback.Error   = "";
                v_callback.Status  = Kyub.Async.AsyncStatusEnum.Done;
                v_callback.Texture = p_spriteReturned.texture;
                v_callback.Sprite  = p_spriteReturned;
                v_callback.Url     = v_callback.Url != null ? p_key : "";
            }
            CallPickerFinishEvent(v_callback);
        }
示例#8
0
        protected override void Apply()
        {
            if (ImageComponent != null)
            {
                var v_isDownloading = ExternalResources.IsDownloading(Key);
                if (string.IsNullOrEmpty(Key) || !v_isDownloading ||
                    (_canUnregisterOnDisable && v_isDownloading)) //someone called this request before this external image
                {
                    ExternImgFile v_callback = !ExternalResources.IsLoaded(Key) ?
                                               ExternalResources.ReloadSpriteAsync(Key, ApplySprite) : ExternalResources.LoadSpriteAsync(Key, ApplySprite);
                    if (v_callback != null)
                    {
                        if (v_callback.IsProcessing())
                        {
                            //Reset image
                            if (/*DefaultSprite != null &&*/ Sprite != DefaultSprite)
                            {
                                ApplyDefaultSpriteInImageComponent();
                            }

                            _canUnregisterOnDisable = false;
                            if (OnRequestDownloadImageCallback != null)
                            {
                                OnRequestDownloadImageCallback.Invoke();
                            }
                        }
                        else
                        {
                            HandleOnImageLoaded(v_callback);
                        }
                    }
                }
                else
                {
                    if (/*DefaultSprite != null &&*/ Sprite != DefaultSprite)
                    {
                        ApplyDefaultSpriteInImageComponent();
                    }
                    SetDirty();
                }
            }
        }
        protected virtual void HandleOnPickerReturn(ExternImgFile p_file)
        {
            CrossPickerServices.OnPickerFinish -= HandleOnPickerReturn;

            if (p_file == null || string.IsNullOrEmpty(p_file.Url))
            {
                HandleOnHide();
            }
            else
            {
                if (m_externalImage != null && p_file != null)
                {
                    m_externalImage.Key = p_file.Url;
                }

                if (OnPickerSucessCallback != null)
                {
                    OnPickerSucessCallback.Invoke(p_file != null ? p_file.Url : "");
                }
            }
        }
示例#10
0
        protected ExternImgFile CreateImageStruct(string p_key)
        {
            ExternImgFile v_wwwImage = null;

            _cachedImages.TryGetValue(p_key, out v_wwwImage);
            if (v_wwwImage == null)
            {
                v_wwwImage = new ExternImgFile();
            }
            v_wwwImage.Error   = null;
            v_wwwImage.Url     = p_key;
            v_wwwImage.Texture = !string.IsNullOrEmpty(p_key) && CrossFileProvider.FileExists(p_key)? NativeGallery.LoadImageAtPath(p_key, MaxImageLoadSize, false, false) : null;
            if (v_wwwImage.Texture != null)
            {
                v_wwwImage.Sprite = Sprite.Create(v_wwwImage.Texture, new Rect(0, 0, v_wwwImage.Texture.width, v_wwwImage.Texture.height), new Vector2(0.5f, 0.5f));
            }
            if (v_wwwImage.Texture == null)
            {
                v_wwwImage.Error = "Unable to get image from path";
            }
            v_wwwImage.Status    = AsyncStatusEnum.Done;
            _cachedImages[p_key] = v_wwwImage;
            return(v_wwwImage);
        }
示例#11
0
 public void ShareExternalImgFile(ExternImgFile p_externImgFile)
 {
     ShareFile(p_externImgFile != null ? p_externImgFile.Url : "");
 }