Beispiel #1
0
    public void tryToSavePicToLocal(SaveBodyEntity entity)
    {
        Debug.Log("try to save data to local ---> " + entity.savepath);
        Thread thread = new Thread(new ParameterizedThreadStart(saveToFile));

        thread.IsBackground = true;
        thread.Start(entity);
    }
Beispiel #2
0
        public static SaveBodyEntity create(string name, byte[] datas)
        {
            SaveBodyEntity entity = new SaveBodyEntity();

            entity.path  = Application.persistentDataPath;
            entity.name  = name;
            entity.datas = datas;
            return(entity);
        }
Beispiel #3
0
    void saveToFile(object obj)
    {
        SaveBodyEntity entity = (SaveBodyEntity)obj;
        FileInfo       file   = new FileInfo(entity.savepath);
        FileStream     stream = null;

        if (!file.Exists)
        {
            stream = file.Create();
        }
        else
        {
            stream = file.OpenWrite();
        }
        stream.Write(entity.Datas, 0, entity.Datas.Length);
        stream.Close();
        stream.Dispose();
    }
Beispiel #4
0
 public void loadPic(string name, UITexture texture, Texture src = null)
 {
     if (pic_caches.ContainsKey(name))
     {
         texture.mainTexture = pic_caches[name];
         return;
     }
     if (src == null)
     {
         StartCoroutine(_loadPic(name, texture));
     }
     else
     {
         texture.mainTexture = src;
         pic_caches.Add(name, src);
         tryToSavePicToLocal(SaveBodyEntity.create(name, ((Texture2D)src).EncodeToJPG()));
     }
 }
Beispiel #5
0
    private IEnumerator loadPicFromNet(string name, UITexture texture)
    {
        string path = PIC_PHP_URL + "/uploads/" + name;
        WWW    www  = new WWW(path);

        yield return(www);

        if (www.isDone)
        {
            if (www.error == null)
            {
                texture.mainTexture = www.texture;
                pic_caches.Add(name, www.texture);
                tryToSavePicToLocal(SaveBodyEntity.create(name, www.texture.EncodeToJPG()));
            }
            else
            {//加载失败,继续加载
                StartCoroutine(loadPicFromNet(name, texture));
            }
        }
    }