Skip to content

Commit b7610e8

Browse files
author
AJubrey
committed
[ADDED] you can now export RectTransforms
1 parent cd0309f commit b7610e8

File tree

2 files changed

+37
-6
lines changed

2 files changed

+37
-6
lines changed

Assets/FbxExporters/Editor/FbxExporter.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,21 +683,41 @@ protected void ExportTransform (UnityEngine.Transform unityTransform, FbxNode fb
683683
FbxDouble3 fbxRotate;
684684
UnityEngine.Vector3 unityScale;
685685

686+
RectTransform uiComponent = unityTransform.gameObject.GetComponent<RectTransform>();
687+
686688
switch (exportType) {
687689
case TransformExportType.Reset:
688690
unityTranslate = Vector3.zero;
689691
fbxRotate = new FbxDouble3 (0);
690692
unityScale = Vector3.one;
693+
if (uiComponent != null) // if this component is a RectTransform
694+
{
695+
unityTranslate = uiComponent.localPosition;
696+
fbxRotate = ConvertQuaternionToXYZEuler(uiComponent.localRotation);
697+
unityScale = uiComponent.localScale;
698+
}
691699
break;
692700
case TransformExportType.Global:
693701
unityTranslate = GetRecenteredTranslation(unityTransform, newCenter);
694702
fbxRotate = ConvertQuaternionToXYZEuler(unityTransform.rotation);
695703
unityScale = unityTransform.lossyScale;
704+
if (uiComponent != null) // if this component is a RectTransform
705+
{
706+
unityTranslate = GetRecenteredTranslation(uiComponent.transform, newCenter);
707+
fbxRotate = ConvertQuaternionToXYZEuler(uiComponent.rotation);
708+
unityScale = uiComponent.lossyScale;
709+
}
696710
break;
697711
default: /*case TransformExportType.Local*/
698712
unityTranslate = unityTransform.localPosition;
699713
fbxRotate = ConvertQuaternionToXYZEuler(unityTransform.localRotation);
700714
unityScale = unityTransform.localScale;
715+
if(uiComponent != null) // if this component is a RectTransform
716+
{
717+
unityTranslate = uiComponent.localPosition;
718+
fbxRotate = ConvertQuaternionToXYZEuler(uiComponent.localRotation);
719+
unityScale = uiComponent.localScale;
720+
}
701721
break;
702722
}
703723

Assets/FbxExporters/Editor/FbxPrefabAutoUpdater.cs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -983,13 +983,24 @@ public HashSet<GameObject> ImplementUpdates(FbxPrefab prefabInstance)
983983
prefabComponent = prefabXfo.gameObject.AddComponent(fbxComponent.t);
984984
Log("created component {0}:{1}", nodeName, fbxComponent.t);
985985
}
986-
// Check that the component exists before copying to it.
987-
// This happens for Rect Transform components as the fbx
988-
// contains a Transform which it tries to add/update on the
989-
// prefab, but fails because you cannot have both a Transform
990-
// and a Rect Transform
991-
// UNI-29179 TODO: better handling of Rect Transforms
986+
992987
if (!prefabComponent) {
988+
989+
index = prefabComponents.FindIndex(x => x.GetType() == typeof(RectTransform));
990+
prefabComponent = prefabComponents[index];
991+
prefabComponents.RemoveAt(index);
992+
993+
GameObject tempGameObject = new GameObject();
994+
Transform tempTransform = tempGameObject.transform;
995+
996+
UnityEditor.EditorJsonUtility.FromJsonOverwrite(fbxComponent.jsonValue, tempTransform);
997+
998+
prefabComponent.gameObject.GetComponent<RectTransform>().rotation = tempTransform.rotation;
999+
prefabComponent.gameObject.GetComponent<RectTransform>().position = tempTransform.position;
1000+
prefabComponent.gameObject.GetComponent<RectTransform>().localScale = tempTransform.localScale;
1001+
GameObject.DestroyImmediate(tempGameObject);
1002+
1003+
Log("updated component {0}:{1}", nodeName, typeof(RectTransform));
9931004
continue;
9941005
}
9951006
// Now set the values.

0 commit comments

Comments
 (0)