Unity2020 common tips and settings summary

I. Introduction

I wrote an article about Unitycommonly used tips and settings before, but now Unity2020, there are some small adjustments, so let's write an article about Unity2020it.

Two, Unity common windows

1. Six Unity windows

UnityThe six main windows ( Scene、Game、Inspector、Hierarchy、Project、Console) are included in the Window - Generalmenu, and the corresponding shortcut keys can be remembered, at least Consolethe shortcut keys of the window Ctrl+Shift+C.
Insert picture description here

2. Game window resolution setting

GameClicking under the view label will pull down the resolution list. UnityThe commonly used resolutions have been built into the list, and we can also +add custom resolutions in dots .
Insert picture description here

3. Hiding the 3D icon in the Scene window

As shown below, a big 3Dicon is in the Sceneview, blocking us, Cubeand it is very eye-catching.
Insert picture description here
Just remove the check in the Scenview. But there is still a small camera . We can click the button directly to connect the camera. Will not show upGizmos3D Icons
Insert picture description here
iconGizmosicon
Insert picture description here

4. Mutual synchronization of camera and Scene window perspective

4.1. The camera angle of view is synchronized to the Scene window angle of view.
Select the camera and click the menu GameObject - Align View to Selected. At this time, the selected Scenewindow will be based on the camera angle of view
Insert picture description here

4.2. The scene window angle of view is synchronized to the camera angle of view.
Select the camera and click the menu GameObject - Align With View. At this time, the selected camera will be based on the Scenewindow angle of view
Insert picture description here

5. Putting away and unfolding the Inspector component

Collapse All ComponentsCollapse All Component
Expand All ComponentsExpand AllComponent
Insert picture description here

6. Collapse and expand the tree nodes of the Hierarchy window

Select a node, press to Alt+向左collapse all nodes, and press to Alt+向右expand all nodes.
Insert picture description here

7, Project window filtering

Filter according to file type to facilitate quick file search
Insert picture description here

8. Console log window

Insert picture description here
There are several buttons in the window
Collapse: store log, it will store the same output
Clear on Play: Unitywhen running, it will clean up the log
Error Pause: when there is Erroroutput, Unitystop running
=Often planning or artists accidentally clicked Error Pause when using Unity, and then an Error log appeared when running, Unity halted the operation, and then shouted in surprise: "Ah, my unity is stuck"

9, PackageManager window

Unity 2018.1The version began to introduce the package manager Package Managerwindow, which Window - Package Managercan be opened
Insert picture description here
by clicking the menu Package Manager. We can install, remove or update Unitymany great plugin packages, such as Shader Graph、Timeline、ProBuilder、Android Logcatetc.
Insert picture description here
If one of the searched plug-in packages cannot be found, first make sure that the filter is selected hereUnity Registry
Insert picture description here

10. Player Settings window

Many packaging-related settings are in the Player Settingswindow, and many settings mentioned below are related to this window.
Click on the menu: File - Build Settingsopen the Build Settingswindow,
Insert picture description here
and then click Player Settings,
Insert picture description here
you can open the Player Settingswindow, in fact, it is the Project Settingswindow Playertab window
Insert picture description here

Three, Player Settings window commonly used settings

1. Set the game name

You Product Namecan fill in the name of the game on the right and
Insert picture description here
set it by code:

UnityEditor.PlayerSettings.productName = "testgame";

2. Set the Bundle ID

Open the Other Settingsdrop-down page, and Package Namefill in the package name ( Bundle ID) on the right . The general format is com.公司名.游戏名
Insert picture description here
code setting:

// Unity5.x之前
UnityEditor.PlayerSettings.bundleIdentifie = "com.linxinfa.mygame";
// Unity2017以后
UnityEditor.PlayerSettings.applicationIdentifier = "com.linxinfa.mygame";

3. Set the version number

Open the Other Settingsdrop-down page, Version*and Bundle Version Codeyou can fill in the version number on the and right side. It is
Insert picture description here
recommended to use the code to set:

	UnityEditor.PlayerSettings.bundleVersion = "1.0.0";
#if UNITY_ANDROID
	UnityEditor.PlayerSettings.Android.bundleVersionCode = 1;
#elif UNITY_IOS
	UnityEditor.PlayerSettings.iOS.buildNumber = "1";
#endif

For the difference between Bundle Identifier, Bundle Version, and Bundle Version Code, please refer to my article: https://linxinfa.blog.csdn.net/article/details/87693138

3. Set the game icon

Open the Icondrop-down page to set the game icon
Insert picture description here
code mode setting:

PlayerSettings.SetIconsForTargetGroup(BuildTargetGroup platform,Texture2D[] icons);

Pay attention to the second parameter icons array, Android must pass6 icons, IOS must pass15 icons, Otherwise the interface call is invalid.
Unity uses code to set the game icon, you can refer to my blog: https://blog.csdn.net/linxinfa/article/details/84248474

4. HD game icon compression format setting

See my blog:
Unity game icon compression format settings (to solve the problem of unclear icons): https://blog.csdn.net/linxinfa/article/details/84140334

5. Set the splash screen

Open the Splash Imagedrop-down page to set the game splash screen.
Insert picture description here
UnityUse the code to set the Splash Screen splash screen. Please refer to my blog: https://blog.csdn.net/linxinfa/article/details/87694417

6. Horizontal and vertical screen settings

Open the Resolution and Pressentationdrop-down page, on the Default Orientation*right, you can select the default horizontal and vertical screens.
Insert picture description here
Code mode settings:

Screen.orientation = ScreenOrientation.LandscapeRight;

7. Set the macro definition

Open the Other Settingspull-down page, Scripting Define Symbolsyou can set the macro definition, a plurality of macro separated by semicolons
Insert picture description here

#if MY_DEFINE1
        Debug.Log("Hello MY_DEFINE1");
#endif
#if MY_DEFINE2
        Debug.Log("Hello MY_DEFINE2");
#endif

8. Platform CPU type setting

Open the Other Settingspull-down page, Target Architecturesyou can check the publishing platform supported under CPUthe type of
Insert picture description here
image above ARM64can not be checked because the Scripting Backenduse is Mono, if you want to support ARM64, you Scripting Backendmust selectIL2CPP
Insert picture description here

9. Set up multi-threaded rendering

Open the Other Settingsdrop-down page, check it Multithread Renderingto support multi-threaded rendering
Insert picture description here

About multi-threaded rendering: https://zhuanlan.zhihu.com/p/44116722

10. Set the lock frame rate

Then click on the Qualitypage to VSync Countset it to Don't Sync. If it is not set Don't Sync, the frame rate locked in the code will not take effect.
Insert picture description here
Then set the frame rate in the code:

Application.targetFrameRate = 30;

11. Set a fixed time step (physical update)

Click on the Timepage Fixed Timestepto set the fixed time step
Insert picture description here
for physics update on the right. For a stable physics simulation, a fixed time step ( fixed time stepping) is very important, and the physical calculation must be performed independently of the frame rate of the game. rigidbodyPhysical calculations such as collision detection and rigid body ( ) movement are performed in discrete fixed time steps independent of the frame rate.
Code setting:

Time.fixedDeltaTime = 0.02f;

12. Set the physical collision of the layer

Click on Physicsthe page, in Layer Collision Matrixthe collision can be checked between different physical layers, for the layer need not be calculated physical impact, can be removed to improve performance.
Insert picture description here

13, set up the Layer layer

Click on the Tags and Layerspage to open the Layersdrop-down page to edit and add new Layerlayers
Insert picture description here

14. Set Tags

Click on the Tags and Layerspage to open the Tagsdrop-down page to edit and add newTags
Insert picture description here

15. Set engine code clipping

This is only available in the Apple version Unity.
In Player Settingsthe Other Settingsdrop-down page of the window , there is one Strip Engine Code. After checking it, the code will be tailored when packaging, and the unused code will not be packaged. For example, if a 2Dgame does not use Rigidbodyother physical components, then the Rigidbodyrelevant code of the engine will be It is cut out to reduce the package body.
Insert picture description here
However, this feature should be used with caution, because I've run
into trouble , you can refer to my previous blog: "Unity loads resource instantiation through AssetBundle to solve the problem of crashing on iOS (caused by Strip)": https://blog.csdn. net/linxinfa/article/details/79757492

Four, other settings

1. Save file prompt settings

Open Preferenceswindow, menu:, Edit - Preferencesopen Generalpage, checkVerify Saving Assets
Insert picture description here

In this way, when Unityyou press ctrl+ssave in the editor, a query box will pop up to ask whether you want to save the modified file.
We can selectively save
Insert picture description here

2. Download and configure Android Build Support

Recommended to Unity HubinstallAndroid Build Support
Insert picture description here

3. Set up JDK, Android SDK, NDK, Gradle

Through the Unity Hubinstallation Android Build Support, the downloads are JDK、Android SDK、NDK、Gradleall in the directory in the following figure: Unity安装目录\Editor\Data\PlaybackEngines\AndroidPlayer
Insert picture description here
click the menu Edit - Preferences..., open the Preferenceswindow, select the External Toolspage, you can set JDK、Android SDK、NDK、Gradle, and the default is to tick.
Insert picture description here

Five, the code is commonly used

1. Frame rate FPS

var fps = 1.0f / Time.smoothDeltaTime();

2. Debug.Log outputs log with color

Debug.Log(string.Format("<color=#ff0000>{0}</color>", "hello world"));
Debug.Log(string.Format("<color=yellow>{0}</color>", "welcome to unity"));

Insert picture description here
Hexadecimal color code table
https://www.sioe.cn/yingyong/yanse-rgb-16/

3. Capture Unity log and upload to the server

See my blog: https://linxinfa.blog.csdn.net/article/details/107221307

4. Screenshot function

See my blog: https://linxinfa.blog.csdn.net/article/details/49493775

5. Unity file operation path

See my blog: https://linxinfa.blog.csdn.net/article/details/51679528

Guess you like

Origin blog.csdn.net/linxinfa/article/details/108664568