Table of Contents

Saving & Loading


You can persist the player's explored fog state and restore it later — for save games, level transitions, or checkpoints.

Important

Saving and loading operate on the fog texture, so they require the Texture Storage fog sample mode (and therefore World Bounds).

Saving

GetFowTextureSaveData() returns a byte[] (PNG-encoded) you can write to disk.

using FOW;
using System.IO;
using UnityEngine;

byte[] data = FogOfWarWorld.instance.GetFowTextureSaveData();
File.WriteAllBytes(Path.Combine(Application.persistentDataPath, "fow.dat"), data);

Loading

LoadFowTextureData(byte[]) restores exploration from a byte array previously created with GetFowTextureSaveData().

using FOW;
using System.IO;
using UnityEngine;

string path = Path.Combine(Application.persistentDataPath, "fow.dat");
if (File.Exists(path))
{
    byte[] data = File.ReadAllBytes(path);
    FogOfWarWorld.instance.LoadFowTextureData(data);
}

Clearing

To wipe exploration back to the starting state, call ClearFowTexture().