static bool BuildMachineAssets(PlatformType platformType) { bool result = false; BuildTarget target = BuildAssetBundleHelper.GetBuildTarget(platformType); if (target != BuildTarget.NoTarget) { //Note: Important fix. If don't switch platform, everytime before building AssetBundle, //it will take much time to switch to the particular platform. PerformBuild.SwitchBuildPlatform(target); string path = BuildAssetBundleHelper.GetAssetBundlePath(platformType); BuildAssetBundleHelper.DeleteAllFilesInDir(path); foreach (SingleMachineAssetConfig config in _machineConfig._machineConfigs) { if (config._selected) { string bundleName = config._name.ToLower(); string[] assetNames = AssetDatabase.GetAssetPathsFromAssetBundle(bundleName); bool buildResult = BuildAssetBundles.BuildBundlesFromMap(path, "", platformType, target, false, bundleName, assetNames); Debug.Log("Build MachineAsset result:" + buildResult.ToString()); Debug.Assert(buildResult); WriteMachineVersionToFile(path, bundleName, config._version); } } result = true; } return(result); }
static void BuildExcels(PlatformType platform, BuildTarget target) { //0 clean directory BuildAssetBundleHelper.DeleteAllFilesInDir(_buildOutputPath); //1 build foreach (string name in _allExcelFileNames) { for (int i = 0; i < (int)ExcelDirType.Count; i++) { ExcelDirType dirType = (ExcelDirType)i; BuildSingleExcel(platform, target, name, _buildOutputPath, dirType); } } //2 encrypt and copy foreach (string name in _allExcelFileNames) { for (int i = 0; i < (int)ExcelDirType.Count; i++) { ExcelDirType dirType = (ExcelDirType)i; EncryptAndCopyFile(name, dirType); } } }
static void CopyBetweenProjectAndAB(string versionName, ExcelDirType dirType, bool isABToProject) { string excelTopDir = ExcelConfig.GetTopDir(dirType); string abDir = GetCurrentVersionPath(versionName); if (!Directory.Exists(abDir)) { Debug.LogError("Error: directory doesn't exist:" + abDir); return; } List <FileInfo> abInfos = BuildAssetBundleHelper.GetUsefulFileInfosFromDir(abDir); string projectPath = Application.dataPath; List <FileInfo> allInfos = BuildAssetBundleHelper.GetUsefulFileInfosFromDir(projectPath); foreach (FileInfo abInfo in abInfos) { bool isExcel = abInfo.Name.EndsWith(".xls"); FileInfo projectInfo = ListUtility.FindFirstOrDefault(allInfos, (FileInfo i) => { //Debug.Log("name:" + i.Name); bool result = abInfo.Name == i.Name; if (result && isExcel) { result = IsContainDirectory(i.FullName, excelTopDir); } return(result); }); if (projectInfo == null) { string errStr = "Can't find corresponding project file:" + abInfo.Name; Debug.LogError(errStr); } else { if (isABToProject) { Debug.Log("copy from " + abInfo.FullName); Debug.Log("copy to " + projectInfo.FullName); File.Copy(abInfo.FullName, projectInfo.FullName, true); string relativePath = BuildAssetBundleHelper.TrimToRelativePath(projectInfo.FullName); AssetDatabase.ImportAsset(relativePath); } else { File.Copy(projectInfo.FullName, abInfo.FullName, true); } } } }
static bool BuildSingleExcel(PlatformType platform, BuildTarget target, string excelName, string outputPath, ExcelDirType dirType) { List <string> allResPaths = BuildAssetBundleHelper.GetSingleExcelResourcePaths(dirType, excelName); string bundleName = ExcelConfig.GetBundleName(dirType, excelName); bool result = BuildAssetBundles.BuildBundlesFromMap(outputPath, "", platform, target, false, bundleName, allResPaths); if (!result) { Debug.Log("Warn: Fail to build excel: " + excelName); } return(result); }
static bool BuildLiveUpdateAssets() { bool result = false; BuildTarget target = BuildAssetBundleHelper.GetBuildTarget(_liveUpdateConfig._platformType); if (target != BuildTarget.NoTarget) { //Note: Important fix. If don't switch platform, everytime before building AssetBundle, //it will take much time to switch to the particular platform. PerformBuild.SwitchBuildPlatform(target); string path = BuildAssetBundleHelper.GetAssetBundlePath(_liveUpdateConfig._platformType); BuildAssetBundleHelper.DeleteAllFilesInDir(path); ExcelDirType dirType = BuildAssetBundleHelper.GetExcelDirType(target); List <string> allResPaths = BuildAssetBundleHelper.GetAllExcelResourcePaths(dirType, _liveUpdateConfig._excelFileNames); allResPaths.AddRange(_liveUpdateConfig._resourcePaths); result = BuildAssetBundles.BuildBundlesFromMap(path, _liveUpdateConfig._version, _liveUpdateConfig._platformType, target, true, _liveUpdateConfig._bundleName, allResPaths); } return(result); }
static bool BuildABTestAssets() { bool result = false; BuildTarget target = BuildAssetBundleHelper.GetBuildTarget(_abTestConfig._platformType); if (target != BuildTarget.NoTarget) { //Note: Important fix. If don't switch platform, everytime before building AssetBundle, //it will take much time to switch to the particular platform. PerformBuild.SwitchBuildPlatform(target); ExcelDirType dirType = BuildAssetBundleHelper.GetExcelDirType(target); result = true; foreach (string abVersion in _abTestConfig._abVersions) { string path = BuildAssetBundleHelper.GetAssetBundlePath(_abTestConfig._platformType); BuildAssetBundleHelper.DeleteAllFilesInDir(path); BuildABTestHelper.CopyABToProject(abVersion, dirType); string version = _abTestConfig._version + "." + abVersion; List <string> allResPaths = BuildAssetBundleHelper.GetAllExcelResourcePaths(dirType, _abTestConfig._excelFileNames); allResPaths.AddRange(_abTestConfig._resourcePaths); bool r = BuildAssetBundles.BuildBundlesFromMap(path, version, _abTestConfig._platformType, target, true, _abTestConfig._bundleName, allResPaths); if (!r) { result = false; } } } return(result); }
void OnGUI() { _scrollPosition = GUILayout.BeginScrollView(_scrollPosition, false, true); GUILayout.Label("*********************************************************************"); GUILayout.Label("* Machine Asset *"); GUILayout.Label("*********************************************************************"); _machineConfig._platformType = (PlatformType)EditorGUILayout.EnumPopup("PlatformType", _machineConfig._platformType); GUILayout.Space(20); GUILayout.Label("Machine Names:"); for (int i = 0; i < _machineConfig._machineConfigs.Count; i++) { GUILayoutOption[] options = new GUILayoutOption[] { }; GUILayout.BeginHorizontal(); _machineConfig._machineConfigs[i]._selected = EditorGUILayout.Toggle(_machineConfig._machineConfigs[i]._selected, options); _machineConfig._machineConfigs[i]._name = EditorGUILayout.TextField("Name:", _machineConfig._machineConfigs[i]._name, options); string v = EditorGUILayout.TextField("Version:", _machineConfig._machineConfigs[i]._version, options); int parseVersion = 0; int.TryParse(v, out parseVersion); if (parseVersion > 0) { _machineConfig._machineConfigs[i]._version = v; } else { Debug.LogError("Version should be integer and >0"); } GUILayout.Space(10); if (GUILayout.Button("-", GUILayout.Width(30))) { _machineConfig._machineConfigs.RemoveAt(i); i--; } GUILayout.EndHorizontal(); } if (GUILayout.Button("+", GUILayout.Width(30))) { _machineConfig._machineConfigs.Insert(_machineConfig._machineConfigs.Count, new SingleMachineAssetConfig()); } GUILayout.Space(20); if (GUILayout.Button("Select All", GUILayout.Width(100.0f))) { SelectAllButtonDown(); } if (GUILayout.Button("Deselect All", GUILayout.Width(100.0f))) { DeselectAllButtonDown(); } GUILayout.Space(20); if (GUILayout.Button("Build Machine AssetBundles", GUILayout.Width(180.0f))) { BuildMachineButtonDown(); } GUILayout.Space(20); GUILayout.Label("Upload Setting:"); _machineConfig._isUploadDebugServer = EditorGUILayout.Toggle("Upload debug server", _machineConfig._isUploadDebugServer); _machineConfig._isUploadReleaseServer = EditorGUILayout.Toggle("Upload release server", _machineConfig._isUploadReleaseServer); _machineConfig._isUseVPN = EditorGUILayout.Toggle("Use VPN", _machineConfig._isUseVPN); if (GUILayout.Button("Upload To Server", GUILayout.Width(120))) { UploadMachineButtonDown(); } GUILayout.Space(20); if (GUILayout.Button("Save config", GUILayout.Width(100))) { BuildAssetBundleHelper.SaveConfigButtonDown(_machineConfig); } GUILayout.EndScrollView(); }
void OnGUI() { _scrollPosition = GUILayout.BeginScrollView(_scrollPosition, false, true); GUILayout.Label("*********************************************************************"); GUILayout.Label("* LiveUpdate Asset *"); GUILayout.Label("*********************************************************************"); _liveUpdateConfig._platformType = (PlatformType)EditorGUILayout.EnumPopup("PlatformType", _liveUpdateConfig._platformType); _liveUpdateConfig._bundleName = EditorGUILayout.TextField("BundleName", _liveUpdateConfig._bundleName); _liveUpdateConfig._version = EditorGUILayout.TextField("ResourceVersion", _liveUpdateConfig._version); GUILayout.Space(20); GUILayout.Label("Excel File Names:"); for (int i = 0; i < _liveUpdateConfig._excelFileNames.Count; i++) { GUILayout.BeginHorizontal(); _liveUpdateConfig._excelFileNames[i] = EditorGUILayout.TextField("Name:", _liveUpdateConfig._excelFileNames[i]); GUILayout.Space(10); if (GUILayout.Button("-", GUILayout.Width(30))) { _liveUpdateConfig._excelFileNames.RemoveAt(i); i--; } GUILayout.EndHorizontal(); } if (GUILayout.Button("+", GUILayout.Width(30))) { _liveUpdateConfig._excelFileNames.Insert(_liveUpdateConfig._excelFileNames.Count, ""); } GUILayout.Space(20); GUILayout.Label("Resource Paths:"); for (int i = 0; i < _liveUpdateConfig._resourcePaths.Count; i++) { GUILayout.BeginHorizontal(); string path = _liveUpdateConfig._resourcePaths[i]; path = EditorGUILayout.TextField(path, GUILayout.Width(300)); if (string.IsNullOrEmpty(path)) { if (!string.IsNullOrEmpty(_lastResourcePath)) { path = _lastResourcePath; } else { path = BuildAssetBundleHelper.GetDefaultResourcePath(); } } if (GUILayout.Button("...", GUILayout.Width(30))) { string selectPath = BuildAssetBundleHelper.OpenFilePanel(path); if (selectPath.Length != 0) { // the path should be relative not absolute one to make it work on any platform. string trimPath = BuildAssetBundleHelper.TrimToRelativePath(selectPath); if (!string.IsNullOrEmpty(trimPath)) { // set relative path _liveUpdateConfig._resourcePaths[i] = trimPath; _lastResourcePath = trimPath; } else { EditorUtility.DisplayDialog("Error", "Folder should be under 'Assets' folder", "OK"); return; } } } if (GUILayout.Button("-", GUILayout.Width(30))) { _liveUpdateConfig._resourcePaths.RemoveAt(i); } if (GUILayout.Button("+", GUILayout.Width(30))) { _liveUpdateConfig._resourcePaths.Insert(i + 1, ""); } GUILayout.EndHorizontal(); } if (GUILayout.Button("+", GUILayout.Width(30))) { _liveUpdateConfig._resourcePaths.Insert(_liveUpdateConfig._resourcePaths.Count, ""); } GUILayout.Space(20); if (GUILayout.Button("Build LiveUpdate AssetBundles", GUILayout.Width(180.0f))) { BuildLiveUpdateButtonDown(); } GUILayout.Space(20); if (GUILayout.Button("Save config", GUILayout.Width(100))) { BuildAssetBundleHelper.SaveConfigButtonDown(_liveUpdateConfig); } GUILayout.EndScrollView(); }
void OnGUI() { _scrollPosition = GUILayout.BeginScrollView(_scrollPosition, false, true); GUILayout.Label("*********************************************************************"); GUILayout.Label("* AB Test *"); GUILayout.Label("*********************************************************************"); _abTestConfig._platformType = (PlatformType)EditorGUILayout.EnumPopup("PlatformType", _abTestConfig._platformType); _abTestConfig._bundleName = EditorGUILayout.TextField("BundleName", _abTestConfig._bundleName); _abTestConfig._version = EditorGUILayout.TextField("Version", _abTestConfig._version); GUILayout.Space(20); GUILayout.Label("AB Versions:"); for (int i = 0; i < _abTestConfig._abVersions.Count; i++) { GUILayout.BeginHorizontal(); _abTestConfig._abVersions[i] = EditorGUILayout.TextField("Version:", _abTestConfig._abVersions[i]); string versionName = _abTestConfig._abVersions[i]; GUILayout.Space(10); if (GUILayout.Button("AB -> Project", GUILayout.Width(90))) { BuildTarget target = BuildAssetBundleHelper.GetBuildTarget(_abTestConfig._platformType); if (target != BuildTarget.NoTarget) { ExcelDirType dirType = BuildAssetBundleHelper.GetExcelDirType(target); BuildABTestHelper.CopyABToProject(versionName, dirType); } else { Debug.LogError("Can't copy since platformType is wrong"); } } GUILayout.Space(10); if (GUILayout.Button("-", GUILayout.Width(30))) { _abTestConfig._abVersions.RemoveAt(i); i--; } GUILayout.EndHorizontal(); } if (GUILayout.Button("+", GUILayout.Width(30))) { _abTestConfig._abVersions.Insert(_abTestConfig._abVersions.Count, ""); } GUILayout.Space(20); GUILayout.Label("Excel File Names:"); for (int i = 0; i < _abTestConfig._excelFileNames.Count; i++) { GUILayout.BeginHorizontal(); _abTestConfig._excelFileNames[i] = EditorGUILayout.TextField("Name:", _abTestConfig._excelFileNames[i]); GUILayout.Space(10); if (GUILayout.Button("-", GUILayout.Width(30))) { _abTestConfig._excelFileNames.RemoveAt(i); i--; } GUILayout.EndHorizontal(); } if (GUILayout.Button("+", GUILayout.Width(30))) { _abTestConfig._excelFileNames.Insert(_abTestConfig._excelFileNames.Count, ""); } GUILayout.Space(20); GUILayout.Label("Resource Paths:"); for (int i = 0; i < _abTestConfig._resourcePaths.Count; i++) { GUILayout.BeginHorizontal(); string path = _abTestConfig._resourcePaths[i]; path = EditorGUILayout.TextField(path, GUILayout.Width(300)); if (string.IsNullOrEmpty(path)) { if (!string.IsNullOrEmpty(_lastResourcePath)) { path = _lastResourcePath; } else { path = BuildAssetBundleHelper.GetDefaultResourcePath(); } } if (GUILayout.Button("...", GUILayout.Width(30))) { string selectPath = BuildAssetBundleHelper.OpenFilePanel(path); if (selectPath.Length != 0) { // the path should be relative not absolute one to make it work on any platform. string trimPath = BuildAssetBundleHelper.TrimToRelativePath(selectPath); if (!string.IsNullOrEmpty(trimPath)) { // set relative path _abTestConfig._resourcePaths[i] = trimPath; _lastResourcePath = trimPath; } else { EditorUtility.DisplayDialog("Error", "Folder should be under 'Assets' folder", "OK"); return; } } } if (GUILayout.Button("-", GUILayout.Width(30))) { _abTestConfig._resourcePaths.RemoveAt(i); } if (GUILayout.Button("+", GUILayout.Width(30))) { _abTestConfig._resourcePaths.Insert(i + 1, ""); } GUILayout.EndHorizontal(); } if (GUILayout.Button("+", GUILayout.Width(30))) { _abTestConfig._resourcePaths.Insert(_abTestConfig._resourcePaths.Count, ""); } GUILayout.Space(20); if (GUILayout.Button("Build ABTest AssetBundles", GUILayout.Width(180.0f))) { BuildABTestButtonDown(); } GUILayout.Space(20); if (GUILayout.Button("Save config", GUILayout.Width(100))) { BuildAssetBundleHelper.SaveConfigButtonDown(_abTestConfig); } GUILayout.EndScrollView(); }