public string[] GetScenes(WorkerPlatform workerType) { List <string> scenePathsBuilder = new List <string>(); string[] scenePaths; switch (workerType) { case WorkerPlatform.UnityClient: Debug.Log("Client Scene Count: " + spatialSceneNames.Client.Count); scenePathsBuilder.AddRange(spatialSceneNames.Client); scenePathsBuilder.AddRange(spatialSceneNames.Common); scenePaths = FormatSceneList(scenePathsBuilder.ToArray(), scenePathsBuilder[0]); break; case WorkerPlatform.UnityWorker: scenePathsBuilder.AddRange(spatialSceneNames.Worker); scenePathsBuilder.AddRange(spatialSceneNames.Common); scenePaths = FormatSceneList(scenePathsBuilder.ToArray(), scenePathsBuilder[0]); break; default: throw new Exception("Attempting to get scenes for unrecognised worker platform"); } EditorBuildSettings.scenes = scenePaths.Select(scenePath => new EditorBuildSettingsScene(scenePath, true)).ToArray(); return(scenePaths); }
public string[] GetScenePathsForWorker(WorkerPlatform workerType) { return(GetScenesForWorker(workerType) .Where(sceneAsset => sceneAsset != null) .Select(AssetDatabase.GetAssetPath) .ToArray()); }
public UnityPlayerBuilder(WorkerPlatform workerType, string targetString, Config config) { WorkerType = workerType; BuildTarget = ToRuntimePlatform(targetString); this.config = config; options = GenerateFlag(config.FlagsForPlatform(targetString)); platformData = CreatePlatformData(BuildTarget); }
private static IList <UnityPlayerBuilder> ToPlatformBuilders(WorkerPlatform platform, Config config) { if (config == null) { return(new List <UnityPlayerBuilder>()); } return(config.Targets.Select(configTarget => new UnityPlayerBuilder(platform, configTarget, config)).ToList()); }
/// <inheritdoc cref="IPlayerBuildEvents" /> public virtual string[] GetScenes(WorkerPlatform workerType) { var scenePath = workerToScene[workerType]; var scene = EditorSceneManager.OpenScene(scenePath, OpenSceneMode.Single); ProcessScene(scene.name); return(new[] { scenePath }); }
private static bool IsPlatformCompatible(object[] workerTypes, WorkerPlatform platform) { WorkerPlatform workerPlatformMask = 0; for (int i = 0; i < workerTypes.Length; i++) { workerPlatformMask |= ((WorkerTypeAttribute)workerTypes[i]).WorkerPlatform; } return(workerTypes.Length == 0 || (workerPlatformMask & platform) != 0); }
public static void Export(WorkerPlatform platform) { Clean(); var prefabPaths = GetAllPrefabAssetPaths(); var copies = CopyPrefabs(prefabPaths); CompilePrefabs(copies, platform); AssetDatabase.SaveAssets(); Resources.UnloadUnusedAssets(); }
public BuildEnvironmentConfig GetEnvironmentConfigForWorker(WorkerPlatform platform, BuildEnvironment targetEnvironment) { var config = WorkerBuildConfigurations.FirstOrDefault(x => x.WorkerPlatform == platform); if (config == null) { throw new ArgumentException("Unknown WorkerPlatform " + platform); } return(config.GetEnvironmentConfig(targetEnvironment)); }
private SceneAsset[] GetScenesForWorker(WorkerPlatform workerPlatform) { WorkerBuildConfiguration configurationForWorker = null; if (WorkerBuildConfigurations != null) { configurationForWorker = WorkerBuildConfigurations.FirstOrDefault(config => config.WorkerPlatform == workerPlatform); } return(configurationForWorker == null ? new SceneAsset[0] : configurationForWorker.ScenesForWorker); }
private static void BuildWorkerForTarget(WorkerPlatform workerPlatform, BuildTarget buildTarget, BuildOptions buildOptions, BuildEnvironment targetEnvironment) { var spatialOSBuildConfiguration = GetBuildConfiguration(); Debug.LogFormat("Building \"{0}\" for worker platform: \"{1}\", environment: \"{2}\"", buildTarget, workerPlatform, targetEnvironment); var symbols = PlayerSettings.GetScriptingDefineSymbolsForGroup(BuildTargetGroup.Standalone); try { var workerBuildData = new WorkerBuildData(workerPlatform, buildTarget); var scenes = spatialOSBuildConfiguration.GetScenePathsForWorker(workerPlatform); var typeSymbol = $"IMPROBABLE_WORKERTYPE_{workerBuildData.WorkerPlatformName.ToUpper()}"; var workerSymbols = symbols.Split(';') .Concat(new[] { typeSymbol }) .Distinct() .Aggregate((current, next) => current + ";" + next); PlayerSettings.SetScriptingDefineSymbolsForGroup(BuildTargetGroup.Standalone, workerSymbols); var buildPlayerOptions = new BuildPlayerOptions { options = buildOptions, target = buildTarget, scenes = scenes, locationPathName = workerBuildData.BuildScratchDirectory }; var result = BuildPipeline.BuildPlayer(buildPlayerOptions); if (result.summary.result != BuildResult.Succeeded) { throw new BuildFailedException($"Build failed for {workerPlatform}"); } var zipPath = Path.GetFullPath(Path.Combine(PlayerBuildDirectory, workerBuildData.PackageName)); var basePath = PathUtil.Combine(BuildPaths.BuildScratchDirectory, workerBuildData.PackageName); Zip(zipPath, basePath, targetEnvironment == BuildEnvironment.Local ? PlayerCompression.Disabled : PlayerCompression.Enabled); } finally { PlayerSettings.SetScriptingDefineSymbolsForGroup(BuildTargetGroup.Standalone, symbols); } }
public static void BuildWorkerForEnvironment(WorkerPlatform workerPlatform, BuildEnvironment targetEnvironment) { var spatialOSBuildConfiguration = GetBuildConfiguration(); var environmentConfig = spatialOSBuildConfiguration.GetEnvironmentConfigForWorker(workerPlatform, targetEnvironment); var buildPlatforms = environmentConfig.BuildPlatforms; var buildOptions = environmentConfig.BuildOptions; PathUtil.EnsureDirectoryExists(PlayerBuildDirectory); foreach (var unityBuildTarget in GetUnityBuildTargets(buildPlatforms)) { BuildWorkerForTarget(workerPlatform, unityBuildTarget, buildOptions, targetEnvironment); } }
private static void CompilePrefabs(List <string> paths, WorkerPlatform platform) { var progress = 0; foreach (var path in paths) { EditorUtility.DisplayProgressBar("Processing EntityPrefabs", "Preparing", progress / (float)paths.Count()); progress++; var compiler = new PrefabCompiler(platform); var prefab = AssetDatabase.LoadAssetAtPath <GameObject>(path); compiler.Compile(prefab); } EditorUtility.ClearProgressBar(); }
// Overridden function to load (and optionally modify) scenes, then return an array of scene paths to be built into the worker public string[] GetScenes(WorkerPlatform workerType) { string[] scenePaths; switch (workerType) { case WorkerPlatform.UnityClient: scenePaths = FormatSceneList(BuildSettings.ClientScenes, BuildSettings.ClientDefaultActiveScene); break; case WorkerPlatform.UnityWorker: scenePaths = FormatSceneList(BuildSettings.WorkerScenes, BuildSettings.WorkerDefaultActiveScene); break; default: throw new Exception("Attempting to get scenes for unrecognised worker platform"); } return(scenePaths); }
public WorkerBuildData(WorkerPlatform workerPlatform, BuildTarget buildTarget) { switch (workerPlatform) { case WorkerPlatform.UnityWorker: case WorkerPlatform.UnityClient: break; default: throw new ArgumentException("Unsupported WorkerPlatform " + workerPlatform); } if (!BuildTargetNames.ContainsKey(buildTarget)) { throw new ArgumentException("Unsupported BuildPlatform " + workerPlatform); } this.workerPlatform = workerPlatform; this.buildTarget = buildTarget; }
public BehaviourWorkerCompatibilityCache(WorkerPlatform platform) { compatibleBehaviours = new HashSet <Type>(); var allTypes = AppDomain .CurrentDomain .GetAssemblies() .SelectMany(assembly => assembly.GetTypes()); foreach (var type in allTypes) { var attributes = type.GetCustomAttributes(typeof(WorkerTypeAttribute), false); if (typeof(MonoBehaviour).IsAssignableFrom(type)) { if (IsPlatformCompatible(attributes, platform)) { compatibleBehaviours.Add(type); } } else if (attributes.Length > 0) { Debug.LogWarningFormat("{0} uses EngineTypeAttribute but is not MonoBehavoiur. The attribute will be ignored.", type.FullName); } } }
public static IPackager GetDefaultPackager(WorkerPlatform workerType, BuildTarget buildTarget, Config config) #pragma warning restore 0618 { return(new SimplePackager()); }
public PrefabCompiler(WorkerPlatform workerPlatform) { this.workerPlatform = workerPlatform; compatibilityCache = new BehaviourWorkerCompatibilityCache(workerPlatform); }
/// <inheritdoc cref="IPlayerBuildEvents" /> public virtual void BeginPackage(WorkerPlatform workerType, BuildTarget target, Config config, string packagePath) { #pragma warning disable 0618 UnityPlayerBuilder.GetPackager(workerType, target, config).Prepare(packagePath); #pragma warning restore 0618 }
public WorkerTypeAttribute(WorkerPlatform workerPlatform) { WorkerPlatform = workerPlatform; }
// Overridden function - use to do work such as copying additional files that need to be packaged with the worker public void BeginPackage(WorkerPlatform workerType, BuildTarget target, Config config, string packagePath) { }
private static void BuildWorkerForTarget(WorkerPlatform workerPlatform, BuildTarget buildTarget, BuildOptions buildOptions, BuildEnvironment targetEnvironment) { var spatialOSBuildConfiguration = GetBuildConfiguration(); Debug.LogFormat("Building \"{0}\" for worker platform: \"{1}\", environment: \"{2}\"", buildTarget, workerPlatform, targetEnvironment); EntityPrefabs.Export(workerPlatform); var symbols = PlayerSettings.GetScriptingDefineSymbolsForGroup(BuildTargetGroup.Standalone); try { var workerBuildData = new WorkerBuildData(workerPlatform, buildTarget); var scenes = spatialOSBuildConfiguration.GetScenePathsForWorker(workerPlatform); var typeSymbol = "IMPROBABLE_WORKERTYPE_" + workerBuildData.WorkerPlatformName.ToUpper(); var workerSymbols = symbols.Split(';') .Concat(new[] { typeSymbol }) .Distinct() .Aggregate((current, next) => current + ";" + next); PlayerSettings.SetScriptingDefineSymbolsForGroup(BuildTargetGroup.Standalone, workerSymbols); BuildPlayerOptions buildPlayerOptions = new BuildPlayerOptions { options = buildOptions, target = buildTarget, scenes = scenes, locationPathName = workerBuildData.BuildScratchDirectory }; var buildConfigString = string.Format("WorkerPlatform={0};BuildTarget={1};BuildOptions={2}", workerPlatform, buildTarget, buildOptions); var buildErrorMessage = BuildPipeline.BuildPlayer(buildPlayerOptions); #if UNITY_2018_1_OR_NEWER if (buildErrorMessage.summary.result != UnityEditor.Build.Reporting.BuildResult.Succeeded) { throw new ApplicationException(string.Format("Failed to build player {0} due to {1} errors", buildConfigString, buildErrorMessage.summary.totalErrors)); } #else if (!string.IsNullOrEmpty(buildErrorMessage)) { throw new ApplicationException(string.Format("Failed to build player {0} due to {1}", buildConfigString, buildErrorMessage)); } #endif Debug.LogFormat("Built player {0} into {1}", buildConfigString, workerBuildData.BuildScratchDirectory); var zipPath = Path.GetFullPath(Path.Combine(PlayerBuildDirectory, workerBuildData.PackageName)); var basePath = PathUtil.Combine(BuildPaths.BuildScratchDirectory, workerBuildData.PackageName); SpatialCommands.Zip(zipPath, basePath, targetEnvironment == BuildEnvironment.Local ? PlayerCompression.Disabled : PlayerCompression.Enabled); } finally { PlayerSettings.SetScriptingDefineSymbolsForGroup(BuildTargetGroup.Standalone, symbols); EntityPrefabs.Clean(); } }
public static string ToWorkerName(WorkerPlatform workerPlatform) { return(WorkerPlatformToNameMap[workerPlatform]); }