Beispiel #1
0
        public static void Build()
        {
            Clear();
            var Mods   = ModsEditor.GetMods();
            int length = Mods.Length;

            for (int i = 0; i < length; i++)
            {
                var ModInfo         = ModsEditor.GetModInfo(Mods[i]);
                var ModOutPutFolder = OutPutFolder + "/" + ModInfo.PackageName;
                Directory.CreateDirectory(ModOutPutFolder);

                //生成ModInfo文件
                using (StreamWriter sw = File.CreateText(ModOutPutFolder + "/" + ModInfo.PackageName + ".json"))
                {
                    sw.Write(JsonConvert.SerializeObject(ModInfo));
                }

                //Windows64版本构建
                //构建参数
                var param = new BundleBuildParameters(BuildTarget.StandaloneWindows64, BuildTargetGroup.Standalone, ModOutPutFolder);
                param.BundleCompression = BuildCompression.LZ4;
                //填入资源
                var content = new BundleBuildContent(new AssetBundleBuild[] { GetAllAssets(ModInfo, "winmod") });
                IBundleBuildResults results;
                //构建包
                ReturnCode code = ContentPipeline.BuildAssetBundles(param, content, out results);
                if (code != ReturnCode.Success)
                {
                    if (code == ReturnCode.Canceled)
                    {
                        return;//如果取消,直接返回
                    }
                    Debug.LogError("构建失败!错误原因:" + code.ToString());
                }
            }
        }
Beispiel #2
0
        public static void BuildAll()
        {
            Clear();
            var Mods   = ModsEditor.GetMods();
            int length = Mods.Length;

            for (int i = 0; i < length; i++)
            {
                var ModInfo         = ModsEditor.GetModInfo(Mods[i]);
                var ModOutPutFolder = OutPutFolder + "/" + ModInfo.PackageName;
                //Windows64版本构建
                //构建参数
                var param = new BundleBuildParameters(BuildTarget.StandaloneWindows64, BuildTargetGroup.Standalone, ModOutPutFolder);
                param.BundleCompression = BuildCompression.LZ4;
                //填入资源
                var content = new BundleBuildContent(new AssetBundleBuild[] { GetAllAssets(ModInfo, "winmod") });
                IBundleBuildResults results;
                //构建包
                ReturnCode code = ContentPipeline.BuildAssetBundles(param, content, out results);
                if (code != ReturnCode.Success)
                {
                    if (code == ReturnCode.Canceled)
                    {
                        return;//如果取消,直接返回
                    }
                    Debug.LogError("构建失败!错误原因:" + code.ToString());
                }

                //OSX版本构建
                //构建参数
                param.Target = BuildTarget.StandaloneOSX;
                //填入资源
                content = new BundleBuildContent(new AssetBundleBuild[] { GetAllAssets(ModInfo, "osxmod") });
                results = null;
                //构建包
                code = ContentPipeline.BuildAssetBundles(param, content, out results);
                if (code != ReturnCode.Success)
                {
                    if (code == ReturnCode.Canceled)
                    {
                        return;//如果取消,直接返回
                    }
                    Debug.LogError("构建失败!错误原因:" + code.ToString());
                }

                //Linux版本构建
                //构建参数
                param.Target = BuildTarget.StandaloneLinux64;
                //填入资源
                content = new BundleBuildContent(new AssetBundleBuild[] { GetAllAssets(ModInfo, "linuxmod") });
                results = null;
                //构建包
                code = ContentPipeline.BuildAssetBundles(param, content, out results);
                if (code != ReturnCode.Success)
                {
                    if (code == ReturnCode.Canceled)
                    {
                        return;//如果取消,直接返回
                    }
                    Debug.LogError("构建失败!错误原因:" + code.ToString());
                }

                //Android版本构建
                //构建参数
                param.Target = BuildTarget.Android;
                param.Group  = BuildTargetGroup.Android;
                //填入资源
                content = new BundleBuildContent(new AssetBundleBuild[] { GetAllAssets(ModInfo, "androidmod") });
                results = null;
                //构建包
                code = ContentPipeline.BuildAssetBundles(param, content, out results);
                if (code != ReturnCode.Success)
                {
                    if (code == ReturnCode.Canceled)
                    {
                        return;//如果取消,直接返回
                    }
                    Debug.LogError("构建失败!错误原因:" + code.ToString());
                }

                //ios版本构建
                //构建参数
                param.Target = BuildTarget.iOS;
                param.Group  = BuildTargetGroup.iOS;
                //填入资源
                content = new BundleBuildContent(new AssetBundleBuild[] { GetAllAssets(ModInfo, "iosmod") });
                results = null;
                //构建包
                code = ContentPipeline.BuildAssetBundles(param, content, out results);
                if (code != ReturnCode.Success)
                {
                    if (code == ReturnCode.Canceled)
                    {
                        return;//如果取消,直接返回
                    }
                    Debug.LogError("构建失败!错误原因:" + code.ToString());
                }

                //生成ModInfo文件
                ModInfo = ModsEditor.GetModInfo(Mods[i]);//由于构建后资源会被释放,这里需要重载
                using (FileStream fs = File.Create(ModOutPutFolder + "/" + ModInfo.PackageName + ".json"))
                {
                    StreamWriter sw = new StreamWriter(fs);
                    sw.Write(JsonConvert.SerializeObject(ModInfo));
                    sw.Dispose();
                }
            }
        }