Skip to content

Commit dac4e27

Browse files
committed
Pull request changes
1 parent 78a6d96 commit dac4e27

File tree

3 files changed

+18
-25
lines changed

3 files changed

+18
-25
lines changed

Assets/FbxExporters/Editor/FbxPrefabAutoUpdater.cs

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using UnityEngine;
55
using UnityEditor;
66
using System.Linq;
7+
using System;
78

89
namespace FbxExporters
910
{
@@ -162,14 +163,13 @@ public FbxPrefabUtility(FbxPrefab fbxPrefab){
162163
/// <summary>
163164
/// Utility function: check if the user has specified a matching Unity name in the inspector
164165
/// </summary>
165-
public string getUnityObjectName(string fbxObjectName)
166+
public string GetUnityObjectName(string fbxObjectName)
166167
{
167168
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;
173173
break;
174174
}
175175
}
@@ -179,14 +179,13 @@ public string getUnityObjectName(string fbxObjectName)
179179
/// <summary>
180180
/// Utility function: check if the user has specified a matching FBX name in the inspector
181181
/// </summary>
182-
public string getFBXObjectName(string unityObjectName)
182+
public string GetFBXObjectName(string unityObjectName)
183183
{
184184
string oldNameInFBX = unityObjectName;
185185
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;
190189
break;
191190
}
192191
}
@@ -464,7 +463,6 @@ void InitFromJson(string json, ref int index)
464463
if (isChild) {
465464
var subrep = new FbxRepresentation(json, ref index);
466465
Add(ref m_children, name.Substring(1), subrep);
467-
//Add(ref m_children, getFBXName(name.Substring(1)), subrep);
468466
} else {
469467
string jsonComponent = ReadString(json, ref index);
470468
Append(ref m_components, name, jsonComponent);
@@ -691,8 +689,6 @@ public List<string> GetComponentValues(string name, string typename)
691689
/// </summary>
692690
HashSet<string> m_nodesInUpdatedPrefab;
693691

694-
695-
696692
/// <summary>
697693
/// Components to destroy in step 4a.
698694
/// The string is the name in the prefab; we destroy the first
@@ -735,15 +731,15 @@ void ClassifyDestroyCreateNodes()
735731
if (isOldFBXNodeName != isNewFBXNodeName) {
736732

737733
// 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) {
739735
continue;
740736
}
741737

742738
// A node was added or deleted in the DCC.
743739
// Do the same in Unity if it wasn't already done.
744740
var isPrefab = m_prefabData.HasNode(nodeName);
745741
// 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))) {
747743
// FBX Node Name of New FBX Data
748744
m_nodesToRename.Add(nodeName);
749745
// 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()
796792
var prefabParent = m_prefabData.GetParent(prefabNodeName);
797793
var oldParent = m_oldFbxData.GetParent(prefabNodeName);
798794
// 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));
800796

801797
// 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)) {
803799
// Conflict in this case:
804800
// if (oldParent != prefabParent && !ShouldDestroy(prefabParent))
805801

@@ -858,7 +854,7 @@ void ClassifyComponents(Transform newFbx, Transform prefab)
858854
foreach (var nodeNameInUpdatedPrefab in m_nodesInUpdatedPrefab)
859855
{
860856
// 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);
862858

863859
// The newFbxData contains the fbx name, so we check if the node is in it with the matching equivalent
864860
if (!m_newFbxData.HasNode(nodeNameInFBX)) {
@@ -910,8 +906,6 @@ void ClassifyComponents(Transform newFbx, Transform prefab)
910906
}
911907
}
912908

913-
914-
915909
/// <summary>
916910
/// Discover what needs to happen.
917911
///
@@ -1051,8 +1045,8 @@ public HashSet<GameObject> ImplementUpdates(FbxPrefab prefabInstance)
10511045
// Rename old nodes (unity names) into new nodes (FBX names).
10521046
foreach (var FBXNodeNameToRename in m_nodesToRename)
10531047
{
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);
10561050
}
10571051

10581052
// Create or update the new components.

Assets/FbxExporters/Editor/UnitTests/ExporterTestBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ protected virtual string ExportSelectedObjects(string filename, params Object[]
247247
/// The root can be allowed to mismatch. That's normal with
248248
/// GameObject.Instantiate.
249249
/// </summary>
250-
public static void AssertSameHierarchy (
250+
public static void AssertSameHierarchy (
251251
GameObject expectedHierarchy, GameObject actualHierarchy,
252252
bool ignoreRootName = false, bool ignoreRootTransform = false)
253253
{

Assets/FbxExporters/Editor/UnitTests/FbxPrefabTest.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,6 @@ public void Init() {
164164
var prefabInstance = GameObject.Instantiate(m_original);
165165
var fbxPrefab = prefabInstance.AddComponent<FbxPrefab>();
166166
var fbxPrefabUtility = new FbxPrefabAutoUpdater.FbxPrefabUtility (fbxPrefab);
167-
168167
fbxPrefabUtility.SetSourceModel(m_source);
169168
fbxPrefabUtility.SetAutoUpdate(true);
170169
m_autoPrefab = PrefabUtility.CreatePrefab(

0 commit comments

Comments
 (0)