Skip to content

Commit

Permalink
更新文档
Browse files Browse the repository at this point in the history
  • Loading branch information
pirunxi committed Aug 29, 2024
1 parent 3d08cd8 commit 61c2aa3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
8 changes: 8 additions & 0 deletions docs/beginner/monobehaviour.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ public class Print : MonoBehaviour
}
```

## 解决GameObject被裁剪的问题

由于快速上手中完全没有用到GameObject,导致GameObject类型的部分函数在打包时被裁剪。`HybridCLR/Generate/All`命令会重新扫描热更新程序集,生成link.xml以保留热更新代码中用到的类型。

请运行完该命令后**重新构建一次新包**,否则运行下一步的热更新代码时会出现`GameObject::.ctor`函数找不到的错误。


## 代码中调用AddComponent来动态挂载热更新脚本

修改 `Hello.Run`函数,添加动态挂载Print脚本的代码,最终代码如下:
Expand Down Expand Up @@ -51,3 +58,4 @@ public class Print : MonoBehaviour

对于新手来说,你只需要记住:挂载热更新脚本的资源(场景或prefab)必须打包成ab,在实例化资源前先加载热更新dll即可(这个要求是显然的!)。


Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ public class Print : MonoBehaviour
}
```

## Solve issue of GameObject being stripped

Since GameObject is not used at all in the quick start, some functions of the GameObject type are stripped when building. The `HybridCLR/Generate/All` command will rescan the hot update assembly and generate link.xml to retain the types used in the hot update code.

Please **rebuild a new package** after running this command, otherwise the error `GameObject::.ctor` function cannot be found will appear when running the next hot update code.

## Call AddComponent in the code to dynamically mount the hot update script

Modify the `Hello.Run` function and add the code to dynamically mount the Print script. The final code is as follows:
Expand Down

0 comments on commit 61c2aa3

Please sign in to comment.