Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Sample Analysis of Packaging in Unity3D

Shulou Source: shulou.com Published: 2022-06-01 18:01:38 09月25日 Update

This article mainly introduces the example analysis packaged in Unity3D, which is very detailed and has certain reference value. Friends who are interested must finish it!

When packaged in Unity3D, events can be monitored during the process. For example, the beginning of packaging, and the end of packaging, compiling shader and so on.

Start packing.

Implement the IPreprocessBuild interface in the editor. The following is an official example:

Using UnityEditor;using UnityEditor.Build;using UnityEngine

Class MyCustomBuildProcessor: IPreprocessBuild {public int callbackOrder {get {return 0;}} public void OnPreprocessBuild (BuildTarget target, string path) {Debug.Log ("MyCustomBuildProcessor.OnPreprocessBuild for target" + target + "at path" + path);} end of packing

Add a listening PostProcessBuildAttribute to the editor

Using UnityEngine;using UnityEditor;using UnityEditor.Callbacks

Public class MyBuildPostprocessor {[PostProcessBuildAttribute (1)] public static void OnPostprocessBuild (BuildTarget target, string pathToBuiltProject) {Debug.Log (pathToBuiltProject);}

} before compiling shader

Implement IPreprocessShaders interface in editor

Using System.Collections.Generic;using UnityEditor.Build;using UnityEditor.Rendering;using UnityEngine;using UnityEngine.Rendering

Class MyCustomBuildProcessor: IPreprocessShaders {ShaderKeyword m_Blue

Public MyCustomBuildProcessor () {m_Blue = new ShaderKeyword ("_ BLUE");}

Public int callbackOrder {get {return 0;}}

Public void OnProcessShader (Shader shader, ShaderSnippetData snippet, IList data) {for (int I = data.Count-1; I > = 0;-- I) {if (! data [I] .shaderKeywordSet.IsEnabled (m_Blue)) continue

Data.RemoveAt (I);} Packaging scenario

Implement IProcessScene interface in editor

Using UnityEditor;using UnityEditor.Build;using UnityEngine

Class MyCustomBuildProcessor: IProcessScene {public int callbackOrder {get {return 0;}} public void OnProcessScene (UnityEngine.SceneManagement.Scene scene) {Debug.Log ("MyCustomBuildProcessor.OnProcessScene" + scene.name);}}

Switching platform

Implement IActiveBuildTargetChanged interface in editor

Using UnityEngine;using UnityEditor;using UnityEditor.Build

Public class ActiveBuildTargetListener: IActiveBuildTargetChanged {public int callbackOrder {get {return 0;}} public void OnActiveBuildTargetChanged (BuildTarget previousTarget, BuildTarget newTarget) {Debug.Log ("Switched build target to" + newTarget);}}

With these events, you can easily add your own personalized needs before and after packaging.

For example, delete some test scenarios and test resources contained in the AB package before packaging.

The above is all the content of the article "sample Analysis packaged in Unity3D". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Tags: Editors interfaces examples analysis events content scenarios articles reality testing compilation personality value examples interests official guys partners platforms more Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Microsoft Xiaomi MySQL NVidia