查看开发者文档,在对应的目录下创建好了文件并且使用了样例的代码,但是在构建的时候,并没有触发。
请问是为什么?难道是需要在某个地方调用 PluginDemo 这个函数吗??按道理来说,应该是自动触发的吧。。。
// plugin.cs
using System.IO;
using UnityEngine;
using WeChatWASM;
/// <summary>
/// 构建生命周期回调钩子
/// 注意事项:
/// 请创建脚本在 Editor (子)目录下;
/// 回调钩子请使用 public 声明成员函数
/// </summary>
public class PluginDemo : LifeCycleBase
{
public override void afterCopyDefault()
{
// code...
Debug.Log("afterCopyDefault");
}
public override void beforeCopyDefault()
{
// 可使用 Exception 阻止继续构建导出
throw new System.Exception("Build Failed.");
}
public override void beforeCoverTemplate()
{
// 读取你的自定义模板目录并对其中的资源做动态修改
var tmp = BuildTemplateHelper.CustomTemplateDir;
using (
FileStream file = new FileStream(
Path.Combine(tmp, "newFile.js"),
FileMode.Create, FileAccess.Write))
{
using (StreamWriter writer = new StreamWriter(file))
{
writer.WriteLineAsync("Your Code Content.");
}
}
// 尽管你在导出期间动态的创建/修改了自定义模板中的资源
// 在导出结束后WXSDK会自动恢复你的修改
}
}
你好,我使用文档案例钩子执行正常。我使用的是 Windows10 Unity2021.3.45 PackageManager导入的最新版本WXSDK。
请提供下你的 操作系统、Unity版本、WXSDK导入方式。