这篇文章主要介绍Unity3D中打包的示例分析,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!
在Unity3D中打包,其过程是可以监听到事件的.例如打包开始,及打包结束,编译shader等.
在编辑器中实现IPreprocessBuild接口,以下是官方例子:
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);
}
}
在编辑器中添加监听 PostProcessBuildAttribute
using UnityEngine;
using UnityEditor;
using UnityEditor.Callbacks;
public class MyBuildPostprocessor {
[PostProcessBuildAttribute(1)]
public static void OnPostprocessBuild(BuildTarget target, string pathToBuiltProject) {
Debug.Log( pathToBuiltProject );
}
}
编译shader前
在编辑器中实现IPreprocessShaders接口
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<ShaderCompilerData> data)
{
for (int i = data.Count - 1; i >= 0; --i)
{
if (!data[i].shaderKeywordSet.IsEnabled(m_Blue))
continue;
data.RemoveAt(i);
}
}
}
在编辑器里实现IProcessScene接口
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);
}
}
在编辑器里实现IActiveBuildTargetChanged接口
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);
}
}
有了这些事件,就可以很方便的在打包前后加入自己的个性化需求了
例如在打包前要删除掉一部分AB包里面所包含的测试场景,测试资源等.
以上是“Unity3D中打包的示例分析”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注亿速云行业资讯频道!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。