private void VerifyGameObjectHierarchy(GameObject go, GameObjectHierarchyNode hierarchy) { Assert.AreEqual(hierarchy.name, go.name); Assert.AreEqual(hierarchy.children.Length, go.transform.childCount); var components = go.GetComponents(typeof(Component)); Assert.LessOrEqual(hierarchy.componentType.Length, components.Length); foreach (var component in hierarchy.componentType) { Assert.NotNull(components.SingleOrDefault(x => x.GetType() == component)); } for (int i = 0; i < go.transform.childCount; ++i) { var child = go.transform.GetChild(i).gameObject; var childHierarchy = hierarchy.children.FirstOrDefault(x => x.name == child.name); VerifyGameObjectHierarchy(child, childHierarchy); } }
public void PSBImportProduceGameObjectWithCorrectHierarchy() { var testAssetPath = CopyTestAssetFile(); var importer = AssetImporter.GetAtPath(testAssetPath); var so = new SerializedObject(importer); so.FindProperty("m_MosaicLayers").boolValue = true; so.FindProperty("m_CharacterMode").boolValue = true; var textureImporterSettingsSP = so.FindProperty("m_TextureImporterSettings"); textureImporterSettingsSP.FindPropertyRelative("m_TextureType").intValue = (int)TextureImporterType.Sprite; textureImporterSettingsSP.FindPropertyRelative("m_SpriteMode").intValue = (int)SpriteImportMode.Multiple; so.ApplyModifiedPropertiesWithoutUndo(); importer.SaveAndReimport(); var prefab = AssetDatabase.LoadAssetAtPath <GameObject>(testAssetPath); Assert.NotNull(prefab); var expectedGOHierarchy = new GameObjectHierarchyNode { name = "TestPSB", componentType = new[] { typeof(Transform) }, children = new[] { new GameObjectHierarchyNode() { name = "Green", componentType = new[] { typeof(Transform), typeof(SpriteRenderer) }, children = new GameObjectHierarchyNode[0] }, new GameObjectHierarchyNode() { name = "Blue", componentType = new[] { typeof(Transform), typeof(SpriteRenderer) }, children = new GameObjectHierarchyNode[0] }, new GameObjectHierarchyNode() { name = "Pink", componentType = new[] { typeof(Transform), typeof(SpriteRenderer) }, children = new GameObjectHierarchyNode[0] }, new GameObjectHierarchyNode() { name = "Black", componentType = new[] { typeof(Transform), typeof(SpriteRenderer), typeof(SpriteSkin) }, children = new GameObjectHierarchyNode[0] }, new GameObjectHierarchyNode() { name = "bone_1", componentType = new[] { typeof(Transform) }, children = new[] { new GameObjectHierarchyNode() { name = "bone_2", componentType = new[] { typeof(Transform) }, children = new[] { new GameObjectHierarchyNode() { name = "bone_3", componentType = new[] { typeof(Transform) }, children = new GameObjectHierarchyNode[0] } } } } }, } }; VerifyGameObjectHierarchy(prefab, expectedGOHierarchy); }