Exemple #1
0
        /// <summary>
        /// 下载版本信息文本成功监听
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnHttpReadTextSuccess(object sender, IEventArgs e)
        {
            HttpReadTextEventArgs args = (HttpReadTextEventArgs)e;

            if (args != null)
            {
                if (args.Url == Path.Combine(GameMain.ResourceMG.ResUpdatePath, _assetPlatformVersionText))
                {
                    AssetPlatformVersionInfo assetPlatform = JsonUtility.FromJson <AssetPlatformVersionInfo>(args.Additive);
                    string platformName = GameFrameworkCommon.GetPlatformName();
                    if (assetPlatform.Platforms.Contains(platformName))
                    {
                        //资源的更新路径
                        GameMain.ResourceMG.ResUpdatePath = Path.Combine(GameMain.ResourceMG.ResUpdatePath, platformName);

                        //读取远程的文本
                        string remotePath = Path.Combine(GameMain.ResourceMG.ResUpdatePath, _assetVersionTxt);
                        GameMain.WebRequestMG.ReadHttpText(remotePath);
                    }
                    else
                    {
#if UNITY_EDITOR
                        UnityEngine.Debug.Log("服务器上不包含当前平台的资源文件!");
#endif
                    }
                }
                else if (args.Url == Path.Combine(GameMain.ResourceMG.ResUpdatePath, _assetVersionTxt))
                {
                    _remoteVersion = JsonUtility.FromJson <AssetBundleVersionInfo>(args.Additive);
                    if (_remoteVersion == null)
                    {
#if UNITY_EDITOR
                        UnityEngine.Debug.LogError("Remote version is null.");
#endif
                        return;
                    }

                    if (!CompareVersion())
                    {
                        //更新资源
                        UpdateResource();
                        //下载资源
                        DownloadResource();
                    }

#if UNITY_EDITOR
                    Debug.Log(">>>>>资源已经是最新版本了!");
#endif

                    //资源更新完成
                    _resourceUpdateDone = true;
                }
            }
        }
            static void GenerateAssetPlatformVersionInfo()
            {
                AssetPlatformVersionInfo platforms = new AssetPlatformVersionInfo();

                platforms.Version   = 100000;
                platforms.Platforms = new List <string>()
                {
                    "StandaloneWindows", "IOS", "Android"
                };

                string platformVersion = EditorJsonUtility.ToJson(platforms);

                System.IO.File.WriteAllText(System.IO.Path.Combine(ResourceManager.GetDeafultPath(PathType.ReadOnly), CheckResourceState.AssetPlatformVersionText), platformVersion);

                ATFileOp.ShowExplorerWindow(System.IO.Path.Combine(ResourceManager.GetDeafultPath(PathType.ReadOnly), CheckResourceState.AssetPlatformVersionText));
            }
Exemple #3
0
        //http文本读取成功
        private void OnHttpReadTextSuccess(object sender, IEventArgs e)
        {
            HttpReadTextSuccessEventArgs ne = (HttpReadTextSuccessEventArgs)e;

            if (ne != null)
            {
                if (ne.Url == Path.Combine(GameMode.Resource.ResUpdatePath, _assetPlatformVersionText))
                {
                    AssetPlatformVersionInfo assetPlatform = JsonUtility.FromJson <AssetPlatformVersionInfo>(ne.Content);
                    string platformName = GetPlatformName();
                    if (assetPlatform.Platforms.Contains(platformName))
                    {
                        //更新远程资源的路径
                        GameMode.Resource.ResUpdatePath =
                            Path.Combine(GameMode.Resource.ResUpdatePath, platformName);
                        //读取远程的文本
                        string remotePath = Path.Combine(GameMode.Resource.ResUpdatePath, _assetVersionTxt);
                        GameMode.WebRequest.ReadHttpText(remotePath);
                    }
                }
                else
                {
                    _remoteVersion = JsonUtility.FromJson <AssetBundleVersionInfo>(ne.Content);
                    if (_remoteVersion == null)
                    {
                        Debug.LogError("Remote Version is null");
                        return;
                    }

                    //如果资源版本不一样 则更新资源
                    if (!CompareVersion())
                    {
                        //更新资源
                        UpdateResource();
                        //下载资源
                        DownloadResource();
                    }

                    //资源更新完成
                    _resourceUpdateDone = true;
                }
            }
        }
Exemple #4
0
        public static void BuildAssetBundles()
        {
            string buildPath = EditorConfigInfo.BuildPath;

            if (!Directory.Exists(buildPath))
            {
                Debug.LogError("Please set build path!");
                return;
            }

            //平台资源的信息
            string platformVersionPath = Path.Combine(buildPath, "AssetPlatformVersion.txt");
            AssetPlatformVersionInfo assetPlatformVersionInfo = new AssetPlatformVersionInfo();

            assetPlatformVersionInfo.Platforms = new List <string>();
            //资源加密
            EnciphererKey keyAsset = null;

            if ((EncryptMode)EditorConfigInfo.EncryptMode == EncryptMode.AES)
            {
                string keyPath = Application.dataPath + "/Resources";
                if (!Directory.Exists(keyPath))
                {
                    Directory.CreateDirectory(keyPath);
                }

                if (!File.Exists(keyPath + "/Key.asset"))
                {
                    EnciphererKey ek = ScriptableObject.CreateInstance <EnciphererKey>();
                    ek.GeneraterKey();
                    AssetDatabase.CreateAsset(ek, "Assets/Resources/Key.asset");
                    AssetDatabase.Refresh();
                }

                keyAsset = Resources.Load("Key") as EnciphererKey;
            }

            //根据各个平台打包
            foreach (var item in EditorConfigInfo.BuildTargets)
            {
                //打包
                BuildTarget target     = (BuildTarget)item;
                string      targetName = target.ToString().ToLower();
                //添加平台的信息
                assetPlatformVersionInfo.Platforms.Add(targetName);
                string targetBuildPath = Path.Combine(buildPath, targetName);
                if (!Directory.Exists(targetBuildPath))
                {
                    Directory.CreateDirectory(targetBuildPath);
                }

                Debug.Log("开始打包--" + targetName + System.DateTime.Now.ToString("  HH:mm:ss:fff"));
                BuildAssetBundleOptions option = (BuildAssetBundleOptions)EditorConfigInfo.ZipMode;
                BuildPipeline.BuildAssetBundles(targetBuildPath, option, target);
                Debug.Log("打包完成--" + targetName + System.DateTime.Now.ToString("  HH:mm:ss:fff"));

                //写入版本号信息
                string assetVersionPath        = targetBuildPath + "/AssetVersion.txt";
                AssetBundleVersionInfo version = new AssetBundleVersionInfo();
                version.ManifestAssetBundle = targetName;
                version.Version             = EditorConfigInfo.AssetVersion;
                version.IsEncrypt           = (EncryptMode)EditorConfigInfo.EncryptMode == EncryptMode.AES;
                version.Resources           = new List <ResourcesInfo>();

                List <FileInfo> allFiles = GetAllFiles(targetBuildPath);
                for (int i = 0; i < allFiles.Count; i++)
                {
                    FileInfo fileInfo = allFiles[i];
                    if (fileInfo.Extension == ".manifest")
                    {
                        File.Delete(fileInfo.FullName);
                    }
                    else if (fileInfo.Name == "AssetVersion.txt")
                    {
                        continue;
                    }
                    //加密
                    else
                    {
                        byte[] bs = File.ReadAllBytes(fileInfo.FullName);
                        if (keyAsset != null)
                        {
                            byte[] cipbs = Encipherer.AESEncrypt(bs, keyAsset);
                            File.WriteAllBytes(fileInfo.FullName, cipbs);
                            //加密后md5的值应该刷新
                            bs = cipbs;
                        }
                        ResourcesInfo resourcesInfo = new ResourcesInfo();
                        string        fullPath      = Path.GetFullPath(targetBuildPath);
                        resourcesInfo.Name = fileInfo.FullName.Replace(fullPath + "\\", "");
                        System.Security.Cryptography.MD5 md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
                        //计算字节数组的哈希值
                        byte[] toData  = md5.ComputeHash(bs);
                        string fileMD5 = "";
                        for (int j = 0; j < toData.Length; j++)
                        {
                            fileMD5 += toData[j].ToString("x2");
                        }
                        resourcesInfo.MD5 = fileMD5;
                        version.Resources.Add(resourcesInfo);
                    }
                }

                //保存AssetVersion文件
                string content = JsonUtility.ToJson(version);
                File.WriteAllText(assetVersionPath, content);
            }

            //保存平台信息文件
            string platformContent = JsonUtility.ToJson(assetPlatformVersionInfo);

            File.WriteAllText(platformVersionPath, platformContent);

            //版本号迭代
            EditorConfigInfo.AssetVersion += 1;
            SaveEditorConfigInfo();

            AssetDatabase.Refresh();

            //打开打包文件夹
            EditorUtility.OpenWithDefaultApp(buildPath);
        }