如果你的游戏项目只有一个版本或渠道维护,那可能对一键发包的需要不是很大,但是如果需要从一个项目工程发布不同渠道版本包时,最好是搞个一键发包工具,全自动化,只需在发包窗口做一些必要设置如版本号,目标平台等信息,点击发布即可。也避免了需要打开多个面板去设置麻烦,如PlayerSetting面板、EditorBuildSetting、UserBuildSettings,甚至场景里的游戏对象预设等。把它们都集成到同一个发布工具窗口显示修改,防止东漏西漏的可能。
这里主要介绍关键常用设置的API。
1.Version与VersionCode
//版本号
PlayerSettings.bundleVersion = EditorGUILayout.TextField("Version-[可编辑]", PlayerSettings.bundleVersion);
//根据当前的游戏版本计算当前的bundle version code
PlayerSettings.Android.bundleVersionCode = GetBundleVersionCode(config.device_model);
EditorGUILayout.LabelField("Bundle Version Code", PlayerSettings.Android.bundleVersionCode.ToString());
2.签名文件:keyStoreName与keyAlisName
//选择现有签名文件
PlayerSettings.Android.keystoreName = GetKeystoreName(config.device_model);
EditorGUILayout.LabelField("KeystoreName", PlayerSettings.Android.keystoreName);
PlayerSettings.keystorePass = "123456";
//使用签名文件
PlayerSettings.Android.keyaliasName = GetKeyaliasName(config.device_model);
EditorGUILayout.LabelField("KeyaliasName", PlayerSettings.Android.keyaliasName);
PlayerSettings.keyaliasPass = "123456";
3.启动动画:SplashScreenImage
PlayerSettings.showUnitySplashScreen = false;
4.是否导出Android工程
EditorUserBuildSettings.exportAsGoogleAndroidProject = false;
5.应用名称:ProductName
PlayerSettings.productName = "爱看VR-Pico";
6.横竖屏:
PlayerSettings.defaultInterfaceOrientation = UIOrientation.LandscapeLeft;
7.包名
PlayerSettings.SetApplicationIdentifier(BuildTargetGroup.Android, "com.cmcc.iWatchVRSkyworth");
8.最低API设置
PlayerSettings.Android.minSdkVersion = AndroidSdkVersions.AndroidApiLevel25;
9.构建打包
BuildReport result = BuildPipeline.BuildPlayer(scenes, selectPath, target, BuildOptions.None);
下面粘贴项目中打包工具代码共参考
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using Newtonsoft.Json;
using System;
using UnityEditor.SceneManagement;
using System.IO;
using UnityEditor.Build.Reporting;
using UnityEngine.SceneManagement;
public class LetinDevTools2 : EditorWindow
{
public static LetinDevTools2 myWin;
public string configAssetPath;
public LetinBuildConfig config;
public static EquipmentModel deviceModel;
public string manifestPath;
public string tmpFile = "";
public string appType = "";
private static DateTime lastSaveTimeScene = DateTime.Now;
private static bool isDebugOpen = false;
//场景跳转
[MenuItem("LetinDevTool/跳转到==>InitScene")]
public static void Switch2InitScene()
{
if (EditorUtility.DisplayDialog("提示", "是否保存当前场景修改", "保存", "不保存"))
{
EditorSceneManager.SaveOpenScenes();
}
EditorSceneManager.OpenScene(Application.dataPath + "/scenes/MainScene/InitScene.unity");
lastSaveTimeScene = DateTime.Now;
}
//场景跳转
[MenuItem("LetinDevTool/跳转到==>UpdateScene")]
public static void Switch2UpdateScene()
{
if (EditorUtility.DisplayDialog("提示", "是否保存当前场景修改", "保存", "不保存"))
{
EditorSceneManager.SaveOpenScenes();
}
EditorSceneManager.OpenScene(Application.dataPath + "/scenes/MainScene/UpdateScene.unity");
}
//场景跳转
[MenuItem("LetinDevTool/跳转到==>MainScene")]
public static void Switch2MainScene()
{
if (EditorUtility.DisplayDialog("提示", "是否保存当前场景修改", "保存", "不保存"))
{
EditorSceneManager.SaveOpenScenes();
}
EditorSceneManager.OpenScene(Application.dataPath + "/scenes/MainScene/MainScene.unity");
}
[MenuItem("LetinDevTool/将MainScene和Imax场景打包成AssetBundle")]
public static void BuildScenes2AssetBundle()
{
string[] path = new string[] { "Assets/Scenes/MainScene/MainScene.unity", "Assets/Scenes/MainScene/PlayScene/PlaySceneIMAX.unity" };
BuildPipeline.BuildPlayer(path, Application.dataPath + "/streamscene.ab", BuildTarget.Android, BuildOptions.BuildAdditionalStreamedScenes);
}
[MenuItem("LetinDevTool/打包设置")]
public static void OpenLetinConfigWindow()
{
myWin = (LetinDevTools2)EditorWindow.GetWindow<LetinDevTools2>();
myWin.minSize = new Vector2(600, 400);
myWin.LoadConfig();
myWin.title = "发布设置";
myWin.Show();
}
[MenuItem("LetinDevTool/一键发布: Pico版本apk")]
public static void ExportPicoApk()
{
CheckBeforeExport(EquipmentModel.Pico);
}
[MenuItem("LetinDevTool/一键发布: PicoLauncher版本apk")]
public static void ExportPicoLauncher()
{
CheckBeforeExport(EquipmentModel.PicoLauncher);
}
[MenuItem("LetinDevTool/一键发布: GVR版本apk")]
public static void ExportGVRApk()
{
CheckBeforeExport(EquipmentModel.GVR);
}
[MenuItem("LetinDevTool/一键发布: HVR版本apk")]
public static void ExportHVRApk()
{
CheckBeforeExport(EquipmentModel.HVR);
}
[MenuItem("LetinDevTool/一键导出: GVRSDK版本的AS工程")]
public static void ExportGVRSDK()
{
CheckBeforeExport(EquipmentModel.GVRSDK);
}
/// <summary>
/// 一键导出GVRSDK的AS工程
/// </summary>
/// <param name="equipmentModel"></param>
public static void Export2ASProj(EquipmentModel equipmentModel)
{
//对当前平台做检查,如果当前平台与一键打包的平台不一样,则弹出提示框,让开发者前去“打包设置”
if (deviceModel != equipmentModel)
{
EditorUtility.DisplayDialog("提示", "当前平台[" + deviceModel.ToString() + "]与一键导出的SDK[" + equipmentModel.ToString() + "]的平台不同,请前往打包设置", "OK");
return;
}
//确定发布平台
BuildTarget target = BuildTarget.Android;
//创建默认保存路径为当前工程要目录下,GVRSDK_ASProjects文件夹中,如果没有则自动创建目录
string exportFolder = Path.GetFullPath(".") + "\\GVRSDK_ASProjects";
if (!Directory.Exists(exportFolder))
{
Directory.CreateDirectory(exportFolder);
}
string fileName = "";
//提供用户选择路径
string selectPath = EditorUtility.SaveFolderPanel("请选择保存路径", exportFolder,"");
//用户点击取消处理
if (string.IsNullOrEmpty(selectPath))
{
Debug.Log("UPublish:用户取消导出GVRSDK AS项目工程");
return;
}
//获取场景编译场景列表
var scenes = EditorBuildSettings.scenes;
Debug.Log("UPublish:开始发布导出GVRSDK AS项目工程");
BuildReport result = BuildPipeline.BuildPlayer(scenes, selectPath, target, BuildOptions.None);
}
/// <summary>
/// Build前,进行场景检查
/// </summary>
/// <param name="equipmentModel"></param>
public static void CheckBeforeExport(EquipmentModel equipmentModel)
{
//如果当前打开的就是InitScene场景,则
if (EditorSceneManager.GetActiveScene().name.Equals("InitScene"))
{
GameObject[] objects = EditorSceneManager.GetActiveScene().GetRootGameObjects();
for (int i = 0; i < objects.Length; i++)
{
if (objects[i].name.Equals("Global"))
{
EPGLoginManager ePGLoginDataManager = objects[i].GetComponent<EPGLoginManager>();
if (ePGLoginDataManager != null)
ePGLoginDataManager.UserSpectialInfoLogin = false;
UnityEngine.Object newsPref = PrefabUtility.GetPrefabObject(objects[i]);
if (PrefabUtility.GetPrefabType(objects[i]) == PrefabType.PrefabInstance)
{
UnityEngine.Object parentObject = PrefabUtility.GetPrefabParent(objects[i]);
//替换预设
PrefabUtility.ReplacePrefab(objects[i], parentObject, ReplacePrefabOptions.ConnectToPrefab);
//刷新
AssetDatabase.Refresh();
}
break;
}
}
if (equipmentModel == EquipmentModel.GVRSDK)
{
Export2ASProj(equipmentModel);
}
else
{
Export2Android(equipmentModel);
}
}
else
{
if (EditorUtility.DisplayDialog("提示", "当前场景不是InitScene,打包前需要切换到InitScene,再一键打包导出", "切换"))
{
EditorSceneManager.SaveOpenScenes();
//EditorSceneManager.sceneOpened += OnSceneOpenedCallBack;
EditorSceneManager.OpenScene(Application.dataPath + "/scenes/MainScene/InitScene.unity");
}
}
}
/// <summary>
/// 场景切换成InitScene场景成功回调
/// </summary>
/// <param name="scene"></param>
/// <param name="mode"></param>
private static void OnSceneOpenedCallBack(Scene scene, OpenSceneMode mode)
{
Debug.LogError("OnSceneOpenedCallBack========>scene.name"+scene.name);
if (EditorSceneManager.GetActiveScene().name.Equals("InitScene"))
{
GameObject[] objects = EditorSceneManager.GetActiveScene().GetRootGameObjects();
for (int i = 0; i < objects.Length; i++)
{
if (objects[i].name.Equals("Global"))
{
EPGLoginManager ePGLoginDataManager = objects[i].GetComponent<EPGLoginManager>();
if (ePGLoginDataManager != null)
ePGLoginDataManager.UserSpectialInfoLogin = false;
UnityEngine.Object newsPref = PrefabUtility.GetPrefabObject(objects[i]);
if (PrefabUtility.GetPrefabType(objects[i]) == PrefabType.PrefabInstance)
{
UnityEngine.Object parentObject = PrefabUtility.GetPrefabParent(objects[i]);
//替换预设
PrefabUtility.ReplacePrefab(objects[i], parentObject, ReplacePrefabOptions.ConnectToPrefab);
//刷新
AssetDatabase.Refresh();
}
break;
}
}
}
}
/// <summary>
/// 打包文件命名规则:
/// GVR【平台】_ZJCMMC【运营商】_v1.3.0【版本号】_202012311540【打包日期】_Debug/Release【根据Debug开关】.apk
/// </summary>
/// <param name="plantform"></param>
public static void Export2Android(EquipmentModel equipmentModel)
{
//对当前平台做检查,如果当前平台与一键打包的平台不一样,则弹出提示框,让开发者前去“打包设置”
if (deviceModel != equipmentModel)
{
EditorUtility.DisplayDialog("提示", "当前平台["+deviceModel.ToString()+"]与一键打包["+equipmentModel.ToString()+"]的平台不同,请前往打包设置","OK");
return;
}
//文件扩展名
string fileExt = "apk";
//确定发布平台
BuildTarget target = BuildTarget.Android;
//发布是测试版还是发布版本
string releaseStr = isDebugOpen ? "Debug": "Release";
//组装发布文件名
string fileName = equipmentModel.ToString() + "_ZJCMMC_v" + Application.version + "_" + DateTime.Now.ToString("yyyyMMddHHmm") +"_"+releaseStr+ "." + fileExt;
//进行包名检测提示
if (PlayerSettings.applicationIdentifier == "com.Company.ProductName")
{
EditorUtility.DisplayDialog("警告", "请检查设置\t\rPlayerSettings->Identifier->PackageName!", "确定");
Debug.Log("UPublish: 请检查设置PlayerSettings->Identifier->PackageName!");
return;
}
//创建默认保存路径为当前工程要目录下,Release文件夹中,如果没有则自动创建目录
string exportFolder = Path.GetFullPath(".") + "\\Release"+"\\"+ equipmentModel.ToString();
if (!Directory.Exists(exportFolder))
{
Directory.CreateDirectory(exportFolder);
}
//提供用户选择路径
string selectPath = EditorUtility.SaveFilePanel("请选择保存路径", exportFolder, fileName, fileExt);
//用户点击取消处理
if (string.IsNullOrEmpty(selectPath))
{
Debug.Log("UPublish:用户取消发布APK");
return;
}
//获取场景编译场景列表
var scenes = EditorBuildSettings.scenes;
Debug.Log("UPublish:开始发布Android平台");
BuildReport result = BuildPipeline.BuildPlayer(scenes, selectPath, target, BuildOptions.None);
//string result = BuildPipeline.BuildPlayer(scenes, selectPath, target, BuildOptions.None);
//switch (result)
//{
// case "Building to the Assets folder is not allowed.":
// EditorUtility.DisplayDialog("警告", "不允许保存在工程Assets目录内", "确定");
// break;
// case "Building Player was cancelled":
// EditorUtility.DisplayDialog("提示", "用户中途取消发布", "确定");
// Debug.Log("UPuglish: 用户中途取消发布");
// break;
//}
//if (string.IsNullOrEmpty(result))
//{
// //根据用户选择重新定位保存目录
// exportFolder = @"" + Path.GetDirectoryName(selectPath);
// while (exportFolder.Contains("/"))
// {
// exportFolder = exportFolder.Replace("/", "\\");
// }
// System.Diagnostics.Process.Start("explorer.exe", exportFolder);
// Debug.Log("UPublish: APK发布成功 (" + selectPath + ")");
//}
}
public void LoadConfig()
{
string json = File.ReadAllText(Application.dataPath + "/Resources/BuildConfig.json");
config = JsonConvert.DeserializeObject<LetinBuildConfig>(json);
isDebugOpen = config.DebugOpen;
deviceModel = config.device_model;
}
/// <summary>
/// 计算bundle version code
/// </summary>
/// <param name="equipmentModel"></param>
/// <returns></returns>
private int GetBundleVersionCode(EquipmentModel equipmentModel)
{
int baseVC = 1600;
string[] vCArr = PlayerSettings.bundleVersion.Split('.');
float vc = 0;
for (int i = 0; i < vCArr.Length; i++)
{
if (string.IsNullOrEmpty(vCArr[i]))
break;
vc += Convert.ToInt32(vCArr[i]) * Mathf.Pow(10,(vCArr.Length-i-1));
}
return baseVC + (int)vc;
}
/// <summary>
/// 获取keystore文件路径
/// </summary>
/// <param name="equipmentModel"></param>
/// <returns></returns>
private string GetKeystoreName(EquipmentModel equipmentModel)
{
string path = Application.dataPath.Replace("/Assets", "/keystore");
switch (equipmentModel)
{
case EquipmentModel.GVR:
case EquipmentModel.GVRSDK:
path += "/CB/user.keystore";
break;
case EquipmentModel.HVR:
path += "/VRGlass/IWatchVR.keystore";
break;
case EquipmentModel.Pico:
case EquipmentModel.PicoLauncher:
path += "/Pico/zjyd.keystore";
break;
case EquipmentModel.Skyworth:
break;
}
return path;
}
private string GetKeyaliasName(EquipmentModel equipmentModel)
{
string path = "";
switch (equipmentModel)
{
case EquipmentModel.GVR:
case EquipmentModel.GVRSDK:
path = "iwatchvrcardboard";
break;
case EquipmentModel.HVR:
path = "iwatchvr";
break;
case EquipmentModel.Pico:
case EquipmentModel.PicoLauncher:
path = "vrepg";
break;
case EquipmentModel.Skyworth:
break;
}
return path;
}
private void OnGUI()
{
GUILayout.Label("");
GUIStyle title = new GUIStyle();
title.fontSize = 20;
title.alignment = TextAnchor.MiddleCenter;
GUILayout.Label("项目发布设置", title);
GUILayout.Label("");
config.device_model = (EquipmentModel)EditorGUILayout.EnumPopup("目标平台-[可编辑]", config.device_model);
deviceModel = config.device_model;
PlayerSettings.showUnitySplashScreen = false;
EditorUserBuildSettings.exportAsGoogleAndroidProject = false;
string targetFile = Application.dataPath + "/Plugins/Android/AndroidManifest.xml";
switch (config.device_model)
{
case EquipmentModel.Pico:
tmpFile = "/Plugins/Android/AndroidManifest_Pico.xml";
PlayerSettings.defaultInterfaceOrientation = UIOrientation.LandscapeLeft;
appType = "2";
PlayerSettings.productName = "爱看VR-Pico";
//PlayerSettings.applicationIdentifier = "com.cmcc.iWatchVRPico";
//PlayerSettings.SetApplicationIdentifier(BuildTargetGroup.Android, "com.cmcc.iWatchVRPico");
PlayerSettings.SetApplicationIdentifier(BuildTargetGroup.Android, "com.zjcmcc.aikanvr");
PlayerSettings.Android.minSdkVersion = AndroidSdkVersions.AndroidApiLevel25;
break;
case EquipmentModel.PicoLauncher:
tmpFile = "/Plugins/Android/AndroidManifest_PicoLauncher.xml";
PlayerSettings.defaultInterfaceOrientation = UIOrientation.LandscapeLeft;
appType = "2";
PlayerSettings.productName = "爱看VR-PicoLauncher";
//PlayerSettings.applicationIdentifier = "com.picovrtob.vrlauncher";
PlayerSettings.SetApplicationIdentifier(BuildTargetGroup.Android, "com.picovrtob.vrlauncher");
PlayerSettings.Android.minSdkVersion = AndroidSdkVersions.AndroidApiLevel25;
break;
case EquipmentModel.Skyworth:
tmpFile = "/Plugins/Android/AndroidManifest_Skyworth.xml";
//appType = "2";//正式使用2
appType = "1";//测试使用1,防止华为注意到
PlayerSettings.productName = "爱看VR-Skyworth";
//PlayerSettings.applicationIdentifier = "com.cmcc.iWatchVRSkyworth";
PlayerSettings.SetApplicationIdentifier(BuildTargetGroup.Android, "com.cmcc.iWatchVRSkyworth");
break;
case EquipmentModel.HVR:
tmpFile = "/Plugins/Android/AndroidManifest_HVR.xml";
appType = "1";
PlayerSettings.productName = "爱看VR-Glass";
//PlayerSettings.applicationIdentifier = "com.cmcc.iWatchVR";
PlayerSettings.SetApplicationIdentifier(BuildTargetGroup.Android, "com.cmcc.iWatchVR");
break;
case EquipmentModel.GVR:
//签名密码
PlayerSettings.keystorePass = "123456";
tmpFile = "/Plugins/Android/AndroidManifest_Cardboard.xml";
PlayerSettings.companyName = "cmcc";
PlayerSettings.productName = "爱看VR";
//PlayerSettings.applicationIdentifier = "com.cmcc.iWatchVRCardboard";
PlayerSettings.SetApplicationIdentifier(BuildTargetGroup.Android, "com.cmcc.iWatchVRCardboard");
PlayerSettings.Android.minSdkVersion = AndroidSdkVersions.AndroidApiLevel25;
PlayerSettings.defaultInterfaceOrientation = UIOrientation.Portrait;
appType = "0";
break;
case EquipmentModel.GVRSDK:
tmpFile = "/Plugins/Android/AndroidManifest_Cardboard_sdk.xml";
PlayerSettings.companyName = "zjcmcc";
PlayerSettings.productName = "IWatchVR-Unity-SDK";
//PlayerSettings.applicationIdentifier = "com.iwatchvr.sdk";
PlayerSettings.SetApplicationIdentifier(BuildTargetGroup.Android, "com.iwatchvr.sdk");
PlayerSettings.Android.minSdkVersion = AndroidSdkVersions.AndroidApiLevel19;
PlayerSettings.defaultInterfaceOrientation = UIOrientation.LandscapeLeft;
appType = "3";
PlayerSettings.showUnitySplashScreen = true;
EditorUserBuildSettings.exportAsGoogleAndroidProject = true;
break;
}
config.AndroidManifest = tmpFile;
config.AppType = appType;
EditorGUILayout.LabelField("AndroidManifest", config.AndroidManifest);
EditorGUILayout.LabelField("AppType", config.AppType);
//版本号
PlayerSettings.bundleVersion = EditorGUILayout.TextField("Version-[可编辑]", PlayerSettings.bundleVersion);
//根据当前的游戏版本计算当前的bundle version code
PlayerSettings.Android.bundleVersionCode = GetBundleVersionCode(config.device_model);
EditorGUILayout.LabelField("Bundle Version Code", PlayerSettings.Android.bundleVersionCode.ToString());
//选择现有签名文件
PlayerSettings.Android.keystoreName = GetKeystoreName(config.device_model);
EditorGUILayout.LabelField("KeystoreName", PlayerSettings.Android.keystoreName);
PlayerSettings.keystorePass = "123456";
//使用签名文件
PlayerSettings.Android.keyaliasName = GetKeyaliasName(config.device_model);
EditorGUILayout.LabelField("KeyaliasName", PlayerSettings.Android.keyaliasName);
PlayerSettings.keyaliasPass = "123456";
//Log 开关选框
config.DebugOpen = EditorGUILayout.BeginToggleGroup("Log 开关-[可编辑]", config.DebugOpen);
isDebugOpen = config.DebugOpen;
EditorGUILayout.EndToggleGroup();
tmpFile = Application.dataPath + tmpFile;
if (GUILayout.Button("保存"))
{
try
{
//目标视频文件拷贝
CopyTargetVideoFileToStreamingAssetDir(config.device_model);
//目标背景图文件拷贝
CopyTargetSceneBGPrefabToResourceFile(config.device_model);
//Pico_MainScene场景的显示隐藏检查处理
if (config.device_model == EquipmentModel.Pico ||
config.device_model == EquipmentModel.PicoLauncher)
{
EnablePicoSpeicalScene(true);
}
else
{
EnablePicoSpeicalScene(false);
}
switch (config.device_model)
{
case EquipmentModel.GVR:
case EquipmentModel.GVRSDK:
PlayerSettings.virtualRealitySupported = true;
string[] gvr = new string[] { "None", "cardboard" };
PlayerSettings.SetVirtualRealitySDKs(BuildTargetGroup.Android, gvr);
break;
//PlayerSettings.virtualRealitySupported = true;
//string[] gvrSdk = new string[] { "cardboard", "None" };
//PlayerSettings.SetVirtualRealitySDKs(BuildTargetGroup.Android, gvrSdk);
//break;
default:
PlayerSettings.virtualRealitySupported = false;
break;
}
string path = Application.dataPath + "/Resources/BuildConfig.json";
string json = JsonConvert.SerializeObject(config);
File.WriteAllText(path, json);
Debug.Log("tmpfile = " + tmpFile + " targetFile = " + targetFile);
File.Copy(tmpFile, targetFile, true);
AssetDatabase.Refresh();
Debug.Log("目标设备切换: " + config.device_model);
Debug.Log("当前APP类型:" + config.AppType);
EditorUtility.DisplayDialog("提示", "发布配置更新完成", "确定");
PlayerPrefs.DeleteAll();//发布清除缓存
}
catch
{
EditorUtility.DisplayDialog("提示", "配置修改失败!", "确定");
}
}
}
/// <summary>
/// 切换到Pico一体机时,激活Pico_MainScene场景
/// </summary>
private void EnablePicoSpeicalScene(bool isEnable)
{
EditorBuildSettingsScene[] scenes = EditorBuildSettings.scenes;
foreach (EditorBuildSettingsScene S in scenes)
{
//Debug.LogError("S ===SceneName:"+S.path);
if (S.path.Contains("Pico_MainScene"))
{
S.enabled = isEnable;
}
else
{
S.enabled = true;
}
}
EditorBuildSettings.scenes = scenes;
}
public void SaveCoinfigAsset()
{
Debug.Log(config.device_model);
}
/// <summary>
/// 游戏项目中所有视频文件的根目录
/// </summary>
private string Videos_ROOT_PATH;
/// <summary>
/// 游戏项目中当前平台需要的视频的存放目录
/// </summary>
private string Video_TARGET_PATH;
/// <summary>
/// 切换平台时,将对应平台需要的加载视频动画复制到StreamingAsset文件夹下
/// </summary>
private void CopyTargetVideoFileToStreamingAssetDir(EquipmentModel equipmentModel)
{
Videos_ROOT_PATH = @"" + Application.dataPath + "/VideoFiles/";
Video_TARGET_PATH = @"" + Application.streamingAssetsPath + "/";
string videoName = "";
switch (equipmentModel)
{
case EquipmentModel.GVR:
videoName = GameConst.GVR_VIDEO_NAME;
break;
case EquipmentModel.GVRSDK:
videoName = GameConst.GVRSDK_VIDEO_NAME;
break;
case EquipmentModel.HVR:
videoName = GameConst.HVR_VIDEO_NAME;
break;
case EquipmentModel.Pico:
case EquipmentModel.PicoLauncher:
videoName = GameConst.PICO_VIDEO_NAME;
break;
case EquipmentModel.Skyworth:
videoName = GameConst.Skyworth_VIDEO_NAME;
break;
}
//检查删除StreamingAsset目录下所有文件
DelectDir(Video_TARGET_PATH);
//将目标视频复制到目标文件夹StreamingAsset下
if (string.IsNullOrEmpty(videoName))
{
Debug.LogError("当前平台:" + equipmentModel.ToString() + "没有视频文件需要打进StreamingAsset文件夹中");
}
else
{
string originFilePath = Videos_ROOT_PATH + videoName + ".mp4";
string targetFilePath = Video_TARGET_PATH + videoName + ".mp4";
Debug.Log("把当前平台:" + equipmentModel.ToString() + "需要的视频文件:" + videoName + ".mp4 " + "从文件夹=" + originFilePath + " 拷贝到文件夹=" + targetFilePath);
File.Copy(originFilePath, targetFilePath);
}
}
/// <summary>
/// 删除目标文件目录下的所有文件包括子目录
/// </summary>
/// <param name="srcPath"></param>
public static void DelectDir(string srcPath)
{
try
{
DirectoryInfo dir = new DirectoryInfo(srcPath);
FileSystemInfo[] fileinfo = dir.GetFileSystemInfos(); //返回目录中所有文件和子目录
foreach (FileSystemInfo i in fileinfo)
{
if (i is DirectoryInfo) //判断是否文件夹
{
DirectoryInfo subdir = new DirectoryInfo(i.FullName);
subdir.Delete(true); //删除子目录和文件
}
else
{
//Debug.LogError("i.Name======"+i.Name);
if(!i.Name.Equals("vr_icon.png") && !i.Name.Equals("vr_icon.png.meta"))
File.Delete(i.FullName); //删除指定文件
}
}
}
catch (Exception e)
{
throw;
}
}
//所有平台的背景场景预设的根目录
private string SceneBG_RootPath;
//目标平台需要的背景图预设的存放路径
private string SceneBG_TargetPath;
private void CopyTargetSceneBGPrefabToResourceFile(EquipmentModel equipmentModel)
{
SceneBG_RootPath = @"" + Application.dataPath + "/Prefabs/BGs/";
SceneBG_TargetPath = @"" + Application.dataPath + "/Resources/Prefabs/BG/";
string bgName = "";
switch (equipmentModel)
{
case EquipmentModel.GVR:
bgName = GameConst.GVR_SceneBG_Name;
break;
case EquipmentModel.GVRSDK:
bgName = GameConst.GVRSDK_SceneBG_Name;
break;
case EquipmentModel.HVR:
bgName = GameConst.HVR_SceneBG_Name;
break;
case EquipmentModel.Pico:
case EquipmentModel.PicoLauncher:
bgName = GameConst.Pico_SceneBG_Name;
break;
case EquipmentModel.Skyworth:
bgName = GameConst.Skyworth_SceneBG_Name;
break;
}
//检查目标文件夹
DelectDir(SceneBG_TargetPath);
string originFilePath1 = SceneBG_RootPath + "Default" + ".prefab";
string targetFilePath1 = SceneBG_TargetPath + "Default" + ".prefab";
Debug.Log("把当前平台:" + equipmentModel.ToString() + "需要的背景文件:" + "Default.prefab " + "从文件夹=" + originFilePath1 + " 拷贝到文件夹=" + targetFilePath1);
File.Copy(originFilePath1, targetFilePath1);
//拷贝目标背景预设文件到Resources/Prefabs/BG/文件夹下
string originFilePath = SceneBG_RootPath + bgName + ".prefab";
string targetFilePath = SceneBG_TargetPath + bgName + ".prefab";
Debug.Log("把当前平台:" + equipmentModel.ToString() + "需要的背景文件:" + bgName + ".prefab " + "从文件夹=" + originFilePath + " 拷贝到文件夹=" + targetFilePath);
File.Copy(originFilePath, targetFilePath);
}
}