Example #1
0
        private void LoadAuto_INTERNAL(ILoadableResource resourceController, System.Action onDataLoaded, System.Action onComplete, string customResourcePath = null)
        {
            var image = resourceController as IImageComponent;

            System.Action <Object> setup = (data) => {
                if (data == null)
                {
                    WindowSystemLogger.Error(image, string.Format("Error in ResourcesManager: Required resource can't be loaded. Resource: {0}", image.GetResource().GetId()));
                    return;
                }

                var res = resourceController.GetResource();
                res.loadedObject   = data;
                res.loadedObjectId = data.GetInstanceID();
                res.loaded         = true;
            };

            Graphic source = image.GetImageSource();

            if (source != null)
            {
                this.LoadAndSetup_INTERNAL <Sprite>(image, source, (data) => {
                    setup.Invoke(data);
                    image.SetImage(data, () => {
                        if (onComplete != null)
                        {
                            onComplete.Invoke();
                        }
                    });

                    if (onDataLoaded != null)
                    {
                        onDataLoaded.Invoke();
                    }
                }, customResourcePath);
            }
            else
            {
                source = image.GetRawImageSource();
                if (source != null)
                {
                    this.LoadAndSetup_INTERNAL <Texture>(image, source, (data) => {
                        setup.Invoke(data);
                        image.SetImage(data, () => {
                            if (onComplete != null)
                            {
                                onComplete.Invoke();
                            }
                        });

                        if (onDataLoaded != null)
                        {
                            onDataLoaded.Invoke();
                        }
                    }, customResourcePath);
                }
            }
        }
Example #2
0
        private void LoadAndSetup_INTERNAL <T>(IImageComponent image, Graphic graphic, System.Action <T> callbackOnLoad, string customResourcePath = null) where T : Object
        {
            //var key = (image as WindowComponent).GetInstanceID();

            //Coroutine coroutine;

            /*if (this.loading.TryGetValue(key, out coroutine) == true) {
             *
             *      this.StopCoroutine(coroutine);
             *      this.loading.Remove(key);
             *
             * }*/

            /*this.loaded.ForEach(z => { z.references.Remove(image as WindowComponent); });
             * this.loaded.RemoveAll(x => {
             *
             *      if (x.references.Count == 0) {
             *
             *              //if (x.loadedObjectId < 0) Object.Destroy(x.loadedObject);
             *              return true;
             *
             *      }
             *
             *      return false;
             *
             * });*/

            Item item;

            if (this.IsLoaded <T>(image as WindowComponent, image.GetResource(), out item, callbackOnLoad) == false)
            {
                /*coroutine = */ this.StartCoroutine(image.GetResource().Load <T>(image, graphic, customResourcePath, (data) => {
                    if (data == null)
                    {
                        WindowSystemLogger.Error(image, string.Format("Error in ResourcesManager: Required resource can't loaded. Resource: {0}", image.GetResource().GetId()));
                        return;
                    }

                    item.@object = data;

                    item.loadedObject   = data;
                    item.loadedObjectId = data.GetInstanceID();
                    item.loaded         = true;

                    if (item.onObjectLoaded != null)
                    {
                        item.onObjectLoaded.Invoke();
                    }
                    callbackOnLoad(data);

                    //this.loading.Remove(key);
                }));

                //this.loading.Add(key, coroutine);
            }
        }
Example #3
0
        private void LoadAuto_INTERNAL(ILoadableResource resourceController, System.Action onDataLoaded, System.Action onComplete, System.Action onFailed = null, string customResourcePath = null)
        {
            var image = resourceController as IImageComponent;
            var async = image.GetResource().async;

            System.Action <Object> setup = (data) => {
                if (data == null)
                {
                    if (onFailed != null)
                    {
                        onFailed.Invoke();
                    }
                    WindowSystemLogger.Error(image, string.Format("Error in ResourcesManager: Required resource can't be loaded. Resource: {0}", image.GetResource().GetId()));
                    return;
                }
            };

            var source = image.GetGraphicSource();

            var isMaterial = image.GetResource().IsMaterialLoadingType();

            if (isMaterial == false)
            {
                MovieSystem.UnregisterOnUpdateTexture(this.ValidateTexture);
            }

            if (isMaterial == true)
            {
                this.LoadRefCounter_INTERNAL <Material>(resourceController, (data) => {
                    setup.Invoke(data);
                    image.SetMaterial(data, callback: () => {
                        if (onComplete != null)
                        {
                            onComplete.Invoke();
                        }
                    });

                    if (onDataLoaded != null)
                    {
                        onDataLoaded.Invoke();
                    }
                }, onFailed, async, customResourcePath);
            }
            else
            {
                if (source is Image)
                {
                    this.LoadRefCounter_INTERNAL <Sprite>(resourceController, (data) => {
                        setup.Invoke(data);
                        image.SetImage(data, () => {
                            if (onComplete != null)
                            {
                                onComplete.Invoke();
                            }
                        });

                        if (onDataLoaded != null)
                        {
                            onDataLoaded.Invoke();
                        }
                    }, onFailed, async, customResourcePath);
                }
                else if (source is RawImage)
                {
                    this.LoadRefCounter_INTERNAL <Texture>(resourceController, (data) => {
                        setup.Invoke(data);
                        image.SetImage(data, () => {
                            if (onComplete != null)
                            {
                                onComplete.Invoke();
                            }
                        });

                        if (isMaterial == true)
                        {
                            MovieSystem.RegisterOnUpdateTexture(this.ValidateTexture);
                        }

                        if (onDataLoaded != null)
                        {
                            onDataLoaded.Invoke();
                        }
                    }, onFailed, async, customResourcePath);
                }
            }
        }