Skip to content

Commit

Permalink
修复文档错误
Browse files Browse the repository at this point in the history
  • Loading branch information
pirunxi committed Jul 12, 2024
1 parent 28969f5 commit ac1c7d5
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 4 deletions.
4 changes: 3 additions & 1 deletion docs/basic/monobehaviour.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,11 @@ Unity资源管理系统在反序列化资源中的热更新脚本时,需要满

```csharp
var go = new GameObject();
// 我们不希望挂载到这个GameObject上的脚本执行
go.Active = false;
foreach (var type in hotUpdateAss.GetTypes())
{
if (type.IsAssignTo(typeof(MonoBehaviour)))
if (typeof(MonoBehaviour).IsAssignFrom(type))
{
go.AddComponent(type);
}
Expand Down
2 changes: 1 addition & 1 deletion docs/business/reload/commonerrors.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@

解决办法有几种:

- 给被序列化或者反序列化的类型加上`[Serializable]`特性,如果这些类型中成员字段的类型也是class类型`A`或者`List<A>`,则也要给`A`也加上`[Serializable]`
- 给被序列化或者反序列化的类型加上`[Serializable]`特性,如果这些类型中成员字段的类型也是class类型`A`或者`A[]`,则也要给`A`也加上`[Serializable]`
- 修改这些反序列化库的代码,在卸载程序集后,清空它们的反射缓存。像Unity的JsonUtility是native实现,无法清空缓存,只能更换为其他Json库。

2 changes: 1 addition & 1 deletion docs/business/reload/hotreloadassembly.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
- 要求重载的MonoBehaviour中的事件或消息函数如Awake、OnEable之类不发生增删(但函数体可以变化)
- 要求重载后在旧Assembly中存在同名脚本类的序列化字段名不发生变化(类型可以变)
- 如果字段类型为可卸载程序集中的自定义类型A(class或struct或enum),必须给它加上`[Serializable]`特性
- 不支持字段类型为`List<A>`其中A为可卸载的程序集中的类型,请替换为`A[]`
- 不支持字段类型为`List<A>`其中A为可卸载的程序集中的类型,请替换为`A[]`
- 不能继承泛型类型,例如`class MyScript : CommonScript<int>`
- 一些会缓存反射信息的库(这种行为在序列化相关的库中最为普遍,如LitJson),在热重载后需要清理掉缓存的反射信息
- 不支持析构函数,~XXX()。也不允许实例化泛型参数带本程序集类型的带析构函数的泛型类
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Hot reload technology is used to completely unload or reload an assembly, suitab
- Ensure that overloaded MonoBehaviour event or message functions like Awake and OnEnable are not added or removed (but the function body can change).
- Ensure that the serialized field names in the script classes with the same name in the old Assembly do not change (the types can change).
- If the field type is a custom type A (class, struct, or enum) from an unloadable Assembly, it must be marked with the `[Serializable]` attribute.
- Field types such as `List&lt;A&gt;`, where A is a type from an unloadable Assembly, are not supported; replace them with `A[]`.
- Field types such as `List<A>`, where A is a type from an unloadable Assembly, are not supported; replace them with `A[]`.
- Generic types cannot be inherited, e.g., `class MyScript : CommonScript<int>`.
- Some libraries that cache reflection information (most common in serialization-related libraries like LitJson) need to clear cached reflection information after hot reload.
- Destructors `~XXX()` are not supported. Instantiating generic classes with destructors where the generic parameter is a type from the current Assembly is also not allowed.
Expand Down

0 comments on commit ac1c7d5

Please sign in to comment.