UNPKG

com.ubisoft.hotel.packagemanager

Version:

This package is responsible for managing Hotel packages and for assisting consumers in building their apps

439 lines (364 loc) 19.2 kB
using System; using System.Collections.Generic; using UnityEditor; using Ubisoft.Hotel.Package.Editor; using Ubisoft.Hotel.PackageManager.Editor; #if HT_PACKAGE_NETWORKMANAGER_PROD // Make sure that Ubisoft.Hotel.NetworkManager.Editor and Ubisoft.Hotel.NetworkManager are added to the Assembly Definition References section // in Ubisoft.Consumer.PackageManager.Editor.asmdef using Ubisoft.Hotel.Networking.Editor; using NetEnvironment = Ubisoft.Hotel.Networking.Environment; #endif namespace Ubisoft.Consumer.PackageManager.Editor { public class ConsumerPackageSuiteBuilder : PackageSuiteBuilder { /// <summary> /// CONSUMER is used in the comments to guide through the process of handling suites and properties /// </summary> #region suites /// CONSUMER: 1.)Add here your package suite names. /// /// The values below were created to ilustrate how to use this section. Feel free to edit them at will. /// /// xTech team recommend to use at least the following set of suites: /// -)A suite for every compilation that needs to be released to PRODUCTION /// -)A suite for customised suites, typically by passing a set of setup properties from inspector or you CI/CD pipeline. Example: /// -)Bundle: dev /// -)Compilation: master /// -)Scheme: debug /// -)NetworkEnvironment: stage private const string SUITE_MASTER_PROD = "master_prod"; private const string SUITE_CUSTOM = "custom"; private static readonly List<string> PackageSuiteNames = new List<string>() { SUITE_CUSTOM, SUITE_MASTER_PROD }; #endregion #region setup /// CUSTOMER: /// 2.)Create an enum for each setup properties that you want to be able to select easily from inspector or CI/CD pipeline. /// Add its types to <c>s_types</c> too. /// /// The enums below were created to ilustrate how to use this section. Feel free to edit them at will. /// /// xTech team recommend to use at least the following set of setup properties : /// -)Bundle: /// -)store: For the build that will be released live /// -)dev: For development builds so the team can have in full control of all store related features (IAPs, SIWA, push notifications, ...) /// /// -)Compilation: Define here all packages and native capabilities required by every compilation. One per platform /// -)master: For mobile version, unless iOS and Android compilations are pretty different and having two different compilations is more convenient /// /// -)Scheme: /// -)debug: For development: Cheats on, verbose logs /// -)profiler: For profiling: Cheats on, minimum logs to avoid hitting performance, profiler on /// -)prerelease: For QC: Cheats on, medium/minimum logs /// -)release: For live: Cheats off, minimum logs /// /// -)NetworkEnvironment: /// -)dev: For development /// -)integration: For integration testing /// -)stage: For testing QC candidate builds /// -)qc: For testing QC builds /// -)prod: For live private enum Bundle { Store, Dev }; private enum Compilation { Master }; private enum Scheme { Debug, Profiler, Prerelease, Release }; private enum NetworkEnvironment { Local, Dev, Integration, Stage, Qc, Production }; private enum UseCase { None, SetSceneList, EnableHeadlessMode }; private static readonly Type BundleType = typeof(Bundle); private static readonly Type CompilationType = typeof(Compilation); private static readonly Type SchemeType = typeof(Scheme); private static readonly Type NetworkEnvironmentType = typeof(NetworkEnvironment); private static readonly Type UseCaseType = typeof(UseCase); private static Bundle GetBundle(PackageSuiteSetup packageSuiteSetup) { int value = packageSuiteSetup.GetSelectedValueByType(BundleType); return (Bundle)value; } private static Compilation GetCompilation(PackageSuiteSetup packageSuiteSetup) { int value = packageSuiteSetup.GetSelectedValueByType(CompilationType); return (Compilation)value; } private static Scheme GetScheme(PackageSuiteSetup packageSuiteSetup) { int value = packageSuiteSetup.GetSelectedValueByType(SchemeType); return (Scheme)value; } private static NetworkEnvironment GetNetworkEnvironment(PackageSuiteSetup packageSuiteSetup) { int value = packageSuiteSetup.GetSelectedValueByType(NetworkEnvironmentType); return (NetworkEnvironment)value; } private static UseCase GetUseCase(PackageSuiteSetup packageSuiteSetup) { int value = packageSuiteSetup.GetSelectedValueByType(UseCaseType); return (UseCase)value; } private readonly static List<Type> s_types = new List<Type>() { BundleType, CompilationType, SchemeType, NetworkEnvironmentType, UseCaseType }; #endregion #region packages /// CONSUMER: /// 3.)Add here a definitions for every package that you want to handle through package suites. /// You don't need to delete the definition of the package from manifest.json. Hotel PackageManager will do it for you for those compilations /// that don't need it /// /// xTech Team recommend to define here the highest version of every package handled by Hotel so you can find them all together /// /// You can use different versions of a package for two different compilations by adding the one required by a compilation when you create the package suite /// that contains the compilation. /// private static readonly Dictionary<string, string> Packages = new Dictionary<string, string>() { // Add here the definitions for the packages that you want to handle through package suites // Example //{ "com.ubisoft.hotel.core", "1.0.1" } }; #endregion public ConsumerPackageSuiteBuilder() : base(Packages, PackageSuiteNames) { } private PackageSuiteSetup CreatePackageSuiteSetup(Bundle bundle, Compilation compilation, Scheme scheme, NetworkEnvironment networkEnvironvent, UseCase useCase) { return new PackageSuiteSetup(s_types, new List<int>() { (int)bundle, (int)compilation, (int)scheme, (int)networkEnvironvent, (int)useCase }); } protected override PackageSuiteSetup GetPackageSuiteSetup(string packageSuiteName) { /// CONSUMER: /// 4.)Add here a configuration for every package suite PackageSuiteSetup returnValue = null; /// CONSUMER: /// 5.)Uncomment this code if you want to start off with these package suite. /// They're commented out by default so Hotel doesn't mess up with legacy projects /// that are in the works of adopting Hotel switch (packageSuiteName) { case SUITE_MASTER_PROD: returnValue = CreatePackageSuiteSetup(Bundle.Store, Compilation.Master, Scheme.Release, NetworkEnvironment.Production, UseCase.None); break; case SUITE_CUSTOM: returnValue = CreatePackageSuiteSetup(Bundle.Dev, Compilation.Master, Scheme.Debug, NetworkEnvironment.Dev, UseCase.None); break; } return returnValue; } public override PackageProperty CreatePackageProperty(BuildTarget buildTarget, string parentName, Type type, PackageSuiteSetup packageSuiteSetup) { /// CONSUMER: /// 5.)Delegate in your own method for every setup property type /// Pass in packageSuiteSetup as an argument if your method needs to look up the values of several setup property types /// to create the PackageProperty object PackageProperty returnValue = null; if (type == BundleType) { returnValue = CreateBundleProperty(parentName, GetBundle(packageSuiteSetup)); } else if (type == CompilationType) { returnValue = CreateCompilationProperty(parentName, GetCompilation(packageSuiteSetup), packageSuiteSetup); } else if (type == SchemeType) { returnValue = CreateSchemeProperty(parentName, GetScheme(packageSuiteSetup)); } else if (type == NetworkEnvironmentType) { returnValue = CreateNetworkEnvironmentProperty(parentName, GetNetworkEnvironment(packageSuiteSetup)); } else if (type == UseCaseType) { returnValue = CreateUseCaseProperty(parentName, GetUseCase(packageSuiteSetup)); } return returnValue; } private PackageProperty CreateBundleProperty(string parentName, Bundle value) { UnityBuildProperty returnValue = null; string bundleId = null; switch (value) { case Bundle.Store: bundleId = "com.ubisoft.hungrydragon.dev"; break; case Bundle.Dev: bundleId = "com.ubisoft.hungrydragon.dev"; break; } if (!string.IsNullOrEmpty(bundleId)) { returnValue = CreateUnityBuildProperty(parentName, value.ToString()); returnValue.BundleId = bundleId; } return returnValue; } private PackageProperty CreateCompilationProperty(string parentName, Compilation value, PackageSuiteSetup packageSuiteSetup) { PackagePropertyComposite returnValue = CreatePackagePropertyComposite(parentName, value.ToString()); /// CONSUMER: /// 6.)Add here all properties that the compilation needs PlatformBuildProperty_iOS iosProperty = CreatePlatformBuildProperty_iOS(parentName, "iOS"); iosProperty.AddEntitlement(PlatformBuildProperty_iOS.EEntitlement.SignInWithApple); returnValue.AddProperty(iosProperty); return returnValue; } private PackageProperty CreateSchemeProperty(string parentName, Scheme value) { SchemeProperty returnValue = CreateSchemeProperty(parentName, value.ToString()); switch (value) { case Scheme.Debug: ConsumerPackageSuiteBuilderHelper.SchemeProperty_SetupDebug(returnValue); break; case Scheme.Profiler: ConsumerPackageSuiteBuilderHelper.SchemeProperty_SetupProfiler(returnValue); break; case Scheme.Prerelease: ConsumerPackageSuiteBuilderHelper.SchemeProperty_SetupPrerelease(returnValue); break; case Scheme.Release: ConsumerPackageSuiteBuilderHelper.SchemeProperty_SetupRelease(returnValue); break; default: returnValue = null; break; } return returnValue; } #if HT_PACKAGE_NETWORKMANAGER_PROD private NetworkManagerProperty CreateNetworkEnvironmentProperty(string parentName, NetworkEnvironment networkEnvironment) { string selectedEnvironment = networkEnvironment.ToString(); string propertyName = GetPropertyName(parentName, "network", selectedEnvironment); List<NetEnvironment> environments = new List<NetEnvironment>(); NetEnvironment netEnvironment = new NetEnvironment(NetworkEnvironment.Local.ToString(), NetEnvironment.EType.Local, "host_local", 80); environments.Add(netEnvironment); netEnvironment = new NetEnvironment(NetworkEnvironment.Dev.ToString(), NetEnvironment.EType.Dev, "host_dev", 1000); environments.Add(netEnvironment); netEnvironment = new NetEnvironment(NetworkEnvironment.Integration.ToString(), NetEnvironment.EType.Integration, "host_integration", 2000); environments.Add(netEnvironment); netEnvironment = new NetEnvironment(NetworkEnvironment.Stage.ToString(), NetEnvironment.EType.Stage, "host_stage", 3000); environments.Add(netEnvironment); netEnvironment = new NetEnvironment(NetworkEnvironment.Qc.ToString(), NetEnvironment.EType.Qc, "host_qc", 4000); environments.Add(netEnvironment); netEnvironment = new NetEnvironment(NetworkEnvironment.Production.ToString(), NetEnvironment.EType.Production, "host_prod", 5000); environments.Add(netEnvironment); return NetworkManagerProperty.CreateInstanceWithParams(propertyName, environments, selectedEnvironment); } #else private PackageProperty CreateNetworkEnvironmentProperty(string parentName, NetworkEnvironment networkEnvironment) { return CreateUnityBuildProperty(parentName, "network_dummy"); } #endif // --------------------------------------------------------------------------------------------------------------------------------- // Use cases: This section showcases some useful use cases. // // More information: https://confluence.ubisoft.com/x/6L1OR // // Be aware that for the sake of simplicity a new PackageProperty object is created for each use case, but you can reuse the same object // to hold stuff required by several use cases as long as they don't conflict with each other. // --------------------------------------------------------------------------------------------------------------------------------- private PackageProperty CreateUseCaseProperty(string parentName, UseCase useCase) { PackageProperty returnValue = null; parentName += ":use_case"; string propertyName = useCase.ToString(); switch (useCase) { case UseCase.None: returnValue = CreateUnityBuildProperty(parentName, propertyName); break; case UseCase.SetSceneList: returnValue = CreateSceneListProperty(parentName, propertyName); break; case UseCase.EnableHeadlessMode: returnValue = CreateEnableHeadlessModeProperty(parentName, propertyName); break; } return returnValue; } /// <summary> /// Use case: The list of scenes to include in the build are not the same for all suites. /// </summary> private PackageProperty CreateSceneListProperty(string parentName, string propertyName) { // Create a UnityBuildProperty, which is the built-in property that gives support to define a scene list to be included in the build UnityBuildProperty returnValue = CreateUnityBuildProperty(parentName, propertyName); // Create a list with the relative unity path to the scenes to be included // By default the first scene in this list will be the first scene in BuildSettings string scene_1 = "Assets/properties_use_cases/Scenes/Scene_1.unity"; string scene_2 = "Assets/properties_use_cases/Scenes/Scene_2.unity"; List<string> sceneList = new List<string>() { scene_1, scene_2 }; ConsumerPackageSuiteBuilderHelper.UnityBuildProperty_SetupSceneList(returnValue, sceneList, scene_2); // RESULT: // Open BuildSettings and verify that the list of scenes is correct return returnValue; } /// <summary> /// Use case: Unity headless/server build mode needs to be enabled for some suites, typically for those that are meant to be run by server (i.e. PvP) /// </summary> private PackageProperty CreateEnableHeadlessModeProperty(string parentName, string propertyName) { // There are two ways to do it: // 1. Via UnityBuildProperty PackageProperty returnValue = CreateEnableHeadlessModePropertyViaUnityProperty(parentName, propertyName); // 2. Via SchemeProperty //PackageProperty returnValue = CreateEnableHeadlessModePropertyViaSchemeProperty(parentName, propertyName); // RESULT: // Open BuildSettings and verify that 'Server Build' option is enabled // Be aware that StandAlone needs to be the active buildTarget to make this option available return returnValue; } private PackageProperty CreateEnableHeadlessModePropertyViaUnityProperty(string parentName, string propertyName) { // Create a UnityBuildProperty, which is the built-in property that gives support to define a scene list to be included in the build UnityBuildProperty returnValue = CreateUnityBuildProperty(parentName, propertyName); ConsumerPackageSuiteBuilderHelper.UnityBuildProperty_SetupHeadlessMode(returnValue, true); return returnValue; } private PackageProperty CreateEnableHeadlessModePropertyViaSchemeProperty(string parentName, string propertyName) { SchemeProperty returnValue = CreateSchemeProperty(parentName, propertyName); ConsumerPackageSuiteBuilderHelper.SchemeProperty_SetupHeadlessMode(returnValue, true); return returnValue; } } }