Version: 2020.3
IMGUI 支持
Unity UI

ViewData 持久性

The ViewData API solves the problem of having a UI-specific state, not part of the data, survive domain reload and Editor restarts. The idea is to have a persistent data store on each EditorWindow. Each VisualElement has a viewDataKey that must be set to enable ViewData persistence.

用法

要为支持视图数据持久性的元素启用视图数据持久性,请将 viewDataKey 设置为 EditorWindow 中的唯一键。

只要元素具有有效的 viewDataKey,就可启用视图数据持久性。唯一的例外是一个元素位于其父级的阴影树(而不是其逻辑父级的 contentContainer 的物理子项)中的时候。在此情况下,父级必须为其阴影树中的子项设置自己的 viewDataKey 才会具有持久性。

For example, in ScrollView, each scroll bar has its own viewDataKey that is unique within the ScrollView element. When the ScrollView has no key set, the scroll bars aren’t persistent. Otherwise, the scroll bars will combine their viewDataKey with the parent viewDataKey to create a unique global key.

IMGUI 支持
Unity UI