Skip to content

Commit c61ea20

Browse files
committed
code review fix - use dictionary to map constraint to export func
1 parent c7b5f79 commit c61ea20

File tree

1 file changed

+23
-26
lines changed

1 file changed

+23
-26
lines changed

Assets/FbxExporters/Editor/FbxExporter.cs

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1468,8 +1468,9 @@ protected void AddFbxNodeToConstraintsMapping<T>(FbxNode fbxNode, T fbxConstrain
14681468
MapConstrainedObjectToConstraints[fbxNode].Add(fbxConstraint, uniConstraintType);
14691469
}
14701470

1471-
protected bool ExportPositionConstraint(PositionConstraint uniPosConstraint, FbxScene fbxScene, FbxNode fbxNode)
1471+
protected bool ExportPositionConstraint(IConstraint uniConstraint, FbxScene fbxScene, FbxNode fbxNode)
14721472
{
1473+
var uniPosConstraint = uniConstraint as PositionConstraint;
14731474
if(uniPosConstraint == null)
14741475
{
14751476
return false;
@@ -1499,8 +1500,9 @@ protected bool ExportPositionConstraint(PositionConstraint uniPosConstraint, Fbx
14991500
return true;
15001501
}
15011502

1502-
protected bool ExportRotationConstraint(RotationConstraint uniRotConstraint, FbxScene fbxScene, FbxNode fbxNode)
1503+
protected bool ExportRotationConstraint(IConstraint uniConstraint, FbxScene fbxScene, FbxNode fbxNode)
15031504
{
1505+
var uniRotConstraint = uniConstraint as RotationConstraint;
15041506
if(uniRotConstraint == null)
15051507
{
15061508
return false;
@@ -1534,8 +1536,9 @@ protected bool ExportRotationConstraint(RotationConstraint uniRotConstraint, Fbx
15341536
return true;
15351537
}
15361538

1537-
protected bool ExportScaleConstraint(ScaleConstraint uniScaleConstraint, FbxScene fbxScene, FbxNode fbxNode)
1539+
protected bool ExportScaleConstraint(IConstraint uniConstraint, FbxScene fbxScene, FbxNode fbxNode)
15381540
{
1541+
var uniScaleConstraint = uniConstraint as ScaleConstraint;
15391542
if (uniScaleConstraint == null)
15401543
{
15411544
return false;
@@ -1567,8 +1570,9 @@ protected bool ExportScaleConstraint(ScaleConstraint uniScaleConstraint, FbxScen
15671570
return true;
15681571
}
15691572

1570-
protected bool ExportAimConstraint(AimConstraint uniAimConstraint, FbxScene fbxScene, FbxNode fbxNode)
1573+
protected bool ExportAimConstraint(IConstraint uniConstraint, FbxScene fbxScene, FbxNode fbxNode)
15711574
{
1575+
var uniAimConstraint = uniConstraint as AimConstraint;
15721576
if (uniAimConstraint == null)
15731577
{
15741578
return false;
@@ -1635,8 +1639,9 @@ protected bool ExportAimConstraint(AimConstraint uniAimConstraint, FbxScene fbxS
16351639
return true;
16361640
}
16371641

1638-
protected bool ExportParentConstraint(ParentConstraint uniParentConstraint, FbxScene fbxScene, FbxNode fbxNode)
1642+
protected bool ExportParentConstraint(IConstraint uniConstraint, FbxScene fbxScene, FbxNode fbxNode)
16391643
{
1644+
var uniParentConstraint = uniConstraint as ParentConstraint;
16401645
if (uniParentConstraint == null)
16411646
{
16421647
return false;
@@ -1686,38 +1691,30 @@ protected bool ExportParentConstraint(ParentConstraint uniParentConstraint, FbxS
16861691
return true;
16871692
}
16881693

1694+
private delegate bool ExportConstraintDelegate(IConstraint c , FbxScene fs, FbxNode fn);
1695+
16891696
protected bool ExportConstraints (GameObject unityGo, FbxScene fbxScene, FbxNode fbxNode)
16901697
{
1698+
var mapConstraintTypeToExportFunction = new Dictionary<System.Type, ExportConstraintDelegate>()
1699+
{
1700+
{ typeof(PositionConstraint), ExportPositionConstraint },
1701+
{ typeof(RotationConstraint), ExportRotationConstraint },
1702+
{ typeof(ScaleConstraint), ExportScaleConstraint },
1703+
{ typeof(AimConstraint), ExportAimConstraint },
1704+
{ typeof(ParentConstraint), ExportParentConstraint }
1705+
};
1706+
16911707
// check if GameObject has one of the 5 supported constraints: aim, parent, position, rotation, scale
16921708
var constraints = unityGo.GetComponents<IConstraint>();
16931709

16941710
foreach(var constraint in constraints)
16951711
{
16961712
var constraintType = constraint.GetType();
1697-
if(constraintType == typeof(PositionConstraint))
1698-
{
1699-
ExportPositionConstraint(constraint as PositionConstraint, fbxScene, fbxNode);
1700-
}
1701-
else if (constraintType == typeof(RotationConstraint))
1702-
{
1703-
ExportRotationConstraint(constraint as RotationConstraint, fbxScene, fbxNode);
1704-
}
1705-
else if(constraintType == typeof(ScaleConstraint))
1706-
{
1707-
ExportScaleConstraint(constraint as ScaleConstraint, fbxScene, fbxNode);
1708-
}
1709-
else if(constraintType == typeof(AimConstraint))
1710-
{
1711-
ExportAimConstraint(constraint as AimConstraint, fbxScene, fbxNode);
1712-
}
1713-
else if(constraintType == typeof(ParentConstraint))
1714-
{
1715-
ExportParentConstraint(constraint as ParentConstraint, fbxScene, fbxNode);
1716-
}
1717-
else
1713+
if (!mapConstraintTypeToExportFunction.ContainsKey(constraintType))
17181714
{
17191715
throw new System.NotImplementedException(constraintType.Name);
17201716
}
1717+
mapConstraintTypeToExportFunction[constraintType](constraint, fbxScene, fbxNode);
17211718
}
17221719

17231720
return true;

0 commit comments

Comments
 (0)