Skip to content

Commit 82d5894

Browse files
committed
move transfer anim UI out of options
- can't set it in the preset since it's not serializable, so don't show it with the other options - if a single object selected, set default source/dest to this object
1 parent 407cea2 commit 82d5894

File tree

4 files changed

+69
-13
lines changed

4 files changed

+69
-13
lines changed

Assets/FbxExporters/Editor/ConvertToPrefabEditorWindow.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,24 @@ public class ConvertToPrefabEditorWindow : ExportOptionsEditorWindow
2020

2121
private float m_prefabExtLabelWidth;
2222

23+
protected override Transform TransferAnimationSource {
24+
get {
25+
return ExportSettings.instance.convertToPrefabSettings.info.AnimationSource;
26+
}
27+
set {
28+
ExportSettings.instance.convertToPrefabSettings.info.SetAnimationSource (value);
29+
}
30+
}
31+
32+
protected override Transform TransferAnimationDest {
33+
get {
34+
return ExportSettings.instance.convertToPrefabSettings.info.AnimationDest;
35+
}
36+
set {
37+
ExportSettings.instance.convertToPrefabSettings.info.SetAnimationDest (value);
38+
}
39+
}
40+
2341
public static void Init (IEnumerable<GameObject> toConvert)
2442
{
2543
ConvertToPrefabEditorWindow window = CreateWindow<ConvertToPrefabEditorWindow> ();
@@ -33,6 +51,13 @@ protected void SetGameObjectsToConvert(IEnumerable<GameObject> toConvert){
3351

3452
if (m_toConvert.Length == 1) {
3553
m_prefabFileName = m_toConvert [0].name;
54+
55+
// if only one object selected, set transfer source/dest to this object
56+
var go = ModelExporter.GetGameObject (m_toConvert [0]);
57+
if (go) {
58+
TransferAnimationSource = go.transform;
59+
TransferAnimationDest = go.transform;
60+
}
3661
} else if (m_toConvert.Length > 1) {
3762
m_prefabFileName = "(automatic)";
3863
}

Assets/FbxExporters/Editor/ExportModelEditorWindow.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ protected void ShowPresetReceiver(UnityEngine.Object target){
118118
UnityEditor.Presets.PresetSelector.ShowSelector(target, null, true, m_receiver);
119119
}
120120

121+
protected abstract Transform TransferAnimationSource { get; set; }
122+
protected abstract Transform TransferAnimationDest { get; set; }
123+
121124
protected void OnGUI ()
122125
{
123126
// Increasing the label width so that none of the text gets cut off
@@ -198,6 +201,15 @@ protected void OnGUI ()
198201

199202
CreateCustomUI();
200203

204+
EditorGUILayout.Space ();
205+
EditorGUI.indentLevel--;
206+
GUILayout.BeginHorizontal();
207+
EditorGUILayout.LabelField(new GUIContent("Transfer Animation", "Select bone to transfer root motion animation to."), GUILayout.Width(LabelWidth - FieldOffset));
208+
GUILayout.EndHorizontal();
209+
EditorGUI.indentLevel++;
210+
TransferAnimationSource = EditorGUILayout.ObjectField ("Source", TransferAnimationSource, typeof(Transform), allowSceneObjects: true) as Transform;
211+
TransferAnimationDest = EditorGUILayout.ObjectField ("Destination", TransferAnimationDest, typeof(Transform), allowSceneObjects: true) as Transform;
212+
201213
EditorGUILayout.Space ();
202214
EditorGUI.indentLevel--;
203215
m_showOptions = EditorGUILayout.Foldout (m_showOptions, "Options");
@@ -257,6 +269,24 @@ public class ExportModelEditorWindow : ExportOptionsEditorWindow
257269
private bool m_singleHierarchyExport = true;
258270
private bool m_isPlayableDirector = false;
259271

272+
protected override Transform TransferAnimationSource {
273+
get {
274+
return ExportSettings.instance.exportModelSettings.info.AnimationSource;
275+
}
276+
set {
277+
ExportSettings.instance.exportModelSettings.info.SetAnimationSource (value);
278+
}
279+
}
280+
281+
protected override Transform TransferAnimationDest {
282+
get {
283+
return ExportSettings.instance.exportModelSettings.info.AnimationDest;
284+
}
285+
set {
286+
ExportSettings.instance.exportModelSettings.info.SetAnimationDest (value);
287+
}
288+
}
289+
260290
public static void Init (IEnumerable<UnityEngine.Object> toExport, string filename = "", bool isTimelineAnim = false, bool isPlayableDirector = false)
261291
{
262292
ExportModelEditorWindow window = CreateWindow<ExportModelEditorWindow> ();
@@ -273,6 +303,16 @@ public static void Init (IEnumerable<UnityEngine.Object> toExport, string filena
273303

274304
protected int SetGameObjectsToExport(IEnumerable<UnityEngine.Object> toExport){
275305
m_toExport = toExport.ToArray ();
306+
307+
// if only one object selected, set transfer source/dest to this object
308+
if (m_toExport.Length == 1) {
309+
var go = ModelExporter.GetGameObject (m_toExport [0]);
310+
if (go) {
311+
TransferAnimationSource = go.transform;
312+
TransferAnimationDest = go.transform;
313+
}
314+
}
315+
276316
return m_toExport.Length;
277317
}
278318

Assets/FbxExporters/Editor/ExportModelSettings.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,6 @@ public override void OnInspectorGUI ()
6767
EditorGUI.EndDisabledGroup ();
6868
GUILayout.EndHorizontal();
6969

70-
GUILayout.BeginHorizontal();
71-
EditorGUILayout.LabelField(new GUIContent("Transfer Animation", "Select bone to transfer root motion animation to."), GUILayout.Width(LabelWidth - FieldOffset));
72-
GUILayout.EndHorizontal();
73-
EditorGUI.indentLevel++;
74-
exportSettings.animSource = EditorGUILayout.ObjectField ("Source", exportSettings.animSource, typeof(Transform), allowSceneObjects: true) as Transform;
75-
exportSettings.animDest = EditorGUILayout.ObjectField ("Destination", exportSettings.animDest, typeof(Transform), allowSceneObjects: true) as Transform;
76-
EditorGUI.indentLevel--;
77-
7870
exportSettings.animatedSkinnedMesh = EditorGUILayout.Toggle ("Animated Skinned Mesh", exportSettings.animatedSkinnedMesh);
7971
EditorGUI.EndDisabledGroup ();
8072

@@ -140,7 +132,9 @@ public abstract class ExportOptionsSettingsSerializeBase : IExportOptions
140132
public bool UseMayaCompatibleNames { get { return mayaCompatibleNaming; } }
141133
public void SetUseMayaCompatibleNames(bool useMayaCompNames){ this.mayaCompatibleNaming = useMayaCompNames; }
142134
public Transform AnimationSource { get { return animSource; } }
135+
public void SetAnimationSource(Transform source) { this.animSource = source; }
143136
public Transform AnimationDest { get { return animDest; } }
137+
public void SetAnimationDest(Transform dest) { this.animDest = dest; }
144138
public abstract ExportSettings.Include ModelAnimIncludeOption { get; }
145139
public abstract ExportSettings.LODExportType LODExportType { get; }
146140
public abstract ExportSettings.ObjectPosition ObjectPosition { get; }

Assets/FbxExporters/Editor/FbxExporter.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,6 @@ namespace Editor
6464

6565
public class ModelExporter : System.IDisposable
6666
{
67-
// To be replaced by checkbox in Fbx Export settings
68-
bool removeAnimationsFromSkinnedMeshRenderer = true;
69-
7067
const string Title =
7168
"exports static meshes with materials and textures";
7269

@@ -1821,7 +1818,7 @@ protected void ExportAnimationClip (AnimationClip uniAnimClip, GameObject uniRoo
18211818
// transfer root motion
18221819
var animSource = ExportOptions.AnimationSource;
18231820
var animDest = ExportOptions.AnimationDest;
1824-
if (animSource && animDest) {
1821+
if (animSource && animDest && animSource != animDest) {
18251822
// list of all transforms between source and dest, including source and dest
18261823
var transformsFromSourceToDest = new List<Transform> ();
18271824
var curr = animDest;
@@ -2307,7 +2304,7 @@ private bool TransformShouldBeReset(Transform t){
23072304
var source = ExportOptions.AnimationSource;
23082305
var dest = ExportOptions.AnimationDest;
23092306

2310-
if (!source || !dest) {
2307+
if (!source || !dest || source == dest) {
23112308
return false;
23122309
}
23132310

0 commit comments

Comments
 (0)