示例#1
0
 internal void OnBeforeBackgroundCameraRender(CompositeRenderContext compositeRenderContext)
 {
     if (BeforeBackgroundCameraRender != null)
     {
         BeforeBackgroundCameraRender.Invoke(compositeRenderContext);
     }
 }
示例#2
0
        /// <summary>
        /// Removes the GameView from being used in the composite render module
        /// and disposes of the CompositeRenderContext for that view.
        /// </summary>
        void TearDownGameView()
        {
            m_MarsSessionCamera = null;

            if (m_SessionRenderContext != null)
            {
                m_SessionRenderContext.Dispose();
                m_SessionRenderContext = null;
            }
        }
示例#3
0
        /// <summary>
        /// Removes a view from being used in the composite render module
        /// and disposes of the CompositeRenderContext for that view.
        /// </summary>
        /// <param name="scriptableObject">ScriptableObject to be removed.</param>
        /// <param name="compositeRenderContext">The render context to remove.</param>
        /// <param name="removeFromCollection">Should the view be removed from the collection.</param>
        void RemoveView(ScriptableObject scriptableObject, CompositeRenderContext compositeRenderContext, bool removeFromCollection)
        {
            m_SimulationSceneModule?.UnregisterSimulationUser(scriptableObject);

            compositeRenderContext?.Dispose();

            if (!removeFromCollection)
            {
                m_CompositeViewRenderContexts.Remove(scriptableObject);
            }
        }
示例#4
0
        public void AddView(ScriptableObject scriptableObject)
        {
            var environmentLayerMask = SimulationConstants.SimulatedEnvironmentLayerMask;
            CompositeRenderContext compositeRenderContext;

            if (scriptableObject is ICompositeView compositeView)
            {
                compositeRenderContext = new CompositeRenderContext(compositeView.ContextViewType,
                                                                    compositeView.TargetCamera, compositeView.CameraTargetDescriptor, compositeView.BackgroundColor,
                                                                    environmentLayerMask, compositeView.ShowImageEffects, compositeView.BackgroundSceneActive,
                                                                    compositeView.DesaturateComposited, compositeView.UseXRay);

                if (!Application.isPlaying)
                {
                    m_SimulationSceneModule?.RegisterSimulationUser(scriptableObject);
                }
            }
            else if (scriptableObject is SceneView sceneView)
            {
                var simView   = scriptableObject as SimulationView;
                var isSimView = simView != null;

                compositeRenderContext = new CompositeRenderContext(isSimView ? ContextViewType.SimulationView : ContextViewType.NormalSceneView,
                                                                    sceneView.camera, sceneView.GetSceneTargetTexture() != null ? sceneView.GetSceneTargetTexture().descriptor : new RenderTextureDescriptor(),
                                                                    SimulationView.EditorBackgroundColor, environmentLayerMask, isSimView && sceneView.sceneViewState.showImageEffects,
                                                                    isSimView && simView.EnvironmentSceneActive, isSimView && simView.DesaturateInactive,
                                                                    isSimView ? simView.UseXRay : true);

                if (isSimView)
                {
                    compositeRenderContext.BeforeCompositeCameraUpdate += simView.UpdateCamera;

                    // Simulation view should not try to open a simulation in play mode.
                    // This is handled in MonoBehaviour Awake of the MARSSession.
                    if (!Application.isPlaying)
                    {
                        m_SimulationSceneModule?.RegisterSimulationUser(scriptableObject);
                    }
                }
            }
            else
            {
                Debug.LogWarningFormat("{0} is not a Scene View or Contains ICompositeView! Cannot add to Composite View Module", scriptableObject.name);
                return;
            }

            compositeRenderContext.CompositeLayerMask = environmentLayerMask;
            m_CompositeViewRenderContexts.Add(scriptableObject, compositeRenderContext);
        }
示例#5
0
        /// <summary>
        /// Sets up a GameView for composite rendering of the content and simulation environment.
        /// </summary>
        /// <param name="camera">Game view main camera</param>
        void SetupGameView(Camera camera)
        {
            // Game view is a special case since it GameView is an internal class
            // so we cannot associate a Scriptable object as the parent of the context
            m_MarsSessionCamera = camera;

            // This is to fix an issue with the camera texture flipping in the composite of the game view.
            // The issue is only present on OSX using Metal rendering
            // and may not be needed in a later version of the editor.
#if UNITY_EDITOR_OSX
            if (SystemInfo.graphicsDeviceType == GraphicsDeviceType.Metal)
            {
                m_MarsSessionCamera.forceIntoRenderTexture = true;
            }
#endif

            var sessionCameraDescriptor = new RenderTextureDescriptor(camera.pixelWidth, camera.pixelHeight);
            m_SessionRenderContext = new CompositeRenderContext(ContextViewType.GameView, m_MarsSessionCamera,
                                                                sessionCameraDescriptor, Color.black, SimulationConstants.SimulatedEnvironmentLayerMask, true);
            m_SessionRenderContext.AssignCameraToSimulation();
            m_SessionRenderContext.CompositeLayerMask = SimulationConstants.SimulatedEnvironmentLayerMask;
        }
示例#6
0
        /// <summary>
        /// Try to get a Composite Render Context associated with the Scriptable Object
        /// from the active Composite Render Module.
        /// </summary>
        /// <param name="scriptableObject">Scriptable object we want the context for.</param>
        /// <param name="context">The Composite Render Context associated with the scriptable object.</param>
        /// <returns>Returns True if there is a context associated with the scriptable object.</returns>
        public static bool TryGetCompositeRenderContext(ScriptableObject scriptableObject, out CompositeRenderContext context)
        {
            context = null;
            if (!GetActiveCompositeRenderModule(out var renderModule))
            {
                return(false);
            }

            return(renderModule.m_CompositeViewRenderContexts.TryGetValue(scriptableObject, out context));
        }