SaveToString

Summary: Convert data to save text for storage you manage.

Description

Convert data to save text for storage you manage.

Declaration

C#
public static SaveResult SaveToString<T>(T data, out string text, SaveOptions options = null);

Parameters

ParameterTypeDescription
T—Type of the data to convert.
dataTThe data to convert.
textout stringThe resulting text, or null if the conversion failed.
optionsSaveOptionsOptional. Protection and compression settings. Null uses the defaults.

Returns

A SaveResult for the conversion. Check IsSuccess on the result.

Example

Create LogPositionSaveText.cs and attach it to an active GameObject. Enter Play mode to produce save text from the GameObject’s position. Copy just the save text from the Console to try the LoadFromString example.

C#
using Gley.SaveSystem;
using UnityEngine;

public class LogPositionSaveText : MonoBehaviour
{
    private void Start()
    {
        SaveResult result = API.SaveToString(transform.position, out string text);

        if (result.IsSuccess)
        {
            Debug.Log(text, this);
        }
        else
        {
            Debug.LogWarning($"Conversion failed ({result.Status}): {result.Message}", this);
        }
    }
}
On This Page