Beispiel #1
0
            public static bool Upgrade(PackageSession session, ILogger log, Package dependentPackage, PackageDependency dependency, Package dependencyPackage, IList <PackageLoadingAssetFile> assetFiles)
            {
                var packageSharedProfile = dependentPackage.Profiles.FindSharedProfile();

                // Only do something if there is a default scene defined
                if (packageSharedProfile != null && packageSharedProfile.Properties.ContainsKey(DefaultScene))
                {
                    var defaultScene = Get(packageSharedProfile.Properties, DefaultScene);

                    var defaultGraphicsProfile = Get(packageSharedProfile.Properties, DefaultGraphicsProfile);

                    // If available, use graphics profile from Windows platform
                    foreach (var profile in dependentPackage.Profiles)
                    {
                        if (profile.Platform == PlatformType.Windows && profile.Properties.ContainsKey(DefaultGraphicsProfile))
                        {
                            defaultGraphicsProfile = Get(profile.Properties, DefaultGraphicsProfile);
                        }
                    }

                    // Create asset
                    var gameSettingsAsset = new GameSettingsAsset
                    {
                        DefaultScene           = AttachedReferenceManager.CreateSerializableVersion <Scene>(defaultScene.Id, defaultScene.Location),
                        BackBufferWidth        = Get(packageSharedProfile.Properties, BackBufferWidth),
                        BackBufferHeight       = Get(packageSharedProfile.Properties, BackBufferHeight),
                        DefaultGraphicsProfile = defaultGraphicsProfile,
                        DisplayOrientation     = Get(packageSharedProfile.Properties, DisplayOrientation),
                    };

                    // Add asset
                    using (var memoryStream = new MemoryStream())
                    {
                        AssetSerializer.Save(memoryStream, gameSettingsAsset, log);
                        assetFiles.Add(new PackageLoadingAssetFile(dependentPackage, GameSettingsLocation + FileExtension, null)
                        {
                            AssetContent = memoryStream.ToArray()
                        });
                    }

                    // Clean properties
                    foreach (var profile in dependentPackage.Profiles)
                    {
                        profile.Properties.Remove(DefaultScene.Name);
                        profile.Properties.Remove(BackBufferWidth.Name);
                        profile.Properties.Remove(BackBufferHeight.Name);
                        profile.Properties.Remove(DefaultGraphicsProfile.Name);
                        profile.Properties.Remove(DisplayOrientation.Name);
                    }
                }

                return(true);
            }
Beispiel #2
0
        private BuildResultCode BuildMaster()
        {
            // Only querying graphics platform, let's load package, print it and exit
            if (builderOptions.GetGraphicsPlatform)
            {
                return BuildGetGraphicsPlatform();
            }

            assetLogger = new RemoteLogForwarder(builderOptions.Logger, builderOptions.LogPipeNames);
            GlobalLogger.GlobalMessageLogged += assetLogger;
            PackageSession projectSession = null;
            try
            {
                // TODO handle solution file + package-id ?

                // When the current platform is not on windows, we need to make sure that all plugins are build, so we
                // setup auto-compile when loading the session
                var sessionLoadParameters = new PackageLoadParameters
                {
                    AutoCompileProjects = builderOptions.Platform != PlatformType.Windows || !builderOptions.DisableAutoCompileProjects,
                    ExtraCompileProperties = builderOptions.ExtraCompileProperties,
                };

                // Loads the root Package
                var projectSessionResult = PackageSession.Load(builderOptions.PackageFile, sessionLoadParameters);
                if (projectSessionResult.HasErrors)
                {
                    projectSessionResult.CopyTo(builderOptions.Logger);
                    return BuildResultCode.BuildError;
                }

                projectSession = projectSessionResult.Session;

                // Check build configuration
                var package = projectSession.LocalPackages.Last();

                // Check build profile
                var sharedProfile = package.Profiles.FindSharedProfile();
                var buildProfile = package.Profiles.FirstOrDefault(pair => pair.Name == builderOptions.BuildProfile);
                if (buildProfile == null)
                {
                    builderOptions.Logger.Error("Unable to find profile [{0}] in package [{1}]", builderOptions.BuildProfile, package.FullPath);
                    return BuildResultCode.BuildError;
                }

                // Setup variables
                var buildDirectory = builderOptions.BuildDirectory;
                var outputDirectory = builderOptions.OutputDirectory;

                // Process game settings asset
                var gameSettingsAsset = package.GetGameSettingsAsset();
                if (gameSettingsAsset == null)
                {
                    builderOptions.Logger.Warning("Could not find game settings asset at location [{0}]. Use a Default One", GameSettingsAsset.GameSettingsLocation);
                    gameSettingsAsset = new GameSettingsAsset();
                }

                // Create context
                var context = new AssetCompilerContext
                {
                    Profile = builderOptions.BuildProfile,
                    Platform = builderOptions.Platform
                };
                context.SetGameSettingsAsset(gameSettingsAsset);

                // Copy properties from shared profiles to context properties
                if (sharedProfile != null)
                {
                    sharedProfile.Properties.CopyTo(context.PackageProperties, true);
                }

                // Copy properties from build profile
                buildProfile.Properties.CopyTo(context.PackageProperties, true);

                // Builds the project
                var assetBuilder = new PackageCompiler(new RootPackageAssetEnumerator(package));
                assetBuilder.AssetCompiled += RegisterBuildStepProcessedHandler;

                var assetBuildResult = assetBuilder.Compile(context);
                assetBuildResult.CopyTo(builderOptions.Logger);
                if (assetBuildResult.HasErrors)
                    return BuildResultCode.BuildError;

                // Create the builder
                var indexName = "index." + builderOptions.BuildProfile;
                builder = new Builder(buildDirectory, builderOptions.BuildProfile, indexName, builderOptions.Logger) { ThreadCount = builderOptions.ThreadCount };
                builder.MonitorPipeNames.AddRange(builderOptions.MonitorPipeNames);

                // Add build steps generated by AssetBuilder
                builder.Root.Add(assetBuildResult.BuildSteps);

                // Run builder
                var result = builder.Run(Builder.Mode.Build);
                builder.WriteIndexFile(false);

                // Fill list of bundles
                var bundlePacker = new BundlePacker();
                bundlePacker.Build(builderOptions.Logger, projectSession, buildProfile, indexName, outputDirectory, builder.DisableCompressionIds);

                return result;
            }
            finally
            {
                if (builder != null)
                {
                    builder.Dispose();
                }

                // Dispose the session (in order to unload assemblies)
                if (projectSession != null)
                {
                    projectSession.Dispose();
                }

                // Flush and close logger
                GlobalLogger.GlobalMessageLogged -= assetLogger;
                assetLogger.Dispose();
            }
        }
 public static void SetGameSettingsAsset(this AssetCompilerContext context, GameSettingsAsset gameSettingsAsset)
 {
     context.Properties.Set(GameSettingsAssetKey, gameSettingsAsset);
 }
 public static void SetGameSettingsAsset(this AssetCompilerContext context, GameSettingsAsset gameSettingsAsset)
 {
     context.Properties.Set(GameSettingsAssetKey, gameSettingsAsset);
 }
            public static bool Upgrade(PackageSession session, ILogger log, Package dependentPackage, PackageDependency dependency, Package dependencyPackage, IList<PackageLoadingAssetFile> assetFiles)
            {
                var packageSharedProfile = dependentPackage.Profiles.FindSharedProfile();

                // Only do something if there is a default scene defined
                if (packageSharedProfile != null && packageSharedProfile.Properties.ContainsKey(DefaultScene))
                {
                    var defaultScene = packageSharedProfile.Properties.Get(DefaultScene);

                    var defaultGraphicsProfile = packageSharedProfile.Properties.Get(DefaultGraphicsProfile);

                    // If available, use graphics profile from Windows platform
                    foreach (var profile in dependentPackage.Profiles)
                    {
                        if (profile.Platform == PlatformType.Windows && profile.Properties.ContainsKey(DefaultGraphicsProfile))
                        {
                            defaultGraphicsProfile = profile.Properties.Get(DefaultGraphicsProfile);
                        }
                    }

                    // Create asset
                    var gameSettingsAsset = new GameSettingsAsset
                    {
                        DefaultScene = AttachedReferenceManager.CreateSerializableVersion<Scene>(defaultScene.Id, defaultScene.Location),
                        BackBufferWidth = packageSharedProfile.Properties.Get(BackBufferWidth),
                        BackBufferHeight = packageSharedProfile.Properties.Get(BackBufferHeight),
                        DefaultGraphicsProfile = defaultGraphicsProfile,
                        DisplayOrientation = packageSharedProfile.Properties.Get(DisplayOrientation),
                    };

                    // Add asset
                    using (var memoryStream = new MemoryStream())
                    {
                        AssetSerializer.Save(memoryStream, gameSettingsAsset, log);
                        assetFiles.Add(new PackageLoadingAssetFile(dependentPackage, GameSettingsLocation + FileExtension, null) { AssetContent = memoryStream.ToArray() });
                    }

                    // Clean properties
                    foreach (var profile in dependentPackage.Profiles)
                    {
                        profile.Properties.Remove(DefaultScene);
                        profile.Properties.Remove(BackBufferWidth);
                        profile.Properties.Remove(BackBufferHeight);
                        profile.Properties.Remove(DefaultGraphicsProfile);
                        profile.Properties.Remove(DisplayOrientation);
                    }
                }

                return true;
            }