Implement Own Expansion of Saved Data


Overview

This page describes how to add your own expanded data to Utage’s save/load functionality.
To customize the save/load operation, all you need to do is follow these two steps:
・Create a component using the IAdvCustomSaveDataIO interface, and write the save/load processing logic inside it.
・Register the object containing that component in AdvEngine>SaveManager>CustomSaveDataObjects.

You can save the data from your own game using Utage’s functionality, as well as your own expansions by using in conjunction the methods for calling programs, such as SendMessage or SendMessageByName.

Sample

This sample handles the ‘Advertisement Display Flag’ from Utage’s scenario data and and also reflects it in the saved data.

Create a Component Using the IAdvCustomSaveDataIO Interface

The components for saving/loading need to use the IAdvCustomSaveDataIO interface.
IAdvCustomSaveDataIO Interface

Below is a sample component that implements the IAdvCustomSaveDataIO interface.

using UnityEngine;
using Utage;
using System.Collections;

/// <summary>
/// ADV用SendMessageByNameコマンドから送られたメッセージを受け取る処理のサンプル
/// </summary>
[AddComponentMenu("Utage/ADV/Examples/SendMessageByName")]
public class SampleSendMessageByName : MonoBehaviour, IAdvCustomSaveDataIO
{
    //広告のオンオフフラグなど
    public bool isAdOpen = false;
    //シナリオからコマンドを呼んで切り替える
    void SetEnableAdvertise(AdvCommandSendMessageByName command)
    {
        this.isAdOpen = command.ParseCellOptional<bool>(AdvColumnName.Arg3, false);
    }


    //セーブに使うキーは他のカスタムセーブデータを被らないように
    public string SaveKey { get { return "SampleSendMessageByName"; } }

    //クリアする
    public void OnClear()
    {
        this.isAdOpen = false;
    }

    //バージョンチェックしたほうが安全
    const int Version = 0;

    //書き込み
    public void OnWrite(System.IO.BinaryWriter writer)
    {
        writer.Write(Version);
        writer.Write(this.isAdOpen);
    }

    //読み込み
    public void OnRead(System.IO.BinaryReader reader)
    {
        //バージョンチェック
        int version = reader.ReadInt32();
        if (version == Version)
        {
            this.isAdOpen = reader.ReadBoolean();
        }
        else
        {
            Debug.LogError(LanguageErrorMsg.LocalizeTextFormat(ErrorMsg.UnknownVersion, version));
        }
    }
}


Create an Object that Uses a Component

Create a new component and then add the newly created component.

Register Object in SaveManager

Register the newly created component in AdvEngine>SaveManager>CustomSaveDataObjects.

Operate Object from Scenario

Use the SendMessgaeByName Command, etc. to operate the object from a scenario.

Verify Save/Load

Verify that save/load operations have been executed correctly.

Save Timing

Utage’s save functionality saves each page’s beginning status automatically in the background every time a page is changed.
Please take care as the timing of this functionality is not based on the press of a Save button.
The reason for this is that after loading files, pages need to be reopened from the beginning.

Related Information