In Unity's cross-platform, we often roam across platforms, such as Android, Apple, andpc. On different platforms, we have to do different things. However, we can use Unity's own macro definition to make platform judgments. Unity helps us define, for example, the following platform preprocessing. (There are also macro definitions of version numbers, which are not written here.) )
We use #if #elif #endif进行宏命令的判断,unity determines which conditions are true and then executes the specified code. Examples are as follows:
In addition, we can also define the macro command ourselves: In the edit-project Settings-player, you can add your own macro definition to the settings bar. If you add the macro definition to the platform, you will be judged to execute the code under the Macro command. The other platforms do not have the corresponding macro commands defined, and the code is not executed.
Pre-processing of the Unity platform (definition of macros)