Esempio n. 1
0
        public IAsyncOperation <Texture2D> getImageAsync(string uri, bool loadFromDefaults)
        {
            var result = new AsyncCompletionSource <Texture2D>();

            if (string.IsNullOrEmpty(uri))
            {
                result.SetResult(null);
            }
            else
            {
                if (images.ContainsKey(uri))
                {
                    result.SetResult(images[uri].Texture);
                }
                else
                {
                    var holder = new Texture2DHolder(fixPath(uri), type);
                    holder.LoadAsync()
                    .Then(done =>
                    {
                        Debug.Log("Done loading " + uri);
                        if (done)
                        {
                            if (!images.ContainsKey(uri))
                            {
                                images.Add(uri, holder);
                            }
                            result.SetResult(holder.Texture);
                        }
                        else if (loadFromDefaults)
                        {
                            // Load from defaults
                            holder = new Texture2DHolder(defaultPath(uri), type);
                            if (holder.Loaded())
                            {
                                Debug.Log(uri + " loaded from defaults...");
                                if (!images.ContainsKey(uri))
                                {
                                    images.Add(uri, holder);
                                }
                                result.SetResult(holder.Texture);
                            }
                            else
                            {
                                Debug.LogWarning("Unable to load " + uri);
                                result.SetResult(null);
                            }
                        }
                        else
                        {
                            result.SetResult(null);
                        }
                    });
                }
            }
            return(result);
        }
Esempio n. 2
0
        private void createOldMethod()
        {
            xmld = new XmlDocument();
            Texture2DHolder auxHolder;
            eFrame          tmp;
            int             num  = 1;
            string          ruta = "";

            switch (type)
            {
            case ResourceManager.LoadingType.RESOURCES_LOAD:
                ruta      = path + "_" + intToStr(num);
                auxHolder = new Texture2DHolder(ruta, this.type);

                while (auxHolder.Loaded())
                {
                    tmp          = new eFrame();
                    tmp.Duration = 500;
                    tmp.Image    = auxHolder.Texture;
                    frames.Add(tmp);

                    num++;
                    ruta      = path + "_" + intToStr(num);
                    auxHolder = new Texture2DHolder(ruta, this.type);
                }
                break;

            case ResourceManager.LoadingType.SYSTEM_IO:
#if !(UNITY_WEBPLAYER || UNITY_WEBGL)
                ruta = path + "_" + intToStr(num);
                string working_extension = "";

                foreach (string extension in extensions)
                {
                    auxHolder = new Texture2DHolder(ruta, this.type);
                    if (System.IO.File.Exists(ruta + extension))
                    {
                        working_extension = extension;
                        break;
                    }
                }

                ruta = ruta + working_extension;
                while (System.IO.File.Exists(ruta))
                {
                    tmp          = new eFrame();
                    tmp.Duration = 500;
                    tmp.Image    = new Texture2DHolder(ruta, this.type).Texture;
                    frames.Add(tmp);
                    num++;
                    ruta = path + "_" + intToStr(num) + working_extension;
                }
#endif
                break;
            }
        }
Esempio n. 3
0
        public Texture2D getImage(string uri, bool loadFromDefaults)
        {
            if (string.IsNullOrEmpty(uri))
            {
                return(null);
            }

            if (images.ContainsKey(uri))
            {
                return(images[uri].Texture);
            }
            else
            {
                var holder = new Texture2DHolder(fixPath(uri), type);
                holder.Load();
                if (holder.Loaded())
                {
                    images.Add(uri, holder);
                    return(holder.Texture);
                }
                else if (loadFromDefaults)
                {
                    // Load from defaults
                    holder = new Texture2DHolder(defaultPath(uri), type);
                    holder.Load();
                    if (holder.Loaded())
                    {
                        Debug.Log(uri + " loaded from defaults...");
                        images.Add(uri, holder);
                        return(holder.Texture);
                    }
                    else
                    {
                        Debug.LogWarning("Unable to load " + uri);
                        return(null);
                    }
                }
                else
                {
                    return(null);
                }
            }
        }
Esempio n. 4
0
 public Texture2D getImage(string uri)
 {
     if (images.ContainsKey(uri))
     {
         return(images[uri].Texture);
     }
     else
     {
         Texture2DHolder holder = new Texture2DHolder(Path + uri, type);
         if (holder.Loaded())
         {
             images.Add(uri, holder);
             return(holder.Texture);
         }
         else
         {
             return(null);
         }
     }
 }
Esempio n. 5
0
        public Sprite getSprite(string uri)
        {
            if (uri == null)
            {
                return(null);
            }

            if (images.ContainsKey(uri))
            {
                return(images[uri].Sprite);
            }
            else
            {
                var holder = new Texture2DHolder(fixPath(uri), type);
                holder.Load();
                if (holder.Loaded())
                {
                    images.Add(uri, holder);
                    return(holder.Sprite);
                }
                else
                {
                    // Load from defaults
                    holder = new Texture2DHolder(defaultPath(uri), type);
                    holder.Load();
                    if (holder.Loaded())
                    {
                        Debug.Log(uri + " loaded from defaults...");
                        images.Add(uri, holder);
                        return(holder.Sprite);
                    }
                    else
                    {
                        Debug.LogWarning("Unable to load " + uri);
                        return(null);
                    }
                }
            }
        }