public void CloneWithHideFlags_NoChildren(HideFlags hideFlags) { m_GameObject = new GameObject { hideFlags = hideFlags }; m_GameObjectCopy = GameObjectUtils.CloneWithHideFlags(m_GameObject); Assert.AreEqual(m_GameObject.hideFlags, m_GameObjectCopy.hideFlags); }
public void CloneWithHideFlags_Children_DifferentFlags() { var hideFlagsCount = s_HideFlagsValues.Length; m_GameObject = new GameObject { hideFlags = s_HideFlagsValues[0] }; var originals = new GameObject[hideFlagsCount]; originals[0] = m_GameObject; for (var i = 1; i < hideFlagsCount; ++i) { var child = new GameObject { hideFlags = s_HideFlagsValues[i] }; child.transform.parent = originals[(i - 1) / k_ChildCount].transform; originals[i] = child; } m_GameObjectCopy = GameObjectUtils.CloneWithHideFlags(m_GameObject); CompareHideFlagsRecursively(m_GameObject, m_GameObjectCopy); }
public void CloneWithHideFlags_Children_SameFlags(HideFlags hideFlags) { m_GameObject = new GameObject { hideFlags = hideFlags }; for (var i = 0; i < k_ChildCount; ++i) { var child = new GameObject { hideFlags = hideFlags }; child.transform.parent = m_GameObject.transform; for (var j = 0; j < k_ChildCount; ++j) { var childChild = new GameObject { hideFlags = hideFlags }; childChild.transform.parent = child.transform; } } m_GameObjectCopy = GameObjectUtils.CloneWithHideFlags(m_GameObject); CompareHideFlagsRecursively(m_GameObject, m_GameObjectCopy); }
void CopySimulatablesToSimulationScene() { ProfilerMarkers.CopySimulatablesToSimulationScene.Begin(); // Destroy old copied objects and objects spawned by queries. DestroySimulatedObjectsRoot(); // If anything about the session changes in EnsureRuntimeState, it tries to dirty the simulatable scene // which would trigger another simulation. To prevent that we temporarily clear the delegate. EditorOnlyDelegates.DirtySimulatableScene = null; MARSSession.EnsureRuntimeState(); EditorOnlyDelegates.DirtySimulatableScene = DirtySimulatableScene; var session = MarsRuntimeUtils.GetMarsSessionInActiveScene(); // Find all the root game objects in the active scene and move them under a root transform. var activeScene = SceneManager.GetActiveScene(); k_RootGameObjects.Clear(); activeScene.GetRootGameObjects(k_RootGameObjects); SimulatedContentRoot = new GameObject(k_TemporaryRootName); SimulatedContentRoot.SetActive(false); foreach (var gameObject in k_RootGameObjects) { gameObject.transform.SetParent(SimulatedContentRoot.transform, true); } k_OriginalSimulatables.Clear(); SimulatedContentRoot.GetComponentsInChildren(k_OriginalSimulatables); k_OriginalTransforms.Clear(); SimulatedContentRoot.GetComponentsInChildren(k_OriginalTransforms); k_OriginalTransforms.RemoveAt(0); // Ignore the root // Copy the root transform to the simulated content scene. The reason we copy simulatables this way rather than // copying them individually is so that their references to other simulatables stay intact. var copiedSimulatedContentRoot = GameObjectUtils.CloneWithHideFlags(SimulatedContentRoot); copiedSimulatedContentRoot.name = k_SimulatedContentRootName; // After copying, we need to move original gameobjects back to the scene root. foreach (var gameObject in k_RootGameObjects) { gameObject.transform.SetParent(null, true); } UnityObjectUtils.Destroy(SimulatedContentRoot); SimulatedContentRoot = copiedSimulatedContentRoot; // Remove the copied MARS Session to avoid conflicts var copiedSession = SimulatedContentRoot.GetComponentInChildren(typeof(MARSSession)); UnityObjectUtils.Destroy(copiedSession); m_SimulationSceneModule.AddContentGameObject(SimulatedContentRoot); k_CopiedTransforms.Clear(); SimulatedContentRoot.GetComponentsInChildren(k_CopiedTransforms); k_CopiedTransforms.RemoveAt(0); // Ignore the root var copiedTransformsCount = k_CopiedTransforms.Count; Debug.Assert(k_OriginalTransforms.Count == copiedTransformsCount, "Copied Transforms in the simulation scene do not map 1:1 with original Transforms in the query scene."); m_OriginalToCopiedTransforms.Clear(); m_CopiedToOriginalTransforms.Clear(); for (var i = 0; i < copiedTransformsCount; ++i) { AddTransformCopy(k_CopiedTransforms[i], k_OriginalTransforms[i]); } m_SimulatableBehaviours.Clear(); k_CopiedSimulatables.Clear(); SimulatedContentRoot.GetComponentsInChildren(k_CopiedSimulatables); var copiedSimulatablesCount = k_CopiedSimulatables.Count; Debug.Assert(k_OriginalSimulatables.Count == copiedSimulatablesCount, "Copied ISimulatables in the simulation scene do not map 1:1 with original ISimulatables in the query scene."); m_CopiedToOriginalSimulatables.Clear(); m_OriginalToCopiedSimulatables.Clear(); m_LandmarkControllers.Clear(); for (var i = 0; i < copiedSimulatablesCount; i++) { var originalSimulatable = k_OriginalSimulatables[i]; var copiedSimulatable = k_CopiedSimulatables[i]; var behaviour = copiedSimulatable as MonoBehaviour; if (behaviour != null) { m_SimulatableBehaviours.Add(behaviour); } var landmarkController = originalSimulatable as LandmarkController; if (landmarkController) { m_LandmarkControllers[landmarkController] = (LandmarkController)copiedSimulatable; } AddSimulatedCopy(copiedSimulatable, originalSimulatable); } AddSyntheticEnvironmentSimulatedObjects(); EditorOnlyEvents.OnSetupSimulatables(m_SimulatableBehaviours); k_CopiedLights.Clear(); SimulatedContentRoot.GetComponentsInChildren(k_CopiedLights); // Content scene lights on shouldn't cast on the simulated environment foreach (var light in k_CopiedLights) { light.cullingMask &= ~(SimulationConstants.SimulatedEnvironmentLayerMask); } // Set up simulation camera at the device starting position // with the correct settings for rendering the sim scene var cameraReference = session.cameraReference; if (cameraReference == null) { cameraReference = session.GetComponentInChildren <MARSCamera>(true); if (cameraReference == null) { Debug.LogError("MARSSession does not have a MARSCamera"); return; } } var originalCamera = cameraReference.gameObject; var copiedCameraTrans = GetCopiedTransform(originalCamera.transform); var startingPose = m_EnvironmentManager.DeviceStartingPose; copiedCameraTrans.SetLocalPose(startingPose); SimulatedCamera = copiedCameraTrans.GetComponent <Camera>(); SimulatedCamera.cameraType = CameraType.SceneView; SimulatedCamera.tag = "Untagged"; // Copied camera should not be marked as the main camera SimulationSceneModule.instance.AssignCameraToSimulation(SimulatedCamera); // Disallow MSAA on copied camera to avoid tiled GPU perf warning // https://issuetracker.unity3d.com/issues/tiled-gpu-perf-warning-appears-when-multiple-cameras-with-allow-msaa-are-present-in-the-scene-and-viewport-rect-is-not-default SimulatedCamera.allowMSAA = false; SimulatedContentRoot.AddToHideFlagsRecursively(SimulatedObjectHideFlags); EntityVisualsModule.instance.simEntitiesRoot = SimulatedContentRoot.transform; SimulatedContentRoot.SetActive(true); foreach (var contentHierarchy in Resources.FindObjectsOfTypeAll <ContentHierarchyPanel>()) { contentHierarchy.RestoreState(); } ProfilerMarkers.CopySimulatablesToSimulationScene.End(); }