Skip to content

Instantly share code, notes, and snippets.

@CapitanLiteral
Last active January 22, 2020 11:38
Show Gist options
  • Save CapitanLiteral/f7291cb8036161233383655bfec3e522 to your computer and use it in GitHub Desktop.
Save CapitanLiteral/f7291cb8036161233383655bfec3e522 to your computer and use it in GitHub Desktop.
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
public static class EditorWindowExtensions
{
public static string Save(this EditorWindow window)
{
var data = JsonUtility.ToJson(window, false);
EditorPrefs.SetString(window.GetType().ToString(), data);
return data;
}
public static string Load(this EditorWindow window)
{
var data = EditorPrefs.GetString(window.GetType().ToString(), JsonUtility.ToJson(window, false));
JsonUtility.FromJsonOverwrite(data, window);
return data;
}
public static string Save(this Editor window)
{
var data = JsonUtility.ToJson(window, false);
EditorPrefs.SetString(window.GetType().ToString(), data);
return data;
}
public static string Load(this Editor window)
{
var data = EditorPrefs.GetString(window.GetType().ToString(), JsonUtility.ToJson(window, false));
JsonUtility.FromJsonOverwrite(data, window);
return data;
}
public static string SaveOnlyForThisProject(this Editor window)
{
var data = JsonUtility.ToJson(window, false);
EditorPrefs.SetString(System.IO.Directory.GetCurrentDirectory()+"\\"+window.GetType().ToString(), data);
return data;
}
public static string LoadOnlyForThisProject(this Editor window)
{
var data = EditorPrefs.GetString(System.IO.Directory.GetCurrentDirectory()+"\\"+window.GetType().ToString(), JsonUtility.ToJson(window, false));
JsonUtility.FromJsonOverwrite(data, window);
return data;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment