Skip to content

Commit a1846c2

Browse files
author
Benoit Hudson
committed
Nicer logging.
1 parent 65744e8 commit a1846c2

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

Assets/FbxExporters/FbxPrefab.cs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,22 @@ public class FbxPrefab : MonoBehaviour
4444
// component is really only about the editor.
4545
#if UNITY_EDITOR
4646

47+
/// <summary>
48+
/// Utility function: log a message, make clear it's the prefab update.
49+
/// </summary>
50+
[System.Diagnostics.Conditional("FBXEXPORTER_DEBUG")]
51+
public static void Log(string message) {
52+
Debug.Log("Fbx prefab update: " + message);
53+
}
54+
55+
[System.Diagnostics.Conditional("FBXEXPORTER_DEBUG")]
56+
public static void Log(string format, params object[] p) {
57+
Log(string.Format(format, p));
58+
}
59+
4760
/// <summary>
4861
/// Utility function: create the object, which must be null.
4962
/// </summary>
50-
/// <param name="item">Item.</param>
51-
/// <typeparam name="T">The 1st type parameter.</typeparam>
5263
public static void Initialize<T>(ref T item) where T: new()
5364
{
5465
if (item != null) { throw new FbxPrefabException(); }
@@ -577,7 +588,6 @@ void ClassifyComponents(Transform newFbx)
577588
builder.AppendFormat("\t{0}:{1}\n", name, typename);
578589
Append(ref components, name, typename, component);
579590
}
580-
Debug.Log("Component map:\n" + builder.ToString());
581591

582592
// What's the logic?
583593
// First check if a component is present or absent. It's
@@ -623,9 +633,6 @@ void ClassifyComponents(Transform newFbx)
623633
var newValues = m_new.GetComponentValues(name, typename);
624634
var prefabValues = m_prefab.GetComponentValues(name, typename);
625635

626-
Debug.Log(string.Format("{4} - type {0}: {1} old / {2} new / {3} prefab",
627-
typename, oldValues.Count, newValues.Count, prefabValues.Count, name));
628-
629636
// TODO: handle multiplicity! The algorithm is eluding me right now...
630637
// We'll need to do some kind of 3-way matching.
631638
if (oldValues.Count > 1) { Debug.LogError("TODO: handle multiplicity " + oldValues.Count); }
@@ -649,7 +656,6 @@ void ClassifyComponents(Transform newFbx)
649656
// if oldValue != prefabValue, conflict =>
650657
// resolve in favor of Chris, so update
651658
// anyway.
652-
Debug.Log(string.Format("{0}\n{1}\nDiffer", oldValue, newValue));
653659
Append(ref typesToUpdate, typename);
654660
}
655661
}
@@ -738,7 +744,7 @@ public void ImplementUpdates(FbxPrefab prefabInstance)
738744
// Create new nodes.
739745
foreach(var name in m_nodesToCreate) {
740746
prefabNodes.Add(name, new GameObject(name).transform);
741-
Debug.Log(name + ": Created");
747+
Log("{0}: created new GameObject", name);
742748
}
743749

744750
// Implement the reparenting in two phases to avoid making loops, e.g.
@@ -762,13 +768,13 @@ public void ImplementUpdates(FbxPrefab prefabInstance)
762768
parentNode = prefabNodes[parent];
763769
}
764770
prefabNodes[name].parent = parentNode;
765-
Debug.Log(name + ": Changed parent to " + parentNode.name);
771+
Log("changed {0} parent to {1}", name, parentNode.name);
766772
}
767773

768774
// Destroy the old nodes.
769775
foreach(var toDestroy in m_nodesToDestroy) {
770776
GameObject.DestroyImmediate(prefabNodes[toDestroy].gameObject);
771-
Debug.Log(toDestroy + ": Destroyed");
777+
Log("destroyed {0}", toDestroy);
772778
}
773779

774780
// Destroy the old components.
@@ -781,7 +787,7 @@ public void ImplementUpdates(FbxPrefab prefabInstance)
781787
var component = xfo.GetComponent(componentType);
782788
if (component != null) {
783789
Object.DestroyImmediate(component);
784-
Debug.Log(name + ": Destroyed obsolete component " + componentType);
790+
Log("destroyed component {0}:{1}", xfo.name, componentType);
785791
}
786792
}
787793
}
@@ -806,14 +812,14 @@ public void ImplementUpdates(FbxPrefab prefabInstance)
806812
// Now update it.
807813
if (UnityEditorInternal.ComponentUtility.CopyComponent(fbxComponent)) {
808814
UnityEditorInternal.ComponentUtility.PasteComponentValues(prefabComponent);
809-
Debug.Log(name + ": updated component " + fbxComponent.GetType());
815+
Log("updated component {0}:{1}", name, fbxComponent.GetType());
810816

811817
}
812818
} else {
813819
// We didn't find a match, so create the component as new.
814820
if (UnityEditorInternal.ComponentUtility.CopyComponent(fbxComponent)) {
815821
UnityEditorInternal.ComponentUtility.PasteComponentAsNew(prefabXfo.gameObject);
816-
Debug.Log(name + ": added component " + fbxComponent.GetType());
822+
Log("added new component {0}:{1}", name, fbxComponent.GetType());
817823
}
818824
}
819825
}

0 commit comments

Comments
 (0)