Created
May 27, 2014 10:39
-
-
Save kyubuns/ec28db10f62fa3bf94c9 to your computer and use it in GitHub Desktop.
EditorWIndow-Undo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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