示例#1
0
        IEnumerator ExtractAssetObjectFromAssetBundle <T>(
            WWW www,
            AssetBundleSettings.AssetBundleInfo abInfo,
            string path,
            Action <T> onFinish,
            Action <string> onFailed) where T : UnityEngine.Object
        {
            string      assetName   = System.IO.Path.GetFileNameWithoutExtension(abInfo.assetBundle);
            AssetBundle assetBundle = null;

            if (AssetBundleSettings.IsEncryptAssetBundle)
            {
                byte[] decryptedBytes = EncryptDecryptUtil.DecryptBytesToBytes(www.bytes, AssetBundleSettings.PASSWORD_ENCRYPT_DECRYPT_ASSETBUNDLE);
                AssetBundleCreateRequest assetBundleCreateRequest = AssetBundle.LoadFromMemoryAsync(decryptedBytes);
                yield return(assetBundleCreateRequest);

                assetBundle = assetBundleCreateRequest.assetBundle;
            }
            else
            {
                assetBundle = www.assetBundle;
            }

            // Load the object asynchronously
            AssetBundleRequest request = assetBundle.LoadAssetAsync(assetName);

            // Wait for completion
            while (!request.isDone)
            {
                yield return(null);
            }
            yield return(new WaitForEndOfFrame());

            UnityEngine.Object obj = request.asset;
            if (obj != null)
            {
                if (obj is Texture2D && typeof(T) == typeof(Sprite))
                {
                    Texture2D texture = request.asset as Texture2D;
                    Sprite    spr     = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f));
                    onFinish(spr as T);
                }
                else
                {
                    onFinish(obj as T);
                }
                new WaitForEndOfFrame();
                assetBundle.Unload(false);
                yield break;
            }
            else
            {
                onFailed("Can not extract『" + abInfo.assetBundle + "』from LocalPath: " + path);
            }
        }
示例#2
0
        IEnumerator ExtractSceneNameAndLoadSceneFromAssetBundle(
            WWW www,
            AssetBundleSettings.AssetBundleInfo abInfo,
            string path,
            UnityEngine.SceneManagement.LoadSceneMode loadSceneMode,
            Action <string> onFinish,
            Action <string> onFailed)
        {
            // Load the object asynchronously
            AssetBundle assetBundle = null;

            if (AssetBundleSettings.IsEncryptAssetBundle)
            {
                byte[] decryptedBytes = EncryptDecryptUtil.DecryptBytesToBytes(www.bytes, AssetBundleSettings.PASSWORD_ENCRYPT_DECRYPT_ASSETBUNDLE);
                AssetBundleCreateRequest assetBundleCreateRequest = AssetBundle.LoadFromMemoryAsync(decryptedBytes);
                yield return(assetBundleCreateRequest);

                assetBundle = assetBundleCreateRequest.assetBundle;
            }
            else
            {
                assetBundle = www.assetBundle;
            }
            if (assetBundle != null)
            {
                string[] scenePath = assetBundle.GetAllScenePaths();
                string   sceneName = Path.GetFileNameWithoutExtension(scenePath [0]);
                var      asyncLoad = UnityEngine.SceneManagement.SceneManager.LoadSceneAsync(sceneName, loadSceneMode);
                yield return(asyncLoad);

                onFinish(sceneName);
                assetBundle.Unload(false);
            }
            else
            {
                onFailed("Can not extract『" + abInfo.assetBundle + "』from LocalPath: " + path);
            }
        }
示例#3
0
        /// <summary>
        /// Gets the asset bundle version file.
        /// </summary>
        /// <returns>The asset bundle version file.</returns>
        /// <param name="success">Success.</param>
        /// <param name="failed">Failed.</param>
        IEnumerator GetAssetBundleVersionFile(Action <string> success, Action <string, string> failed)
        {
            string abVersionFileUrl = AssetBundleSettings.GetAssetBundleServerURL() + "/" + AssetBundleSettings.ASSETBUNDLE_VERSION_FILE_NAME;
            WWW    _www             = new WWW(abVersionFileUrl);

            yield return(_www);

            if (string.IsNullOrEmpty(_www.error))
            {
                if (AssetBundleSettings.IsEncryptAssetBundle)
                {
                    byte[] decryptedBytes = EncryptDecryptUtil.DecryptBytesToBytes(_www.bytes, AssetBundleSettings.PASSWORD_ENCRYPT_DECRYPT_ASSETBUNDLE);
                    _assetBundleVersionDB = _objectPacker.Unpack <AssetBundleSettings.AssetBundleTargetDB> (decryptedBytes);
                }
                else
                {
                    _assetBundleVersionDB = _objectPacker.Unpack <AssetBundleSettings.AssetBundleTargetDB> (_www.bytes);
                }
                yield return(null);

                yield return(StartCoroutine(SettingDownloadABList(_www.bytes)));

                if (success != null)
                {
                    success(abVersionFileUrl);
                }
            }
            else
            {
                if (failed != null)
                {
                    failed(abVersionFileUrl, _www.error);
                }
            }
            yield return(null);
        }
示例#4
0
 protected void Page_Load(object sender, EventArgs e)
 {
     EncryptDecryptUtil.Encrypt("5441191000005226", "F8660BF9063B1BBEFEA2BC413C8514FE", Server.MapPath("/csharpDemo2/code.txt"));
     EncryptDecryptUtil.Decrypt(Server.MapPath("/csharpDemo2/code.txt"), Server.MapPath("/csharpDemo2/result.txt"), "F8660BF9063B1BBEFEA2BC413C8514FE");
 }
示例#5
0
        /// <summary>
        /// Settings the download AB list. Get total size needed to be downloaded
        /// </summary>
        IEnumerator SettingDownloadABList(byte[] newAssetBundleAssetVersion)
        {
            //Load local assetbundle version
            string path = AssetBundleSettings.localFolderPathSaveAB + "/" + AssetBundleSettings.ASSETBUNDLE_VERSION_FILE_NAME;

            if (File.Exists(path))
            {
                System.Uri url  = new System.Uri(path);
                WWW        _www = new WWW(url.AbsoluteUri);
                yield return(new WaitUntil(() => {
                    return _www.isDone;
                }));

                AssetBundleSettings.AssetBundleTargetDB _oldVersionDB = null;
                if (AssetBundleSettings.IsEncryptAssetBundle)
                {
                    byte[] decryptedBytes = EncryptDecryptUtil.DecryptBytesToBytes(_www.bytes, AssetBundleSettings.PASSWORD_ENCRYPT_DECRYPT_ASSETBUNDLE);
                    _oldVersionDB = _objectPacker.Unpack <AssetBundleSettings.AssetBundleTargetDB> (decryptedBytes);
                }
                else
                {
                    _oldVersionDB = _objectPacker.Unpack <AssetBundleSettings.AssetBundleTargetDB> (_www.bytes);
                }

                _downloadList = new List <AssetBundleSettings.AssetBundleInfo> ();
                foreach (var assetBundleInfo  in _assetBundleVersionDB.lstAssetBundleInfo)
                {
                    AssetBundleSettings.AssetBundleInfo oldABInfo = _oldVersionDB.lstAssetBundleInfo.Where(_ => _.assetBundle == assetBundleInfo.assetBundle).FirstOrDefault();
                    if (oldABInfo == null)
                    {
                        _downloadList.Add(assetBundleInfo);
                    }
                    else
                    {
                        if (assetBundleInfo.version != oldABInfo.version)
                        {
                            _downloadList.Add(assetBundleInfo);
                        }
                        else if (assetBundleInfo.hashAssetBundle != oldABInfo.hashAssetBundle)
                        {
                            _downloadList.Add(assetBundleInfo);
                        }
                    }
                }
            }
            else
            {
                _downloadList = new List <AssetBundleSettings.AssetBundleInfo> (_assetBundleVersionDB.lstAssetBundleInfo);
            }

            if (!Directory.Exists(AssetBundleSettings.localFolderPathSaveAB))
            {
                Directory.CreateDirectory(AssetBundleSettings.localFolderPathSaveAB);
            }
            #if UNITY_IPHONE
            //No backup to cloud
            UnityEngine.iOS.Device.SetNoBackupFlag(path);
            #endif
            yield return(null);

            File.WriteAllBytes(path, newAssetBundleAssetVersion);

            totalSize = 0;
            foreach (var item in _downloadList)
            {
                totalSize += item.size;
            }

            yield return(null);
        }