| type | 类型。 |
bool 如果该类型可以在文件中持久化,则为 True,否则为 False。
返回一个布尔值,指示是否可以将类型持久化到备份文件。
只有某些类型可以持久化到备份文件,以在域重新加载和退出 Unity 时保持存续。但是,任何类型都可以存储在PropertyDatabase中,而无需备份。如果您绝对需要持久化,您可以始终将自定义对象分解成可以持久化的较小属性。
// 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.
using (var view = propertyDatabase.GetView())
{
var customTypeValue = new MyCustomType(42, "myValue");
if (view.IsPersistableType(typeof(MyCustomType)))
{
var stored = view.Store("path/to/my/asset", "m_customTypeValue", customTypeValue);
if (!stored)
Debug.LogWarning("Property m_customTypeValue did not store.");
}
else
{
var stored = view.Store("path/to/my/asset", "m_customTypeValue.value", customTypeValue.value);
if (!stored)
Debug.LogWarning("Property m_customTypeValue.value did not store.");
stored = view.Store("path/to/my/asset", "m_customTypeValue.name", customTypeValue.name);
if (!stored)
Debug.LogWarning("Property m_customTypeValue.name did not store.");
}
}
其他资源: PropertyDatabaseType.