Persistable (interface)¶
バージョン 1.13.0 で追加.
The Persistable is an interface that objects can support if they wish to provide custom persistence within Splice. The Splice plugins call methods on objects supporting the Persistable interface. The data is included into the Host DCC scene file.
注釈
For nested data types, the root object must invoke the save and load methods on any members that must also save thier data.
Example¶
A custom object can save its data to the host application’s scene file by supporting the Persistable interface.
require FileIO;
require JSON;
require FabricInterfaces;
// MyObject supports custom persistence in the Splice application.
object MyObject : Persistable {
String name;
String filePath;
};
function MyObject() {
}
// The scene file is being saved, and the KL object can save its own data to the scene file.
function String MyObject.saveDataToString(PersistenceContext context) {
JSONDoc doc();
doc.root.setString("name", this.name);
doc.root.setString("filePath", filePath.string());
String json = doc.write();
return json;
}
// The scene file has been loaded and now the KL obect can load its custom data.
function MyObject.loadDataFromString!(PersistenceContext context, String data) {
JSONDoc doc();
if(doc.parse(data)){
if(doc.root.has("name")){
this.name = doc.root.getString("name");
}
if(doc.root.has("filePath")){
FilePath filePath(doc.root.getString("filePath"));
if(filePath.exists()){
// Read the external data file.
}
}
}
else{
setError("ERROR Loading MyObject. Saved JSON data is not valid");
}
}
Functions¶
loadDataFromString ! ( in PersistenceContext context, in String data ) | |
String | saveDataToString ? ( in PersistenceContext context ) |
Functions in detail¶
Persistable.loadDataFromString! ( in PersistenceContext context, in String data )
a callback invoked by Splice when an object loaded back within Splice
String Persistable.saveDataToString? ( in PersistenceContext context )
a callback invoked by Splice when an object is persisted