Esempio n. 1
0
 void ReleaseTexture(_TextureHandle h)
 {
     if (h.State == LoadState.LOADING)
     {
         return;
     }
     h.deleteTime = Time.realtimeSinceStartup;
     h.State      = LoadState.DEAD;
     deads.Add(h);
 }
Esempio n. 2
0
    IEnumerator LoadTexture(_TextureHandle h)
    {
                #if UNITY_EDITOR
        string path = "file:" + Application.streamingAssetsPath + "/Windows/" + h.Name;
                #elif UNITY_IPHONE
        string path = Application.dataPath + "/Raw" + "/UIAtlas/" + h.Name + ".t2d";
                #elif UNITY_ANDROID
        string path = Application.streamingAssetsPath + "/Android/" + h.Name;
                #endif
        SimpleLog.Log("loading " + path);
        float beging = Time.realtimeSinceStartup;
        WWW   www    = new WWW(path);
        while (!www.isDone)
        {
            yield return(null);
        }
        string[] list = www.assetBundle.GetAllAssetNames();


        AssetBundleRequest request = www.assetBundle.LoadAssetWithSubAssetsAsync <Sprite> (list [0]);
        //AssetBundleRequest request = www.assetBundle.LoadAssetAsync (list [0],typeof(Sprite));
        while (!request.isDone)
        {
            yield return(null);
        }


        //foreach (Object s in request.allAssets) {
        //Debug.LogError (s.name);
        //}
        //Sprite _spr = request.allAssets[0] as Sprite;
        Sprite [] _sprs = new Sprite[request.allAssets.Length];
        for (int i = 0, len = request.allAssets.Length; i < len; i++)
        {
            _sprs[i] = (Sprite)request.allAssets[i];
        }
        h.SetTexture(_sprs);


        www.assetBundle.Unload(false);
        h.State      = LoadState.LOADED;
        h.deleteTime = Time.realtimeSinceStartup;
        float end = Time.realtimeSinceStartup;
        SimpleLog.Log("loading finish " + path + "used " + (end - beging).ToString() + "s");
        if (h.count == 0)
        {
            ReleaseTexture(h);
        }
    }
Esempio n. 3
0
    public void ReleaseAtlasTexture(string name)
    {
        _TextureHandle h = null;

        if (!textures.TryGetValue(name, out h))
        {
            return;
        }
        if (h.count > 0)
        {
            h.count--;
        }
        if (h.count == 0)
        {
            ReleaseTexture(h);
        }
    }
Esempio n. 4
0
    void Update()
    {
                #if UNITY_EDITOR
        //Debug.Log(Application.isPlaying.ToString());
        //Debug.Log(UnityEditor.EditorApplication.isPlaying.ToString() + "  "+UnityEditor.EditorApplication.isPaused.ToString());
        if (!Application.isPlaying)
        {
            GameObject.DestroyImmediate(this.gameObject, true);
            return;
        }
                #endif

        int _len = deads.Count;
        for (int i = 0; i < _len;)
        {
            _TextureHandle h = deads [i];
            if (h.State == LoadState.DEAD)
            {
                if (Time.realtimeSinceStartup - h.deleteTime > deleteTime)
                {
                    SimpleLog.Log("Auto Release " + h.Name);
                    deads.Remove(h);
                    textures.Remove(h.Name);

                    for (int j = 0; j < h.textures.Length; j++)
                    {
                        GameObject.DestroyImmediate(h.textures [j].texture, true);
                        GameObject.DestroyImmediate(h.textures[j], true);
                    }

                    _len--;
                }
                else
                {
                    i++;
                }
            }
            else
            {
                deads.RemoveAt(i);
                _len--;
            }
        }
    }
Esempio n. 5
0
    public TextureHandle LoadAtlasTexture(string path)
    {
        _TextureHandle h = null;

        if (!textures.TryGetValue(path, out h))
        {
            h = new _TextureHandle();
            h.SetPath(path);
            h.State         = LoadState.NONE;
            textures [path] = h;
            StartCoroutine(LoadTexture(h));
        }
        if (h.State == LoadState.DEAD)
        {
            h.State = LoadState.LOADED;
        }
        h.count++;
        return(h);
    }