Version: 2022.2
言語: 日本語
public static bool IsPersistableType (Type type);

パラメーター

type A type.

戻り値

bool True if the type can be persisted in the file, false otherwise.

説明

Returns a boolean indicating if a type can be persisted into the backing file.

Only certain types can be persisted in the backing file to survive a domain reload and quitting Unity. However, any type can be stored without backing in the PropertyDatabase. You can always decompose your custom objects into smaller properties that can be persisted if you absolutely need persistence.

// Any object can be stored in the property database, but only
// some of them will be persisted in the database file. All others
// will disappear after the current Unity session. If you absolutely need your
// data to be persisted, you can decompose your it into smaller properties that can
// be serialized.
var customTypeValue = new MyCustomType(42, "myValue");
if (PropertyDatabase.IsPersistableType(typeof(MyCustomType)))
{
    stored = propertyDatabase.Store("path/to/my/asset", "m_customTypeValue", customTypeValue);
    if (!stored)
        Debug.LogWarning("Property m_customTypeValue did not store.");
}
else
{
    stored = propertyDatabase.Store("path/to/my/asset", "m_customTypeValue.value", customTypeValue.value);
    if (!stored)
        Debug.LogWarning("Property m_customTypeValue.value did not store.");
    stored = propertyDatabase.Store("path/to/my/asset", "m_customTypeValue.name", customTypeValue.name);
    if (!stored)
        Debug.LogWarning("Property m_customTypeValue.name did not store.");
}
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961