Skip to content

Instantly share code, notes, and snippets.

@tsubaki
Created January 31, 2017 14:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tsubaki/de7690f86705ef404580aff4c3225877 to your computer and use it in GitHub Desktop.
Save tsubaki/de7690f86705ef404580aff4c3225877 to your computer and use it in GitHub Desktop.
ISerializationCallbackReceiverを使用したバージョン
using UnityEngine;
using UnityEditor;
public class EditorWindowTest : EditorWindow ,ISerializationCallbackReceiver
{
public static string message;
[MenuItem("Window/Show")]
static void Init()
{
var window = EditorWindow.CreateInstance<EditorWindowTest> ();
EditorWindowTest.message = "C";
window.Show ();
}
void OnGUI()
{
GUILayout.Label (EditorWindowTest.message);
if (GUILayout.Button ("PUSH")) { EditorWindowTest.message += "#"; }
}
public void OnBeforeSerialize ()
{
using (System.IO.StreamWriter writer = new System.IO.StreamWriter ("Temp/EditorWindowTest")) {
writer.WriteLine (EditorWindowTest.message);
}
}
public void OnAfterDeserialize ()
{
using (System.IO.StreamReader reader = new System.IO.StreamReader ("Temp/EditorWindowTest")) {
EditorWindowTest.message = reader.ReadLine ();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment