@@ -123,6 +123,74 @@ protected void ShowPresetReceiver(UnityEngine.Object target){
123
123
protected abstract Transform TransferAnimationSource { get ; set ; }
124
124
protected abstract Transform TransferAnimationDest { get ; set ; }
125
125
126
+ //-------Helper functions for determining if Animation source and dest are valid---------
127
+
128
+ /// <summary>
129
+ /// Determines whether p is an ancestor to t.
130
+ /// </summary>
131
+ /// <returns><c>true</c> if p is ancestor to t; otherwise, <c>false</c>.</returns>
132
+ /// <param name="p">P.</param>
133
+ /// <param name="t">T.</param>
134
+ protected bool IsAncestor ( Transform p , Transform t ) {
135
+ var curr = t ;
136
+ while ( curr != null ) {
137
+ if ( curr == p ) {
138
+ return true ;
139
+ }
140
+ curr = curr . parent ;
141
+ }
142
+ return false ;
143
+ }
144
+
145
+ /// <summary>
146
+ /// Determines whether t1 and t2 are in the same hierarchy.
147
+ /// </summary>
148
+ /// <returns><c>true</c> if t1 is in same hierarchy as t2; otherwise, <c>false</c>.</returns>
149
+ /// <param name="t1">T1.</param>
150
+ /// <param name="t2">T2.</param>
151
+ protected bool IsInSameHierarchy ( Transform t1 , Transform t2 ) {
152
+ return ( IsAncestor ( t1 , t2 ) || IsAncestor ( t2 , t1 ) ) ;
153
+ }
154
+
155
+
156
+ protected virtual bool TransferAnimationSourceIsValid ( Transform newValue , GameObject selectedGO ) {
157
+ if ( ! newValue ) {
158
+ return true ;
159
+ }
160
+
161
+ // source must be ancestor to dest
162
+ if ( TransferAnimationDest && ! IsAncestor ( newValue , TransferAnimationDest ) ) {
163
+ Debug . LogWarningFormat ( "FbxExportSettings: Source {0} must be an ancestor of {1}" , newValue . name , TransferAnimationDest . name ) ;
164
+ return false ;
165
+ }
166
+ // must be in same hierarchy as selected GO
167
+ if ( ! selectedGO || ! IsInSameHierarchy ( newValue , selectedGO . transform ) ) {
168
+ Debug . LogWarningFormat ( "FbxExportSettings: Source {0} must be in the same hierarchy as {1}" , newValue . name , selectedGO ? selectedGO . name : "the selected object" ) ;
169
+ return false ;
170
+ }
171
+ return true ;
172
+ }
173
+
174
+ protected virtual bool TransferAnimationDestIsValid ( Transform newValue , GameObject selectedGO ) {
175
+ if ( ! newValue ) {
176
+ return true ;
177
+ }
178
+
179
+ // source must be ancestor to dest
180
+ if ( TransferAnimationSource && ! IsAncestor ( TransferAnimationSource , newValue ) ) {
181
+ Debug . LogWarningFormat ( "FbxExportSettings: Destination {0} must be a descendant of {1}" , newValue . name , TransferAnimationSource . name ) ;
182
+ return false ;
183
+ }
184
+ // must be in same hierarchy as selected GO
185
+ if ( ! selectedGO || ! IsInSameHierarchy ( newValue , selectedGO . transform ) ) {
186
+ Debug . LogWarningFormat ( "FbxExportSettings: Destination {0} must be in the same hierarchy as {1}" , newValue . name , selectedGO ? selectedGO . name : "the selected object" ) ;
187
+ return false ;
188
+ }
189
+ return true ;
190
+ }
191
+
192
+ // -------------------------------------------------------------------------------------
193
+
126
194
protected void OnGUI ( )
127
195
{
128
196
// Increasing the label width so that none of the text gets cut off
@@ -308,6 +376,7 @@ protected bool IsPlayableDirector {
308
376
set {
309
377
m_isPlayableDirector = value ;
310
378
DisableNameSelection = m_isPlayableDirector ;
379
+ DisableTransferAnim = m_isPlayableDirector ;
311
380
}
312
381
}
313
382
@@ -316,10 +385,10 @@ protected override Transform TransferAnimationSource {
316
385
return ExportSettings . instance . exportModelSettings . info . AnimationSource ;
317
386
}
318
387
set {
319
- // source must be ancestor to dest
320
-
321
- // must be in same hierarchy as selected GO
322
-
388
+ var selectedGO = ModelExporter . GetGameObject ( m_toExport [ 0 ] ) ;
389
+ if ( ! TransferAnimationSourceIsValid ( value , selectedGO ) ) {
390
+ return ;
391
+ }
323
392
ExportSettings . instance . exportModelSettings . info . SetAnimationSource ( value ) ;
324
393
}
325
394
}
@@ -329,6 +398,10 @@ protected override Transform TransferAnimationDest {
329
398
return ExportSettings . instance . exportModelSettings . info . AnimationDest ;
330
399
}
331
400
set {
401
+ var selectedGO = ModelExporter . GetGameObject ( m_toExport [ 0 ] ) ;
402
+ if ( ! TransferAnimationDestIsValid ( value , selectedGO ) ) {
403
+ return ;
404
+ }
332
405
ExportSettings . instance . exportModelSettings . info . SetAnimationDest ( value ) ;
333
406
}
334
407
}
0 commit comments