Example #1
0
    // static int count = 0;
    public static AssetBundle LoadFromFile(string fullpath, out Stream fileStream)
    {
        // var watch = new System.Diagnostics.Stopwatch();
        // watch.Start();
        // Debug.Log("ASSETBUNDLE:" + fullpath + " : " + (count ++));
        fileStream = null;
#if UNITY_EDITOR
        FileStream fs = File.OpenRead(fullpath);
        byte []    bs = new byte[fs.Length];
        fs.Read(bs, 0, (int)fs.Length);
        decode(bs, 0, (int)fs.Length);
        return(AssetBundle.LoadFromMemory(bs));
#else
        AssetBundle   ab = null;
        EncryptStream et = new EncryptStream(fullpath);
        if (et.Exist())
        {
            ab = AssetBundle.LoadFromStream(et);
            if (ab != null)
            {
                fileStream = et;
            }
        }
        else
        {
            et.Dispose();
        }
        // ab = AssetBundle.LoadFromFile(fullpath);

        // watch.Stop();
        // UnityEngine.Debug.Log(string.Format("LoadFromStream bundle dela time {0}ms, {1}", watch.ElapsedMilliseconds, fullpath));
        return(ab);
#endif
    }
Example #2
0
    public static AssetBundleCreateRequest LoadFromFileAsync(string fullpath, out Stream fileStream)
    {
        // Debug.Log("ASSETBUNDLE ASYNC:" + fullpath + " : " + (count++));

        fileStream = null;

#if UNITY_EDITOR
        FileStream fs = File.OpenRead(fullpath);
        byte[]     bs = new byte[fs.Length];
        fs.Read(bs, 0, (int)fs.Length);
        decode(bs, 0, (int)fs.Length);
        return(AssetBundle.LoadFromMemoryAsync(bs));
#else
        AssetBundleCreateRequest req = null;
        EncryptStream            et  = new EncryptStream(fullpath);
        if (et.Exist())
        {
            fileStream = et;
            req        = AssetBundle.LoadFromStreamAsync(et);
        }

        return(req);
#endif
    }