Skip to content

Instantly share code, notes, and snippets.

@kyubuns
Created May 27, 2014 10:39
Show Gist options
  • Save kyubuns/ec28db10f62fa3bf94c9 to your computer and use it in GitHub Desktop.
Save kyubuns/ec28db10f62fa3bf94c9 to your computer and use it in GitHub Desktop.
EditorWIndow-Undo
using UnityEngine;
using UnityEditor;
using System;
public class TestWindow : EditorWindow {
// Serializableの物(public or SerializeField)がUndo対象.
[SerializeField] string testText;
// うぃんど~ひらくよ~
[MenuItem("Window/TestWindow")]
static void Open()
{
var window = (TestWindow)EditorWindow.GetWindow(typeof(TestWindow));
window.Show();
}
void OnGUI()
{
EditorGUI.BeginChangeCheck();
// ここで直接代入してはいけない.
var tempTestText = EditorGUILayout.TextField("", testText);
if(EditorGUI.EndChangeCheck())
{
// Undoで戻る先を保存する.
Undo.RecordObject(this, "test undo");
// そのあと、変更を適用
testText = tempTestText;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment