UNPKG

com.ubisoft.hotel.packagemanager

Version:

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

368 lines (306 loc) 15.5 kB
using System; using System.Collections.Generic; using UnityEditor; using Ubisoft.Hotel.Logger.Editor; using Ubisoft.Hotel.Package.Editor; using Ubisoft.Hotel.PackageManager.Editor; #if HT_PACKAGE_NETWORKMANAGER_PROD // Make sure that Ubisoft.Hotel.NetworkManager and Ubisoft.Hotel.NetworkManager.Editor are added to the Assembly Definition References section // in Ubisoft.Consumer.PackageManager.Editor.asmdef using Ubisoft.Hotel.NetworkManager.Editor; using NetEnvironment = Ubisoft.Hotel.NetworkManager.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_MASTER_PROD, SUITE_CUSTOM, }; #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 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 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 readonly static List<Type> s_types = new List<Type>() { BundleType, CompilationType, SchemeType, NetworkEnvironmentType }; #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 const string PACKAGE_HOTEL_SRDEBUGGER = "com.ubisoft.hotel.srdebugger"; 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 { PACKAGE_HOTEL_SRDEBUGGER, "0.5.0" } }; #endregion public ConsumerPackageSuiteBuilder() : base(Packages, PackageSuiteNames) { } private PackageSuiteSetup CreatePackageSuiteSetup(Bundle bundle, Compilation compilation, Scheme scheme, NetworkEnvironment networkEnvironvent) { return new PackageSuiteSetup(s_types, new List<int>() { (int)bundle, (int)compilation, (int)scheme, (int)networkEnvironvent }); } 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); break; case SUITE_CUSTOM: returnValue = CreatePackageSuiteSetup(Bundle.Dev, Compilation.Master, Scheme.Debug, NetworkEnvironment.Dev); 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)); } return returnValue; } private PackageProperty CreateBundleProperty(string parentName, Bundle value) { UnityBuildProperty returnValue = null; string bundleId = null; switch (value) { case Bundle.Store: bundleId = "com.ubisoft.yourgame"; break; case Bundle.Dev: bundleId = "com.ubisoft.yourgame.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 /// // SRDebugger console is excluded from Release builds Scheme scheme = GetScheme(packageSuiteSetup); if (scheme != Scheme.Release) { returnValue.AddPackage(PACKAGE_HOTEL_SRDEBUGGER, Packages[PACKAGE_HOTEL_SRDEBUGGER], PackageDefinition.EImplementation.Prod); } // Create the Logger property based on scheme LoggerProperty loggerProperty = CreateLoggerPropertyFromScheme(parentName, scheme); returnValue.AddProperty(loggerProperty); 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, "local.json"); environments.Add(netEnvironment); netEnvironment = new NetEnvironment(NetworkEnvironment.Dev.ToString(), NetEnvironment.EType.Dev, "host_dev", 1000, "dev.json"); environments.Add(netEnvironment); netEnvironment = new NetEnvironment(NetworkEnvironment.Integration.ToString(), NetEnvironment.EType.Integration, "host_integration", 2000, "int.json"); environments.Add(netEnvironment); netEnvironment = new NetEnvironment(NetworkEnvironment.Stage.ToString(), NetEnvironment.EType.Stage, "host_stage", 3000, "stage.json"); environments.Add(netEnvironment); netEnvironment = new NetEnvironment(NetworkEnvironment.Qc.ToString(), NetEnvironment.EType.Qc, "host_qc", 4000, "qc.json"); environments.Add(netEnvironment); netEnvironment = new NetEnvironment(NetworkEnvironment.Production.ToString(), NetEnvironment.EType.Production, "host_prod", 5000, "prod.json"); environments.Add(netEnvironment); return NetworkManagerProperty.CreateInstanceWithParams(propertyName, environments, selectedEnvironment, ""); } #else private PackageProperty CreateNetworkEnvironmentProperty(string parentName, NetworkEnvironment networkEnvironment) { return CreateUnityBuildProperty(parentName, "network_dummy"); } #endif private LoggerProperty CreateLoggerPropertyFromScheme(string parentName, Scheme value) { LoggerProperty returnValue = CreateLoggerProperty(parentName, value.ToString()); if (value == Scheme.Debug) { returnValue.MinLogLevel = HtLogger.ELogLevel.Trace; } else { returnValue.MinLogLevel = HtLogger.ELogLevel.Information; } returnValue.IsAssertEnabled = value != Scheme.Release; returnValue.IsUnityLoggerEnabled = value != Scheme.Release; // Size is bigger in Development builds if (value == Scheme.Release) { // Set this variable to 0 if you want to disable logging to file in Release builds returnValue.MaxSizeFile = 512; // 0.5 Mb } else { returnValue.MaxSizeFile = 10 * 1024; // 10 Mb } return returnValue; } } }