Skip to content

Commit 7f174c2

Browse files
authored
Merge pull request #222 from Unity-Technologies/UNI-30583-hide-disabled-gameobjects-in-fbx
UNI-30583 set visibility of fbx nodes according to whether the GO is enabled
2 parents 13dd119 + 21fd8e1 commit 7f174c2

File tree

3 files changed

+67
-1
lines changed

3 files changed

+67
-1
lines changed

Assets/FbxExporters/Editor/FbxExporter.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -944,6 +944,8 @@ protected int ExportComponents (
944944
return -1;
945945
}
946946

947+
fbxNode.SetVisibility (unityGo.activeSelf);
948+
947949
ExportTransform ( unityGo.transform, fbxNode, newCenter, exportType);
948950

949951
// try export mesh

Assets/FbxExporters/Editor/UnitTests/IntegrationsTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public void BasicTest() {
4141
LogNonEmptyString ("display name", mayaIntegration.DccDisplayName);
4242
LogNonEmptyString ("integration zip path", mayaIntegration.IntegrationZipPath);
4343

44-
Assert.IsFalse (Editor.MayaIntegration.IsHeadlessInstall ());
44+
Assert.IsFalse (Editor.MayaIntegration.IsHeadlessInstall () == 0);
4545

4646
LogNonEmptyString ("module template path", mayaIntegration.GetModuleTemplatePath ());
4747
LogNonEmptyString ("package path", Editor.MayaIntegration.GetPackagePath ());

Assets/FbxExporters/Editor/UnitTests/ModelExporterTest.cs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,5 +376,69 @@ private void CompareCameraValues(Camera camera, Camera fbxCamera, float delta=0.
376376
Assert.AreEqual (camera.nearClipPlane, fbxCamera.nearClipPlane, delta);
377377
Assert.AreEqual (camera.farClipPlane, fbxCamera.farClipPlane, delta);
378378
}
379+
380+
[Test]
381+
public void TestNodeVisibility()
382+
{
383+
// create test hierarchy
384+
// root (enabled)
385+
// -- parent1 (enabled)
386+
// ---- child3 (disabled)
387+
// -- parent2 (disabled)
388+
// ---- child1 (disabled)
389+
// ---- child2 (enabled)
390+
391+
var root = GameObject.CreatePrimitive(PrimitiveType.Cube);
392+
root.name = "root";
393+
var parent1 = GameObject.CreatePrimitive(PrimitiveType.Cube);
394+
parent1.name = "parent1";
395+
var parent2 = GameObject.CreatePrimitive(PrimitiveType.Cube);
396+
parent2.name = "parent2";
397+
var child1 = GameObject.CreatePrimitive(PrimitiveType.Cube);
398+
child1.name = "child1";
399+
var child2 = GameObject.CreatePrimitive(PrimitiveType.Cube);
400+
child2.name = "child2";
401+
var child3 = GameObject.CreatePrimitive (PrimitiveType.Cube);
402+
child3.name = "child3";
403+
404+
parent1.transform.SetParent (root.transform);
405+
parent2.transform.SetParent (root.transform);
406+
child1.transform.SetParent (parent2.transform);
407+
child2.transform.SetParent (parent2.transform);
408+
child3.transform.SetParent (parent1.transform);
409+
410+
root.SetActive (true);
411+
parent1.SetActive (true);
412+
child2.SetActive (true);
413+
parent2.SetActive (false);
414+
child1.SetActive (false);
415+
child3.SetActive (false);
416+
417+
string filename = GetRandomFbxFilePath ();
418+
ModelExporter.ExportObject (filename, root);
419+
420+
GameObject fbxObj = AssetDatabase.LoadMainAssetAtPath (filename) as GameObject;
421+
422+
// check root
423+
CheckObjectVisibility (fbxObj, true);
424+
425+
// check child nodes
426+
foreach (Transform child in fbxObj.transform) {
427+
var isParent1 = child.name.Equals ("parent1");
428+
CheckObjectVisibility (child.gameObject, isParent1);
429+
430+
// all children should be disabled
431+
foreach (Transform c in child) {
432+
CheckObjectVisibility (c.gameObject, false);
433+
}
434+
}
435+
}
436+
437+
private void CheckObjectVisibility(GameObject obj, bool expectedVisibility){
438+
Assert.IsTrue (obj.activeSelf);
439+
var renderer = obj.GetComponent<MeshRenderer> ();
440+
Assert.IsNotNull (renderer);
441+
Assert.AreEqual(expectedVisibility, renderer.enabled);
442+
}
379443
}
380444
}

0 commit comments

Comments
 (0)