@@ -1468,8 +1468,9 @@ protected void AddFbxNodeToConstraintsMapping<T>(FbxNode fbxNode, T fbxConstrain
1468
1468
MapConstrainedObjectToConstraints [ fbxNode ] . Add ( fbxConstraint , uniConstraintType ) ;
1469
1469
}
1470
1470
1471
- protected bool ExportPositionConstraint ( PositionConstraint uniPosConstraint , FbxScene fbxScene , FbxNode fbxNode )
1471
+ protected bool ExportPositionConstraint ( IConstraint uniConstraint , FbxScene fbxScene , FbxNode fbxNode )
1472
1472
{
1473
+ var uniPosConstraint = uniConstraint as PositionConstraint ;
1473
1474
if ( uniPosConstraint == null )
1474
1475
{
1475
1476
return false ;
@@ -1499,8 +1500,9 @@ protected bool ExportPositionConstraint(PositionConstraint uniPosConstraint, Fbx
1499
1500
return true ;
1500
1501
}
1501
1502
1502
- protected bool ExportRotationConstraint ( RotationConstraint uniRotConstraint , FbxScene fbxScene , FbxNode fbxNode )
1503
+ protected bool ExportRotationConstraint ( IConstraint uniConstraint , FbxScene fbxScene , FbxNode fbxNode )
1503
1504
{
1505
+ var uniRotConstraint = uniConstraint as RotationConstraint ;
1504
1506
if ( uniRotConstraint == null )
1505
1507
{
1506
1508
return false ;
@@ -1534,8 +1536,9 @@ protected bool ExportRotationConstraint(RotationConstraint uniRotConstraint, Fbx
1534
1536
return true ;
1535
1537
}
1536
1538
1537
- protected bool ExportScaleConstraint ( ScaleConstraint uniScaleConstraint , FbxScene fbxScene , FbxNode fbxNode )
1539
+ protected bool ExportScaleConstraint ( IConstraint uniConstraint , FbxScene fbxScene , FbxNode fbxNode )
1538
1540
{
1541
+ var uniScaleConstraint = uniConstraint as ScaleConstraint ;
1539
1542
if ( uniScaleConstraint == null )
1540
1543
{
1541
1544
return false ;
@@ -1567,8 +1570,9 @@ protected bool ExportScaleConstraint(ScaleConstraint uniScaleConstraint, FbxScen
1567
1570
return true ;
1568
1571
}
1569
1572
1570
- protected bool ExportAimConstraint ( AimConstraint uniAimConstraint , FbxScene fbxScene , FbxNode fbxNode )
1573
+ protected bool ExportAimConstraint ( IConstraint uniConstraint , FbxScene fbxScene , FbxNode fbxNode )
1571
1574
{
1575
+ var uniAimConstraint = uniConstraint as AimConstraint ;
1572
1576
if ( uniAimConstraint == null )
1573
1577
{
1574
1578
return false ;
@@ -1635,8 +1639,9 @@ protected bool ExportAimConstraint(AimConstraint uniAimConstraint, FbxScene fbxS
1635
1639
return true ;
1636
1640
}
1637
1641
1638
- protected bool ExportParentConstraint ( ParentConstraint uniParentConstraint , FbxScene fbxScene , FbxNode fbxNode )
1642
+ protected bool ExportParentConstraint ( IConstraint uniConstraint , FbxScene fbxScene , FbxNode fbxNode )
1639
1643
{
1644
+ var uniParentConstraint = uniConstraint as ParentConstraint ;
1640
1645
if ( uniParentConstraint == null )
1641
1646
{
1642
1647
return false ;
@@ -1686,38 +1691,30 @@ protected bool ExportParentConstraint(ParentConstraint uniParentConstraint, FbxS
1686
1691
return true ;
1687
1692
}
1688
1693
1694
+ private delegate bool ExportConstraintDelegate ( IConstraint c , FbxScene fs , FbxNode fn ) ;
1695
+
1689
1696
protected bool ExportConstraints ( GameObject unityGo , FbxScene fbxScene , FbxNode fbxNode )
1690
1697
{
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
+
1691
1707
// check if GameObject has one of the 5 supported constraints: aim, parent, position, rotation, scale
1692
1708
var constraints = unityGo . GetComponents < IConstraint > ( ) ;
1693
1709
1694
1710
foreach ( var constraint in constraints )
1695
1711
{
1696
1712
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 ) )
1718
1714
{
1719
1715
throw new System . NotImplementedException ( constraintType . Name ) ;
1720
1716
}
1717
+ mapConstraintTypeToExportFunction [ constraintType ] ( constraint , fbxScene , fbxNode ) ;
1721
1718
}
1722
1719
1723
1720
return true ;
0 commit comments