public void ResourceLoad(object state)
        {
            while (!m_Abort)
            {
                EncryptResourceLoader node = null;
                lock (m_QueueToLoad.SyncRoot)
                {
                    while (m_QueueToLoad.Count <= 0 && !m_Abort)
                    {
                        Monitor.Wait(m_QueueToLoad.SyncRoot);
                    }

                    if (m_Abort)
                    {
                        break;
                    }
                    node = (EncryptResourceLoader)m_QueueToLoad.Dequeue();
                }

                if (node != null)
                {
                    byte[] content         = null;
                    var    assetBundlePath = node.assetBundlePath;
                    try
                    {
#if UNITY_ANDROID && !UNITY_EDITOR
                        if (assetBundlePath.StartsWith(m_StreamingAssetsPath))
                        {
                            var assetPath = assetBundlePath.Substring(m_StreamingPathLength);

                            int assetSize = AndroidAssetLoader.GetStreamAssetLength(assetPath);
                            content = new byte[assetSize];
                            AndroidAssetLoader.GetStreamAssetContent(assetPath, content, assetSize);
                        }
                        else
                        {
                            content = File.ReadAllBytes(assetBundlePath);
                        }
#else
                        content = File.ReadAllBytes(assetBundlePath);
#endif
                    }
                    catch (Exception e)
                    {
                        Debug.LogErrorFormat("Loading asset bundle at path[{0}] error! {1}", assetBundlePath, e.Message);
                    }

                    try
                    {
                        node.bytes  = ms_Decryptor.Invoke(content, node.assetBundleName);
                        node.isDone = true;
                    }
                    catch (Exception e)
                    {
                        node.error = e.Message;
                        Debug.LogErrorFormat("decrypt asset bundle {0} error! {1}", node.assetBundleName, e.Message);
                    }
                }
            }
        }
 public void RequestLoad(EncryptResourceLoader node)
 {
     lock (m_QueueToLoad.SyncRoot)
     {
         m_QueueToLoad.Enqueue(node);
         Monitor.Pulse(m_QueueToLoad.SyncRoot);
     }
 }
        public LoadedAssetBundle(AssetBundleCreateRequest bundleRequest, bool isLoadingAssetBundleManifest)
        {
            m_WWW = null;
            m_IsLoadingAssetBundleManifest = isLoadingAssetBundleManifest;

            m_ReferencedCount    = 1;
            m_AssetBundle        = null;
            m_AssetBundleRequest = bundleRequest;
        }
        public LoadedAssetBundle(EncryptResourceLoader www, bool isLoadingAssetBundleManifest)
        {
            m_WWW = www;
            m_IsLoadingAssetBundleManifest = isLoadingAssetBundleManifest;

            m_ReferencedCount    = 1;
            m_AssetBundle        = null;
            m_AssetBundleRequest = null;
        }
        // Where we actuall call WWW to download the assetBundle.
        static protected bool LoadAssetBundleInternal(string assetBundleName, bool isLoadingAssetBundleManifest)
        {
            if (string.IsNullOrEmpty(assetBundleName))
            {
                return(false);
            }

            // Already loaded.
            LoadedAssetBundle bundle = null;

            m_LoadedAssetBundles.TryGetValue(assetBundleName, out bundle);
            if (bundle != null)
            {
                bundle.m_ReferencedCount++;
                if (bundle.m_AssetBundle != null)
                {
                    return(true);
                }

                return(false);
            }

            if (IsEncryptType(assetBundleName))
            {
                string assetBundlePath = GetEncryPath(m_BaseDownloadingPath + assetBundleName,
                                                      isLoadingAssetBundleManifest, assetBundleName);
                if (!File.Exists(assetBundlePath))
                {
                    assetBundlePath = GetEncryPath(m_BaseInternalPath + assetBundleName, isLoadingAssetBundleManifest, assetBundleName);
                }

                var resourceLoader = new EncryptResourceLoader(assetBundleName, assetBundlePath);
                m_EncryptResourceWorker.RequestLoad(resourceLoader);

                m_LoadedAssetBundles.Add(assetBundleName, new LoadedAssetBundle(resourceLoader, isLoadingAssetBundleManifest));
            }
            else
            {
                string assetBundlePath = GetEncryPath(m_BaseDownloadingPath + assetBundleName,
                                                      isLoadingAssetBundleManifest, assetBundleName);
                if (!File.Exists(assetBundlePath))
                {
                    assetBundlePath = GetEncryPath(m_BaseInternalPath + assetBundleName, isLoadingAssetBundleManifest, assetBundleName);
                }

                var loadedAssetBundle = new LoadedAssetBundle(AssetBundle.LoadFromFileAsync(assetBundlePath),
                                                              isLoadingAssetBundleManifest);
                m_LoadedAssetBundles.Add(assetBundleName, loadedAssetBundle);
            }

            return(false);
        }