本文整理汇总了Java中com.google.android.gms.games.snapshot.SnapshotMetadataChange.Builder方法的典型用法代码示例。如果您正苦于以下问题:Java SnapshotMetadataChange.Builder方法的具体用法?Java SnapshotMetadataChange.Builder怎么用?Java SnapshotMetadataChange.Builder使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.android.gms.games.snapshot.SnapshotMetadataChange
的用法示例。
在下文中一共展示了SnapshotMetadataChange.Builder方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: saveGameStateSync
import com.google.android.gms.games.snapshot.SnapshotMetadataChange; //导入方法依赖的package包/类
@NonNull
public Boolean saveGameStateSync(String id, byte[] gameState, long progressValue,
ISaveGameStateResponseListener listener) {
if (!isSessionActive()) {
if (listener != null)
listener.onGameStateSaved(false, "NOT_CONNECTED");
return false;
}
// Open the snapshot, creating if necessary
Snapshots.OpenSnapshotResult open = Games.Snapshots.open(
mGoogleApiClient, id, true).await();
Snapshot snapshot = processSnapshotOpenResult(open, 0);
if (snapshot == null) {
Gdx.app.log(GAMESERVICE_ID, "Could not open Snapshot.");
if (listener != null)
listener.onGameStateSaved(false, "Could not open Snapshot.");
return false;
}
if (progressValue < snapshot.getMetadata().getProgressValue()) {
Gdx.app.error(GAMESERVICE_ID, "Progress of saved game state higher than current one. Did not save.");
if (listener != null)
listener.onGameStateSaved(true, null);
return false;
}
// Write the new data to the snapshot
snapshot.getSnapshotContents().writeBytes(gameState);
// Change metadata
SnapshotMetadataChange.Builder metaDataBuilder = new SnapshotMetadataChange.Builder()
.fromMetadata(snapshot.getMetadata());
metaDataBuilder = setSaveGameMetaData(metaDataBuilder, id, gameState, progressValue);
SnapshotMetadataChange metadataChange = metaDataBuilder.build();
Snapshots.CommitSnapshotResult commit = Games.Snapshots.commitAndClose(
mGoogleApiClient, snapshot, metadataChange).await();
if (!commit.getStatus().isSuccess()) {
Gdx.app.log(GAMESERVICE_ID, "Failed to commit Snapshot:" + commit.getStatus().getStatusMessage());
if (listener != null)
listener.onGameStateSaved(false, commit.getStatus().getStatusMessage());
return false;
}
// No failures
Gdx.app.log(GAMESERVICE_ID, "Successfully saved gamestate with " + gameState.length + "B");
if (listener != null)
listener.onGameStateSaved(true, null);
return true;
}
示例2: setSaveGameMetaData
import com.google.android.gms.games.snapshot.SnapshotMetadataChange; //导入方法依赖的package包/类
/**
* override this method if you need to set some meta data, for example the description which is displayed
* in the Play Games app
*
* @param metaDataBuilder builder for savegame metadata
* @param id snapshot id
* @param gameState gamestate data
* @param progressValue gamestate progress value
* @return changed meta data builder
*/
protected SnapshotMetadataChange.Builder setSaveGameMetaData(SnapshotMetadataChange.Builder metaDataBuilder,
String id, byte[] gameState, long progressValue) {
return metaDataBuilder.setProgressValue(progressValue);
}