@@ -9,14 +9,22 @@ public class AnnotationInteractionEditor : Editor {
9
9
bool showRichText = true ;
10
10
Annotation annotation ;
11
11
12
-
13
- public override void OnInspectorGUI ( )
12
+ public void Awake ( )
14
13
{
15
14
annotation = ( Annotation ) target ;
15
+ }
16
16
17
+ public override void OnInspectorGUI ( )
18
+ {
17
19
// select type
18
20
string [ ] typeOptions = new string [ ] { "Summary Annotation" , "Area Annotation" } ;
19
- annotation . annotationType = EditorGUILayout . Popup ( "Annotation Type" , annotation . annotationType , typeOptions ) ;
21
+ EditorGUI . BeginChangeCheck ( ) ;
22
+ int _annotationType = EditorGUILayout . Popup ( "Annotation Type" , annotation . annotationType , typeOptions ) ;
23
+ if ( EditorGUI . EndChangeCheck ( ) )
24
+ {
25
+ Undo . RecordObject ( annotation , "Change Annotation Type" ) ;
26
+ annotation . annotationType = _annotationType ;
27
+ }
20
28
21
29
// warnings
22
30
if ( annotation . annotationType == ( int ) AnnotationTypes . AREA )
@@ -38,9 +46,15 @@ public override void OnInspectorGUI()
38
46
int previousType = annotation . importType ;
39
47
40
48
string [ ] importOptions = new string [ ] { "No Full Annotation" , "Import Text File" , "Write in Inspector" } ;
41
- annotation . importType = EditorGUILayout . Popup ( "Import Method" , annotation . importType , importOptions ) ;
42
49
50
+ EditorGUI . BeginChangeCheck ( ) ;
51
+ int _importType = EditorGUILayout . Popup ( "Import Method" , annotation . importType , importOptions ) ;
43
52
//checks with user, then resets full annotation information
53
+ if ( EditorGUI . EndChangeCheck ( ) )
54
+ {
55
+ Undo . RecordObject ( annotation , "Change Annotation Type" ) ;
56
+ annotation . importType = _importType ;
57
+ }
44
58
if ( previousType != 0 && annotation . importType == ( int ) ImportTypes . NONE )
45
59
{
46
60
if ( EditorUtility . DisplayDialog ( "Reset" , "WARNING: Switching back to 'No Full Annotation' will cause any curent information to be lost..." ,
@@ -66,25 +80,35 @@ public override void OnInspectorGUI()
66
80
{
67
81
DisplayWriteInInspector ( ) ;
68
82
}
69
-
70
- if ( GUI . changed ) {
71
- EditorUtility . SetDirty ( annotation ) ;
72
- }
73
83
}
74
84
75
85
void DisplaySetLargeSummary ( )
76
86
{
77
87
GUIStyle textAreaStyle = new GUIStyle ( GUI . skin . textArea ) ;
78
88
textAreaStyle . wordWrap = true ;
79
89
GUILayout . Label ( "Annotation Summary Text:" ) ;
80
- annotation . summary = GUILayout . TextArea ( annotation . summary , 250 , textAreaStyle , GUILayout . Height ( 75 ) ,
90
+
91
+ EditorGUI . BeginChangeCheck ( ) ;
92
+ string _summary = GUILayout . TextArea ( annotation . summary , 250 , textAreaStyle , GUILayout . Height ( 75 ) ,
81
93
GUILayout . Width ( EditorGUIUtility . currentViewWidth - 40 ) , GUILayout . ExpandWidth ( false ) ) ;
94
+ if ( EditorGUI . EndChangeCheck ( ) )
95
+ {
96
+ Undo . RecordObject ( annotation , "Change Annotation Summary" ) ;
97
+ annotation . summary = _summary ;
98
+ }
82
99
}
83
100
84
101
void DisplaySetAreaInteractionSummary ( )
85
102
{
86
103
GUILayout . Label ( "Annotation Name:" ) ;
87
- annotation . summary = GUILayout . TextField ( annotation . summary , 40 ) ;
104
+
105
+ EditorGUI . BeginChangeCheck ( ) ;
106
+ string _summary = GUILayout . TextField ( annotation . summary , 40 ) ;
107
+ if ( EditorGUI . EndChangeCheck ( ) )
108
+ {
109
+ Undo . RecordObject ( annotation , "Change Area Annotation Name" ) ;
110
+ annotation . summary = _summary ;
111
+ }
88
112
}
89
113
90
114
/// <summary>
@@ -130,6 +154,8 @@ void ImportFileButton()
130
154
131
155
if ( absolutePath . StartsWith ( Application . dataPath ) )
132
156
{
157
+ Undo . RecordObject ( annotation , "Change Annotation Text File" ) ;
158
+
133
159
annotation . textFilePath = "Assets" + absolutePath . Substring ( Application . dataPath . Length ) ;
134
160
annotation . textFile = AssetDatabase . LoadAssetAtPath < TextAsset > ( annotation . textFilePath ) ;
135
161
if ( annotation . textFile != null )
@@ -163,15 +189,27 @@ void DisplayWriteInInspector()
163
189
textAreaStyle . richText = false ;
164
190
}
165
191
166
- annotation . text = EditorGUILayout . TextArea ( annotation . text , textAreaStyle , GUILayout . Height ( 100 ) ,
192
+ EditorGUI . BeginChangeCheck ( ) ;
193
+ string _text = EditorGUILayout . TextArea ( annotation . text , textAreaStyle , GUILayout . Height ( 100 ) ,
167
194
GUILayout . Width ( EditorGUIUtility . currentViewWidth - 40 ) , GUILayout . ExpandHeight ( true ) , GUILayout . ExpandWidth ( false ) ) ;
195
+ if ( EditorGUI . EndChangeCheck ( ) )
196
+ {
197
+ Undo . RecordObject ( annotation , "Change Annotation Content" ) ;
198
+ annotation . text = _text ;
199
+ }
168
200
169
201
GUILayout . BeginHorizontal ( ) ;
170
202
GUILayout . FlexibleSpace ( ) ;
171
203
SaveTextFileButton ( ) ;
172
204
GUILayout . EndHorizontal ( ) ;
173
205
174
- annotation . includeImages = EditorGUILayout . Toggle ( "Include Images:" , annotation . includeImages ) ;
206
+ EditorGUI . BeginChangeCheck ( ) ;
207
+ bool _includeImages = EditorGUILayout . Toggle ( "Include Images:" , annotation . includeImages ) ;
208
+ if ( EditorGUI . EndChangeCheck ( ) )
209
+ {
210
+ Undo . RecordObject ( annotation , "Change Annotation Images Folder" ) ;
211
+ annotation . includeImages = _includeImages ;
212
+ }
175
213
176
214
if ( annotation . includeImages )
177
215
{
@@ -198,6 +236,7 @@ void GetImagePath()
198
236
199
237
if ( absolutePath . StartsWith ( Application . dataPath ) )
200
238
{
239
+ Undo . RecordObject ( annotation , "Change Annotation Images Folder" ) ;
201
240
annotation . imagePath = "Assets" + absolutePath . Substring ( Application . dataPath . Length ) + Path . DirectorySeparatorChar ;
202
241
}
203
242
else
@@ -225,10 +264,13 @@ void SaveTextFileButton()
225
264
{
226
265
File . WriteAllText ( path , annotation . text ) ;
227
266
267
+ // We need to enlist an UNDO here, or else the changes to the annotation won't be saved.
268
+ // We can undo the annotation's binding to the file, but not the actual file creation.
269
+ Undo . RecordObject ( annotation , "Save Annotation to File" ) ;
270
+
228
271
//Links annotation file to newly saved file
229
272
annotation . textFilePath = "Assets" + path . Substring ( Application . dataPath . Length ) ;
230
273
annotation . textFile = AssetDatabase . LoadAssetAtPath < TextAsset > ( annotation . textFilePath ) ;
231
-
232
274
}
233
275
catch ( Exception e )
234
276
{
0 commit comments