tarsave
  • Documentation
    • Introduction
    • Installation
    • How to Use
      • DataPersistenceConfig
      • Encryption
      • Compression
      • DataPersistenceBuilder
        • SetDataPersistenceConfig
        • Build
      • DataPersistenceService
        • Save
        • SaveAsync
        • AutoSaveAsync
        • Load
        • LoadAsync
        • Delete
        • DeleteAll
      • Transform Data
      • Audio Data
  • Log
    • Change Log
      • v1.0.6
      • v1.0.5
      • v1.0.4
      • v1.0.3
      • v1.0.2
Powered by GitBook
On this page
  1. Documentation
  2. How to Use

Transform Data

Unity's Transform objects are not serializable by default, meaning they cannot be directly saved and loaded. However, Tarsave provides a solution for saving and loading Transform data through a custom TransformData class. This class stores the position, rotation, and scale of a Transform, making it compatible with Tarsave's save and load operations.

Saving Transform Data: When saving Transform data, a TransformData instance is created for each Transform. This instance is then saved using Tarsave's Save method.

public void Save()
{
    TransformData transformData = new TransformData(_transform);
    bool result = _dataPersistenceService.Save("Key", transformData);
}

Loading Transform Data: When loading, the previously saved TransformData instance is retrieved and applied to the relevant Transform object using the ApplyTransform method.

public void Load()
{
    TransformData transformData = _dataPersistenceService.Load<TransformData>("Key");
    transformData.ApplyTransform(_transform);
}

The TransformData class is specifically designed to store the position, rotation, and scale of a Transform. It also provides the ApplyTransform method to apply the stored data back to a Transform when loading.

This approach allows you to easily manage and persist Transform data in Unity, overcoming the limitations of Unity's default serialization system.

PreviousDeleteAllNextAudio Data

Last updated 6 months ago