Skip to main content

EditorPrefsSaver

Important Attention Reminder

Coding Style wiki​


EditorPrefsSaver is the built-in editor saver of the SaverSystem (inherits Saver). It uses UnityEditor.EditorPrefs as the storage backend and is suited for storing editor tool preferences (EditorWindow, custom Inspectors, etc.); the base class text-content data feature (Data Map) is available directly.

NamespaceOxGKit.SaverSystem.Editor
Typepublic class EditorPrefsSaver : Saver
SourceEditorPrefsSaver.cs
using OxGKit.SaverSystem;
using OxGKit.SaverSystem.Editor;

Important EditorPrefsSaver lives in the Editor Assembly (OxGKit.SaverSystem.Editor) and can only be referenced from editor scripts (Editor folders or Editor asmdefs) — never from runtime scripts (builds would fail to compile).

Quick Start​

using OxGKit.SaverSystem;
using OxGKit.SaverSystem.Editor;

// Create a saver in an editor tool (EditorPrefs backend)
Saver editorSaver = new EditorPrefsSaver();

// Store editor tool preferences
editorSaver.SaveString("MyProject.MyTool.lastExportPath", "Assets/Exports");
string path = editorSaver.GetString("MyProject.MyTool.lastExportPath", "");

General Rules​

Scope​

SaverStorage BackendScope
PlayerPrefsSaverUnityEngine.PlayerPrefsRuntime (in-game settings, stored per application/platform)
EditorPrefsSaverUnityEditor.EditorPrefsEditor only (editor tool preferences)

(See the Module Intro for an overview)

Storage Scope and Write Timing​

Attention EditorPrefs is user-level storage, shared by ALL Unity projects on the same machine — prefix keys with a project or tool name (e.g., MyProject.MyTool.someKey) to avoid collisions.

Reminder Unlike PlayerPrefsSaver, EditorPrefs is persisted automatically by the editor — there is no (and no need for a) Save() call.


Overridden Members​

Method Overview​

MethodDescription
SaveStringSaves a string.
GetStringGets a string.
SaveIntSaves an int.
GetIntGets an int.
SaveFloatSaves a float.
GetFloatGets a float.
HasKeyChecks whether a key exists.
DeleteKeyDeletes a key.
DeleteAllDeletes all EditorPrefs keys.

SaveString​

public override void SaveString(string key, string value)

Saves a string via EditorPrefs.SetString.

editorSaver.SaveString("MyProject.MyTool.lastExportPath", "Assets/Exports");

GetString​

public override string GetString(string key, string defaultValue = "")

Gets a string via EditorPrefs.GetString; returns defaultValue when the key does not exist.

SaveInt​

public override void SaveInt(string key, int value)

Saves an int via EditorPrefs.SetInt.

GetInt​

public override int GetInt(string key, int defaultValue = 0)

Gets an int via EditorPrefs.GetInt; returns defaultValue when the key does not exist.

SaveFloat​

public override void SaveFloat(string key, float value)

Saves a float via EditorPrefs.SetFloat.

GetFloat​

public override float GetFloat(string key, float defaultValue = 0f)

Gets a float via EditorPrefs.GetFloat; returns defaultValue when the key does not exist.

HasKey​

public override bool HasKey(string key)

Checks whether the specified key exists via EditorPrefs.HasKey.

DeleteKey​

public override void DeleteKey(string key)

Deletes the specified key via EditorPrefs.DeleteKey.

DeleteAll​

public override void DeleteAll()

Deletes keys via EditorPrefs.DeleteAll.

Important EditorPrefs.DeleteAll deletes ALL user-level editor preferences of the whole machine (including settings of Unity itself and other tools) — strongly discouraged in normal situations.