Skip to content

Commit

Permalink
Merge pull request #10 from YousicianGit/feature/ObjectGraph
Browse files Browse the repository at this point in the history
Print meaningful object graph for Unity components
  • Loading branch information
Nezz authored Jan 22, 2025
2 parents ea4413e + 671a4ed commit 6cbc457
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,28 @@ public string GetObjectGraphString()
result.AppendLine(context.ObjectType.PrettyName());
}

#if !NOT_UNITY3D
if (this.ObjectInstance is UnityEngine.Component component)
{
// Print the GameObject hierarchy
var transform = component.transform;
while (transform != null)
{
if (transform.name.EndsWith("(Clone)"))
{
// Stop printing when we find an instantiated object, we are validating that prefab
result.AppendLine(transform.name.Replace("(Clone)", " (prefab)"));
break;
}
else
{
result.AppendLine(transform.name);
transform = transform.parent;
}
}
}
#endif

return result.ToString();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ public DiContainer CreateSubContainer(List<TypeValuePair> args, InjectContext co
if (_subContainer == null)
{
#if !ZEN_MULTITHREADING
Assert.That(!_isLookingUp,
"Found unresolvable circular dependency when looking up sub container! Object graph:\n {0}", context.GetObjectGraphString());
if (this._isLookingUp)
{
Assert.That(false, "Found unresolvable circular dependency when looking up sub container! Object graph:\n {0}", context.GetObjectGraphString());
}
_isLookingUp = true;
#endif

Expand All @@ -48,7 +50,7 @@ public DiContainer CreateSubContainer(List<TypeValuePair> args, InjectContext co

Assert.IsNotNull(_subContainer);
}
else
else
{
injectAction = null;
}
Expand Down

0 comments on commit 6cbc457

Please sign in to comment.