4
4
using UnityEngine ;
5
5
using UnityEditor ;
6
6
using System . Linq ;
7
+ using System ;
7
8
8
9
namespace FbxExporters
9
10
{
@@ -162,14 +163,13 @@ public FbxPrefabUtility(FbxPrefab fbxPrefab){
162
163
/// <summary>
163
164
/// Utility function: check if the user has specified a matching Unity name in the inspector
164
165
/// </summary>
165
- public string getUnityObjectName ( string fbxObjectName )
166
+ public string GetUnityObjectName ( string fbxObjectName )
166
167
{
167
168
string newNameInUnity = fbxObjectName ;
168
- if ( fbxObjectName != "" && m_fbxPrefab . NameMapping != null ) {
169
- for ( int i = 0 ; i < m_fbxPrefab . NameMapping . Count ; i ++ )
170
- {
171
- if ( fbxObjectName == m_fbxPrefab . NameMapping [ i ] . FBXObjectName ) {
172
- newNameInUnity = m_fbxPrefab . NameMapping [ i ] . UnityObjectName ;
169
+ if ( String . IsNullOrEmpty ( fbxObjectName ) && m_fbxPrefab . NameMapping != null ) {
170
+ foreach ( var nameMapping in m_fbxPrefab . NameMapping ) {
171
+ if ( fbxObjectName == nameMapping . FBXObjectName ) {
172
+ newNameInUnity = nameMapping . UnityObjectName ;
173
173
break ;
174
174
}
175
175
}
@@ -179,14 +179,13 @@ public string getUnityObjectName(string fbxObjectName)
179
179
/// <summary>
180
180
/// Utility function: check if the user has specified a matching FBX name in the inspector
181
181
/// </summary>
182
- public string getFBXObjectName ( string unityObjectName )
182
+ public string GetFBXObjectName ( string unityObjectName )
183
183
{
184
184
string oldNameInFBX = unityObjectName ;
185
185
if ( unityObjectName != "" && m_fbxPrefab . NameMapping != null ) {
186
- for ( int i = 0 ; i < m_fbxPrefab . NameMapping . Count ; i ++ )
187
- {
188
- if ( unityObjectName == m_fbxPrefab . NameMapping [ i ] . UnityObjectName ) {
189
- oldNameInFBX = m_fbxPrefab . NameMapping [ i ] . FBXObjectName ;
186
+ foreach ( var nameMapping in m_fbxPrefab . NameMapping ) {
187
+ if ( unityObjectName == nameMapping . UnityObjectName ) {
188
+ oldNameInFBX = nameMapping . FBXObjectName ;
190
189
break ;
191
190
}
192
191
}
@@ -464,7 +463,6 @@ void InitFromJson(string json, ref int index)
464
463
if ( isChild ) {
465
464
var subrep = new FbxRepresentation ( json , ref index ) ;
466
465
Add ( ref m_children , name . Substring ( 1 ) , subrep ) ;
467
- //Add(ref m_children, getFBXName(name.Substring(1)), subrep);
468
466
} else {
469
467
string jsonComponent = ReadString ( json , ref index ) ;
470
468
Append ( ref m_components , name , jsonComponent ) ;
@@ -691,8 +689,6 @@ public List<string> GetComponentValues(string name, string typename)
691
689
/// </summary>
692
690
HashSet < string > m_nodesInUpdatedPrefab ;
693
691
694
-
695
-
696
692
/// <summary>
697
693
/// Components to destroy in step 4a.
698
694
/// The string is the name in the prefab; we destroy the first
@@ -735,15 +731,15 @@ void ClassifyDestroyCreateNodes()
735
731
if ( isOldFBXNodeName != isNewFBXNodeName ) {
736
732
737
733
// If there is a mapping for the old name, skip it. We will add the new name to the nodes to rename
738
- if ( m_newFbxData . HasNode ( m_fbxPrefabUtility . getFBXObjectName ( nodeName ) ) && isOldFBXNodeName ) {
734
+ if ( m_newFbxData . HasNode ( m_fbxPrefabUtility . GetFBXObjectName ( nodeName ) ) && isOldFBXNodeName ) {
739
735
continue ;
740
736
}
741
737
742
738
// A node was added or deleted in the DCC.
743
739
// Do the same in Unity if it wasn't already done.
744
740
var isPrefab = m_prefabData . HasNode ( nodeName ) ;
745
741
// If the New FBX has a node that has to be renamed in the prefab
746
- if ( isNewFBXNodeName && m_oldFbxData . HasNode ( m_fbxPrefabUtility . getUnityObjectName ( nodeName ) ) ) {
742
+ if ( isNewFBXNodeName && m_oldFbxData . HasNode ( m_fbxPrefabUtility . GetUnityObjectName ( nodeName ) ) ) {
747
743
// FBX Node Name of New FBX Data
748
744
m_nodesToRename . Add ( nodeName ) ;
749
745
// If it's an old name that is present in the prefab, add it to the list to destroy
@@ -796,10 +792,10 @@ void ClassifyReparenting()
796
792
var prefabParent = m_prefabData . GetParent ( prefabNodeName ) ;
797
793
var oldParent = m_oldFbxData . GetParent ( prefabNodeName ) ;
798
794
// The newFbxData contains the fbx name, so we get the parent from the matching prefabNodeName equivalent
799
- var newParent = m_newFbxData . GetParent ( m_fbxPrefabUtility . getFBXObjectName ( prefabNodeName ) ) ;
795
+ var newParent = m_newFbxData . GetParent ( m_fbxPrefabUtility . GetFBXObjectName ( prefabNodeName ) ) ;
800
796
801
797
// If it's a name mapping, don't add a reparenting, we'll rename it later in ImplementUpdates()
802
- if ( oldParent != newParent && prefabParent != newParent && oldParent != m_fbxPrefabUtility . getUnityObjectName ( newParent ) ) {
798
+ if ( oldParent != newParent && prefabParent != newParent && oldParent != m_fbxPrefabUtility . GetUnityObjectName ( newParent ) ) {
803
799
// Conflict in this case:
804
800
// if (oldParent != prefabParent && !ShouldDestroy(prefabParent))
805
801
@@ -858,7 +854,7 @@ void ClassifyComponents(Transform newFbx, Transform prefab)
858
854
foreach ( var nodeNameInUpdatedPrefab in m_nodesInUpdatedPrefab )
859
855
{
860
856
// Get the matching name for the node in the m_newFbxData
861
- string nodeNameInFBX = m_fbxPrefabUtility . getFBXObjectName ( nodeNameInUpdatedPrefab ) ;
857
+ string nodeNameInFBX = m_fbxPrefabUtility . GetFBXObjectName ( nodeNameInUpdatedPrefab ) ;
862
858
863
859
// The newFbxData contains the fbx name, so we check if the node is in it with the matching equivalent
864
860
if ( ! m_newFbxData . HasNode ( nodeNameInFBX ) ) {
@@ -910,8 +906,6 @@ void ClassifyComponents(Transform newFbx, Transform prefab)
910
906
}
911
907
}
912
908
913
-
914
-
915
909
/// <summary>
916
910
/// Discover what needs to happen.
917
911
///
@@ -1051,8 +1045,8 @@ public HashSet<GameObject> ImplementUpdates(FbxPrefab prefabInstance)
1051
1045
// Rename old nodes (unity names) into new nodes (FBX names).
1052
1046
foreach ( var FBXNodeNameToRename in m_nodesToRename )
1053
1047
{
1054
- prefabNodes [ m_fbxPrefabUtility . getUnityObjectName ( FBXNodeNameToRename ) ] . name = FBXNodeNameToRename ;
1055
- Log ( "Renamed {0} into {1}" , m_fbxPrefabUtility . getUnityObjectName ( FBXNodeNameToRename ) , FBXNodeNameToRename ) ;
1048
+ prefabNodes [ m_fbxPrefabUtility . GetUnityObjectName ( FBXNodeNameToRename ) ] . name = FBXNodeNameToRename ;
1049
+ Log ( "Renamed {0} into {1}" , m_fbxPrefabUtility . GetUnityObjectName ( FBXNodeNameToRename ) , FBXNodeNameToRename ) ;
1056
1050
}
1057
1051
1058
1052
// Create or update the new components.
0 commit comments