public override IEnumerator Execute(UTContext context) { var theOutputFile = outputFileName.EvaluateIn(context); if (string.IsNullOrEmpty(theOutputFile)) { throw new UTFailBuildException("You must specify an output file name.", this); } var theBundleType = bundleType.EvaluateIn(context); var theFiles = new string[0]; if (theBundleType == UTTypeOfBundle.SimpleAssetBundle || !useScenesFromBuildSettings.EvaluateIn(context)) { var theIncludes = EvaluateAll(includes, context); var theExcludes = EvaluateAll(excludes, context); theFiles = UTFileUtils.CalculateFileset(theIncludes, theExcludes); UTFileUtils.FullPathToProjectPath(theFiles); } else { var scenes = EditorBuildSettings.scenes; theFiles = Array.ConvertAll <EditorBuildSettingsScene, string> (scenes, scene => scene.path); } if (UTPreferences.DebugMode) { foreach (var file in theFiles) { Debug.Log("Including: " + file, this); } } Debug.Log("Including " + theFiles.Length + " assets/scenes."); if (theBundleType == UTTypeOfBundle.StreamedScenes && theFiles.Length == 0) { throw new UTFailBuildException("No scenes have been selected. Unable to build a streamed scenes asset bundle with no scenes.", this); } var theMainAsset = ""; UObject realMainAsset = null; UObject[] realAssets = null; if (theBundleType == UTTypeOfBundle.SimpleAssetBundle) { theMainAsset = mainAsset.EvaluateIn(context); if (!String.IsNullOrEmpty(theMainAsset)) { if (theMainAsset.Contains("*")) { var finalList = UTFileUtils.CalculateFileset(new string[] { theMainAsset }, new string[0]); if (finalList.Length != 1) { throw new UTFailBuildException("Main asset wildcard " + theMainAsset + " yielded " + finalList.Length + " results but should yield exactly one asset.", this); } theMainAsset = UTFileUtils.FullPathToProjectPath(finalList [0]); } // now get the real objects for the paths realMainAsset = AssetDatabase.LoadMainAssetAtPath(theMainAsset); if (realMainAsset == null) { throw new UTFailBuildException("Unable to load the main asset " + theMainAsset + " from asset database.", this); } } realAssets = Array.ConvertAll <string, UObject> (theFiles, file => { var result = AssetDatabase.LoadMainAssetAtPath(file); if (result == null) { throw new UTFailBuildException("Unable to load the asset " + file, this); } return(result); }); } var theBuildTarget = targetPlatform.EvaluateIn(context); if (pushDependencies.EvaluateIn(context)) { UTAssetDependencyStack.Push(); } try { UTFileUtils.EnsureParentFolderExists(theOutputFile); if (theBundleType == UTTypeOfBundle.StreamedScenes) { Debug.Log("Building streamed scenes asset bundle."); var result = BuildPipeline.BuildStreamedSceneAssetBundle(theFiles, theOutputFile, theBuildTarget); if (!string.IsNullOrEmpty(result)) { throw new UTFailBuildException("Building streamed scene asset bundle failed. " + result, this); } } else { Debug.Log("Building asset bundle."); var realCollectDependencies = collectDependencies.EvaluateIn(context); var realCompleteAssets = completeAssets.EvaluateIn(context); var realDisableWriteTypeTree = disableWriteTypeTree.EvaluateIn(context); var realDeterministicAssetBundle = deterministicAssetBundle.EvaluateIn(context); var buildOpts = (BuildAssetBundleOptions)0; if (realCollectDependencies) { buildOpts |= BuildAssetBundleOptions.CollectDependencies; } if (realCompleteAssets) { buildOpts |= BuildAssetBundleOptions.CompleteAssets; } if (realDisableWriteTypeTree) { buildOpts |= BuildAssetBundleOptions.DisableWriteTypeTree; } if (realDeterministicAssetBundle) { buildOpts |= BuildAssetBundleOptions.DeterministicAssetBundle; } if (!BuildPipeline.BuildAssetBundle(realMainAsset, realAssets, theOutputFile, buildOpts, theBuildTarget)) { throw new UTFailBuildException("Building asset bundle failed.", this); } } Debug.Log("Built asset bundle at " + theOutputFile); } finally { if (popAllDependencies.EvaluateIn(context)) { UTAssetDependencyStack.PopAll(); } else if (popDependencies.EvaluateIn(context)) { UTAssetDependencyStack.Pop(); } } yield return(""); }
public override IEnumerator Execute(UTContext context) { var theOutput = outputFileName.EvaluateIn(context); if (string.IsNullOrEmpty(theOutput)) { throw new UTFailBuildException("You must specify an output file name.", this); } if (theOutput.StartsWith(Application.dataPath)) { throw new UTFailBuildException("Building a player inside the assets folder will break the build. Please place it somewhere else.", this); } var theTarget = targetPlatform.EvaluateIn(context); if (addPlatformExtension.EvaluateIn(context)) { theOutput += GetPlatformExtension(theTarget); UTFileUtils.EnsureParentFolderExists(theOutput); } #if UNITY_4_1 // workaround for UNITY_4_1 offering StandaloneOSXUniversal but not being able to build for it. if (theTarget == BuildTarget.StandaloneOSXUniversal) { theTarget = BuildTarget.StandaloneOSXIntel; } #endif var useBuildSettings = useScenesFromBuildSettings.EvaluateIn(context); string[] scenes; if (!useBuildSettings) { // get them from includes/excludes var theIncludes = EvaluateAll(includes, context); var theExcludes = EvaluateAll(excludes, context); var fileSet = UTFileUtils.CalculateFileset(theIncludes, theExcludes); if (fileSet.Length == 0) { throw new UTFailBuildException("The file set yielded no scenes to include into the player.", this); } scenes = fileSet; } else { var scenesFromEditor = EditorBuildSettings.scenes; if (scenesFromEditor.Length == 0) { throw new UTFailBuildException("There are no scenes set up in the editor build settings.", this); } var active = Array.FindAll(scenesFromEditor, scene => scene.enabled); scenes = Array.ConvertAll(active, scene => scene.path); } if (UTPreferences.DebugMode) { foreach (var entry in scenes) { Debug.Log("Adding scene: " + entry, this); } } BuildOptions buildOptions = BuildOptions.None; if (developmentBuild.EvaluateIn(context)) { buildOptions |= BuildOptions.Development; } if (runTheBuiltPlayer.EvaluateIn(context)) { buildOptions |= BuildOptions.AutoRunPlayer; } if (showTheBuiltPlayer.EvaluateIn(context)) { buildOptions |= BuildOptions.ShowBuiltPlayer; } if (buildStreamedScenes.EvaluateIn(context)) { buildOptions |= BuildOptions.BuildAdditionalStreamedScenes; } if (acceptExternalModifications.EvaluateIn(context)) { buildOptions |= BuildOptions.AcceptExternalModificationsToPlayer; } if (connectWithProfiler.EvaluateIn(context)) { buildOptions |= BuildOptions.ConnectWithProfiler; } if (allowDebugging.EvaluateIn(context)) { buildOptions |= BuildOptions.AllowDebugging; } if (uncompressedAssetBundle.EvaluateIn(context)) { buildOptions |= BuildOptions.UncompressedAssetBundle; } if (theTarget == BuildTarget.WebPlayer || theTarget == BuildTarget.WebPlayerStreamed) { if (offlineDeployment.EvaluateIn(context)) { buildOptions |= BuildOptions.WebPlayerOfflineDeployment; } if (deployOnline.EvaluateIn(context)) { //buildOptions |= BuildOptions.DeployOnline; } } if (theTarget == BuildTarget.iOS) { if (symlinkLibraries.EvaluateIn(context)) { buildOptions |= BuildOptions.SymlinkLibraries; } } Debug.Log("Building " + ObjectNames.NicifyVariableName(theTarget.ToString()) + " player including " + scenes.Length + " scenes to " + theOutput); yield return(""); if (pushDependencies.EvaluateIn(context)) { UTAssetDependencyStack.Push(); } try { // build the player. var result = BuildPipeline.BuildPlayer(scenes, theOutput, theTarget, buildOptions); if (!string.IsNullOrEmpty(result)) { throw new UTFailBuildException("Building the player failed. " + result, this); } } finally { if (popAllDependencies.EvaluateIn(context)) { UTAssetDependencyStack.PopAll(); } else if (popDependencies.EvaluateIn(context)) { UTAssetDependencyStack.Pop(); } } }