Unity general packaging process
Usually the packaging process is mainly Building setting
to select the scene that needs to be packaged and then export the package to the specified folder location. You can also [MenuItem("MyMenu/Do Something")]
use the static function in to select the packaging path and packaging method - you need to place the script under Editor
the folder
[MenuItem("Test/BuildAndroid")]
public static void BuildAndroid() {
string path = Path.GetFullPath("D:\\Packages") + "/Backbag" + ".apk";
BuildPipeline.BuildPlayer(GetBuildScence(), path, BuildTarget.Android, BuildOptions.None);
}
command line control
- Launching Unity
- First we need to
Unity.exe
execute in the directory where - Select the corresponding Option
command statement explanation
command statement | explain |
---|---|
-batchmode | Run Unity in batch mode. In batch mode, Unity runs command line arguments without human intervention. It also suppresses some popup windows (such as the Save Scene window); however, the Unity editor itself opens as usual. You should always run Unity in batch mode when using command line arguments, as it allows automation to run uninterrupted |
-quit | The Unity editor will exit after the other commands have finished executing. But it will cause the error message to be hidden (shown in Editor.log file) |
-executeMethod <ClassName.MethodName> | Static methods are executed immediately after Unity opens the project, and after optional asset server updates are complete. The script where the method is executed must be in the Editor file and must be static. To return an error from the command line process, either throw an exception causing Unity to exit with code 1, or call EditorApplication.Exit and return a non-zero code |
In addition, some parameters can also be executed in the Unity Standalone Player platform (official documents refer to Mac, Windows and Linux)
To start in batch mode from the command line enterPATH_TO_STANDALONE_BUILD -projectPath PROJECT_PATH -batchMode
for exampleC:\projects\myproject\builds\myproject.exe
-batchMode
command statement | explain |
---|---|
-batchmode | Run the game in "headless" mode. The game will not display anything, or accept user input. Servers mainly used for online games |
-single-instance (Linux and Windows only) | Only one game instance is allowed to run at a time. If another instance is already running, then start it again with -single-instance will adjust to the existing instance |
-force-(…) | Mandatory use of specified rendering methods (DirectX, Metal, OpenGL, etc.) |
-screen-(…) | Re-specify the size of the screen or the way it appears (pop-up window or full screen) |
Player Setting——PC
Player Settings provides various options to help you complete the final game package. Although there are many different platforms, the general settings will be divided into the following parts
Icon
icon, the default icon displayed on the desktop
Resolution and Presentation
Resolution and pre-start window settings, including options such as supported resolution ratios and whether to start full screen by default;
Resolution
- Fullscreen Mode: Select the default window mode
- Default Is Native Resolution : The game starts with the default resolution, and the resolution of the game can be forced after unchecking it. But one thing, if your game has already been packaged and started, it is meaningless to package and force the resolution next time, because Windows will record the final resolution of the application in the registry. At this point there are three solutions:
- 1. Change the name or company of the application;
- 2. Directly control the resolution in the code;
- 3. Use Unity's built-in pre-start resolution to set the small window.
- Mac Retina Support: It can make the game display more clearly on the Mac screen with high DPI, but it may take up more resources;
- Run in background : When the game loses focus, it will continue to run without pausing. Networked games must be checked;
Standalone Player Options
This section allows specifying how the user can customize the screen. For example, it can be determined here whether the user can resize the screen and how many instances can run concurrently.
- Capture Single Screen: Enabling this option ensures that standalone games in full screen mode will not dim secondary monitors in multi-monitor setups.
- Use Player Log : Input all Debug.Log information into a log file, checked by default
- Resizable Window: Allows the player to resize the game window;
- Visible in Background: It can still be displayed normally even in the background
- Force Single Instance : A host can only be run by one instance
- Supported Aspect Ratios: Supported aspect ratios
Splash Image
splash image, setting allows specifying a splash image for a standalone platform
Other Setting
Rendering
- **Color Space: **Color space, very important option, only Gamma can be selected on mobile phones, and the general 3A masterpieces are Linear, and the linear display effect is more realistic
- Auto Graphics API for Windows/ Mac/ Linux: Automatically select the best graphics API, if not checked, you can add the supported graphics API by yourself
- Static Batching : Static batching. - Combine static (non-moving) game objects into large meshes and render them in a faster way
- Dynamic Batching : Dynamic batch processing, automated Unity process, batch rendering of multiple networks at one time to optimize graphics performance, this technology converts all GameObject vertices on the CPU and combines many similar vertices together. (Dynamic batching has no effect when the programmable rendering pipeline is active)
- GPU Skinning / Compute Skinning : use GPU to deal with the process of bone and skin connection, release CPU resources
- Graphics Jobs : Allows the game to hand over some rendering tasks to other CPU cores for processing, increasing the processing efficiency of the game
- Frame Timing Stats: Frame timing status. Enable this property to collect CPU and GPU frame time statistics. Use this with the dynamic resolution camera setting to determine if your application is CPU or GPU bound.
Configuration
- Scripting Backend : Select the way to compile and execute C# code in the project. Unity supports three different scripting backends depending on the target platform: Mono, .NET, and IL2CPP. Universal Windows Platform supports only two: .NET and IL2CPP.
- Mono : Compiles C# code into .NET Common Intermediate Language (CIL) and executes that CIL using the common language runtime
- IL2CPP : Compile C# code to CIL, convert CIL to C++, and then compile C++ to native code for direct execution at runtime.
- API Compatibility Level : Select the .NET API used in the project. This setting affects the compatibility of third-party libraries.
- Use incremental GC: Uses an incremental garbage collector, which spreads garbage collection over multiple frames to reduce GC-related spikes in frame duration.
Script Compilation
- Allow 'unsafe' Code: Enables support for compiling "unsafe" C# code in a predefined assembly (for example, Assembly-CSharp.dll).
- Use Deterministic Compilation : Disable this setting to prevent compilation with the -deterministic C# flag. When this setting is enabled, compiled assemblies are byte-for-byte identical each time they are compiled.
and some options related to Roslyn Analyzers, which can statically analyze code and detect potential bugs, vulnerabilities and optimization opportunities in the code
Scripting Define Symbols
The flag setting when the script is compiled can include or exclude some codes during the compilation phase according to the definition. Sample code:
#if UNITY_STANDALONE_WIN
Debug.Log("Standalone Windows");
#endif
Platform scripting symbols : (Platform ID)
definition | meaning |
---|---|
UNITY_EDITOR | Used to call the symbols under the Editor from the game script |
UNITY_EDITOR_XXX | Compile/execute code in Editor on XXX platform |
UNITY_STANDALONE | Code compiled/executed in an application on any standalone platform (Mac OS X, Windows or Linux) |
UNITY_STANDALONE_XXX | Code compiled/executed in apps on XXX platform |
UNITY_XXX | Compiled/executed code on XXX platforms (except stand-alone) |
Editor version Scripting symbols : (engine version identification)
You can choose the unity version number, which can be specific to any version of X_Y_Z
UNITY_2019 | Unity2019 version, including all versions such as 2019.YZ |
---|---|
UNITY_2019_4 | Unity2019.4 version, including all versions such as 2019.4.Z |
UNITY_2019_4_14 | Unity2019.4.14 version |
Rest of the logos :
definition | meaning |
---|---|
CSHARP_7_3_OR_NEWER | Support C# 7.3 and above |
ENABLE_MONO | The compilation method is Mono. |
ENABLE_IL2CPP | The S compilation method is IL2CPP . |
NET_X_Y | Generate scripts for API compatibility of Net corresponding versions on Mono and IL2CPP |
UNITY_SERVER | Check the Server Build option in Build Setting |
Optimization
- Prebake Collision Meshes : Only add collision boxes when building the game;
- Keep Loaded Shaders Alive: Ensure that the Shader will not be uninstalled;
- Preloader Assets : list of Assets pre-read;
- Managed Stripping Level : Determines the degree to which Unity strips unused managed code. This makes the resulting executable smaller, but may lead to incorrect removal of code that actually uses
- Vertex Compression : Vertex compression, select the data that the model will compress, for example, you can select everything, and then remove positions and lightmap UVs. Of course, when each model is imported, this parameter can be set independently, and this option will be overwritten
- Optimize Mesh Data: Optimize Mesh data. Checking this option will remove Mesh data that is not required by the material, such as tangents, normals, colors, and UV.
Logging
You can choose when to run the script (ScriptOnly), whenever (Full), or never (None)
Player Setting——Android
Most of the comparisons are similar, only the important differences are introduced
Resolution and Presentation
Orientation
Orientation, to customize settings related to the orientation of the application on the device.
Setting | Description |
---|---|
Portrait | Portrait, bottom aligned to top of device |
Portrait Upside Down | Portrait, bottom aligned to device bottom |
Landscape Right | Landscape, left aligned to top of device |
Landscape Left | Landscape, right aligned to top of device |
Auto Rotation | The screen can be rotated to any orientation you specify in the "Allowed Orientations for Auto Rotation" section. |
Other Setting
Identification
Property | Function |
---|---|
Override Default Package Name | Indicates whether to replace the default package name of the application - also affects macOS, IOS and Android |
Package Name | Set the Application ID, which uniquely identifies your application on the device and in the Google Play Store. Application IDs must follow the convention com.YourCompanyName.YourProductName and must contain only alphanumeric and underscore characters. Each segment must begin with an alphabetic character. |
Version | Enter the build version number of the bundle, which identifies the iterative (released or unreleased) version of the bundle, specified in the common format of a string containing numbers separated by dots (for example, 4.3.2) (shared by iOS and Android) |
Bundle Version Code | The internal version number is only used to compare which version is newer (a larger number means the latest), and it is not displayed to the user. It can be seen that xy is converted to an integer or simply incremented by 1 for each release |