@@ -101,10 +101,37 @@ IExportOptions exportOptions
101
101
}
102
102
}
103
103
104
- public static GameObject GetGameObjectBoundToEditorClip ( object editorClip )
104
+ /// <summary>
105
+ /// Get the property propertyName from object obj using reflection.
106
+ /// </summary>
107
+ /// <param name="obj"></param>
108
+ /// <param name="propertyName"></param>
109
+ /// <returns>property propertyName as an object</returns>
110
+ private static object GetPropertyReflection ( object obj , string propertyName )
111
+ {
112
+ return obj . GetType ( ) . GetProperty ( propertyName ) . GetValue ( obj , null ) ;
113
+ }
114
+
115
+ /// <summary>
116
+ /// Get the timeline clip from the given editor clip using reflection.
117
+ /// </summary>
118
+ /// <param name="editorClip"></param>
119
+ /// <returns>the timeline clip or null if none</returns>
120
+ private static TimelineClip GetTimelineClipFromEditorClip ( object editorClip )
105
121
{
106
- object clipItem = editorClip . GetType ( ) . GetProperty ( "item" ) . GetValue ( editorClip , null ) ;
107
- object parentTrack = clipItem . GetType ( ) . GetProperty ( "parentTrack" ) . GetValue ( clipItem , null ) ;
122
+ object clip = GetPropertyReflection ( editorClip , "clip" ) ;
123
+ return clip as TimelineClip ;
124
+ }
125
+
126
+ /// <summary>
127
+ /// Get the GameObject that the editor clip is bound to in the timeline using reflection.
128
+ /// </summary>
129
+ /// <param name="editorClip"></param>
130
+ /// <returns>The GameObject bound to the editor clip or null if none.</returns>
131
+ private static GameObject GetGameObjectBoundToEditorClip ( object editorClip )
132
+ {
133
+ object clipItem = GetPropertyReflection ( editorClip , "item" ) ;
134
+ object parentTrack = GetPropertyReflection ( clipItem , "parentTrack" ) ;
108
135
AnimationTrack animTrack = parentTrack as AnimationTrack ;
109
136
110
137
#if UNITY_2018_2_OR_NEWER
@@ -131,15 +158,19 @@ public static GameObject GetGameObjectBoundToEditorClip(object editorClip)
131
158
return animationTrackGO ;
132
159
}
133
160
134
- public static KeyValuePair < GameObject , AnimationClip > GetGameObjectAndAnimationClip ( Object obj )
161
+ /// <summary>
162
+ /// Get the GameObject and it's corresponding animation clip from the given editor clip.
163
+ /// </summary>
164
+ /// <param name="editorClip"></param>
165
+ /// <returns>KeyValuePair containing GameObject and corresponding AnimationClip</returns>
166
+ public static KeyValuePair < GameObject , AnimationClip > GetGameObjectAndAnimationClip ( Object editorClip )
135
167
{
136
- if ( ! ModelExporter . IsEditorClip ( obj ) )
168
+ if ( ! ModelExporter . IsEditorClip ( editorClip ) )
137
169
return new KeyValuePair < GameObject , AnimationClip > ( ) ;
170
+
171
+ TimelineClip timeLineClip = GetTimelineClipFromEditorClip ( editorClip ) ;
138
172
139
- object clip = obj . GetType ( ) . GetProperty ( "clip" ) . GetValue ( obj , null ) ;
140
- TimelineClip timeLineClip = clip as TimelineClip ;
141
-
142
- var animationTrackGO = GetGameObjectBoundToEditorClip ( obj ) ;
173
+ var animationTrackGO = GetGameObjectBoundToEditorClip ( editorClip ) ;
143
174
if ( animationTrackGO == null )
144
175
{
145
176
return new KeyValuePair < GameObject , AnimationClip > ( ) ;
@@ -148,31 +179,34 @@ public static KeyValuePair<GameObject, AnimationClip> GetGameObjectAndAnimationC
148
179
return new KeyValuePair < GameObject , AnimationClip > ( animationTrackGO , timeLineClip . animationClip ) ;
149
180
}
150
181
182
+ /// <summary>
183
+ /// Get the filename of the format {model}@{anim}.fbx from the given object
184
+ /// </summary>
185
+ /// <param name="obj"></param>
186
+ /// <returns>filename for use for exporting animation clip</returns>
151
187
public static string GetFileName ( Object obj )
152
188
{
153
- if ( ModelExporter . IsEditorClip ( obj ) )
189
+ if ( ! ModelExporter . IsEditorClip ( obj ) )
154
190
{
155
- object clip = obj . GetType ( ) . GetProperty ( "clip" ) . GetValue ( obj , null ) ;
156
- TimelineClip timeLineClip = clip as TimelineClip ;
191
+ // not an editor clip so just return the name of the object
192
+ return obj . name ;
193
+ }
157
194
158
- if ( timeLineClip . displayName . Contains ( "@" ) )
159
- {
160
- return timeLineClip . displayName ;
161
- }
162
- else
163
- {
164
- var goBound = GetGameObjectBoundToEditorClip ( obj ) ;
165
- if ( goBound == null )
166
- {
167
- return null ;
168
- }
169
- return string . Format ( "{0}@{1}" , goBound . name , timeLineClip . displayName ) ;
170
- }
195
+ TimelineClip timeLineClip = GetTimelineClipFromEditorClip ( obj ) ;
196
+
197
+ // if the timeline clip name already contains an @, then take this as the
198
+ // filename to avoid duplicate @
199
+ if ( timeLineClip . displayName . Contains ( "@" ) )
200
+ {
201
+ return timeLineClip . displayName ;
171
202
}
172
- else
203
+
204
+ var goBound = GetGameObjectBoundToEditorClip ( obj ) ;
205
+ if ( goBound == null )
173
206
{
174
207
return obj . name ;
175
208
}
209
+ return string . Format ( "{0}@{1}" , goBound . name , timeLineClip . displayName ) ;
176
210
}
177
211
}
178
212
}
0 commit comments