public override void NewFrameStarting(RecordingSession session)
        {
            switch (adamSettings.source)
            {
            case EImageSource.GameDisplay:
            {
                // Find all cameras targetting Display
                foreach (var cam in Resources.FindObjectsOfTypeAll <Camera>())
                {
                    var hookedCam = m_hookedCameras.Find((x) => cam == x.camera);
                    if (hookedCam != null)
                    {
                        // Should we keep it?
                        if (cam.targetDisplay != 0 || !cam.enabled)
                        {
                            cam.targetTexture = hookedCam.textureBackup;
                            m_hookedCameras.Remove(hookedCam);
                        }
                        continue;
                    }

                    if (!cam.enabled || cam.targetDisplay != 0)
                    {
                        continue;
                    }

                    hookedCam = new HookedCamera()
                    {
                        camera = cam, textureBackup = cam.targetTexture
                    };
                    cam.targetTexture = m_renderRT;
                    m_hookedCameras.Add(hookedCam);
                }
                break;
            }

            case EImageSource.MainCamera:
            {
                var cam = Camera.main;
                if (m_hookedCameras.Count > 0)
                {
                    if (m_hookedCameras[0].camera != cam)
                    {
                        m_hookedCameras[0].camera.targetTexture = m_hookedCameras[0].textureBackup;
                        m_hookedCameras.Clear();
                    }
                    else
                    {
                        break;
                    }
                }
                if (!cam.enabled)
                {
                    break;
                }

                var hookedCam = new HookedCamera()
                {
                    camera = cam, textureBackup = cam.targetTexture
                };
                m_hookedCameras.Add(hookedCam);
                break;
            }

            case EImageSource.TaggedCamera:
                break;

            case EImageSource.RenderTexture:
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Ejemplo n.º 2
0
        protected internal override void NewFrameStarting(RecordingSession session)
        {
            switch (rtsSettings.source)
            {
            case ImageSource.ActiveCamera:
            {
                bool sort = false;

                // Find all cameras targetting Display
                foreach (var cam in Resources.FindObjectsOfTypeAll <Camera>())
                {
                    var hookedCam = m_hookedCameras.Find((x) => cam == x.camera);
                    if (hookedCam != null)
                    {
                        // Should we keep it?
                        if (cam.targetDisplay != 0 || !cam.enabled)
                        {
                            UnityHelpers.Destroy(cam.targetTexture);
                            cam.targetTexture = hookedCam.textureBackup;
                            m_hookedCameras.Remove(hookedCam);
                        }
                        continue;
                    }

                    if (!cam.enabled || !cam.gameObject.activeInHierarchy || cam.targetDisplay != 0)
                    {
                        continue;
                    }

                    hookedCam = new HookedCamera()
                    {
                        camera = cam, textureBackup = cam.targetTexture
                    };
                    var camRT = new RenderTexture((int)(m_renderWidth * cam.rect.width), (int)(m_renderHeight * cam.rect.height), 24, RenderTextureFormat.DefaultHDR, RenderTextureReadWrite.Linear);
                    cam.targetTexture = camRT;
                    m_hookedCameras.Add(hookedCam);
                    sort = true;
                }

                if (sort)
                {
                    m_hookedCameras.Sort((x, y) => x.camera.depth <y.camera.depth ? -1 : x.camera.depth> y.camera.depth ? 1 : 0);
                }
                break;
            }

            case ImageSource.MainCamera:
            {
                var cam = Camera.main;
                if (m_hookedCameras.Count > 0)
                {
                    if (m_hookedCameras[0].camera != cam)
                    {
                        m_hookedCameras[0].camera.targetTexture = m_hookedCameras[0].textureBackup;
                        m_hookedCameras.Clear();
                    }
                    else
                    {
                        break;
                    }
                }
                if (!cam.enabled)
                {
                    break;
                }

                var hookedCam = new HookedCamera()
                {
                    camera = cam, textureBackup = cam.targetTexture
                };
                cam.targetTexture = m_renderRT;
                m_hookedCameras.Add(hookedCam);
                break;
            }

            case ImageSource.TaggedCamera:
            {
                GameObject[] taggedObjs;
                var          tag = (settings as RenderTextureSamplerSettings).CameraTag;
                try
                {
                    taggedObjs = GameObject.FindGameObjectsWithTag(tag);
                }
                catch (UnityException)
                {
                    Debug.LogWarning("No camera has the requested target tag:" + tag);
                    taggedObjs = new GameObject[0];
                }

                // Remove un-tagged cameras form list
                for (int i = m_hookedCameras.Count - 1; i >= 0; i--)
                {
                    if (!m_hookedCameras[i].camera.gameObject.CompareTag(tag))
                    {
                        // un-hook it
                        m_hookedCameras[i].camera.targetTexture = m_hookedCameras[i].textureBackup;
                        m_hookedCameras.RemoveAt(i);
                    }
                }

                // Add newly tagged cameras
                foreach (var t in taggedObjs)
                {
                    var found = false;
                    var cam   = t.transform.GetComponent <Camera>();
                    if (cam != null && cam.enabled)
                    {
                        if (m_hookedCameras.Any(t1 => t1.camera == t.transform.GetComponent <Camera>()))
                        {
                            found = true;
                        }

                        if (!found)
                        {
                            var hookedCam = new HookedCamera {
                                camera = cam, textureBackup = cam.targetTexture
                            };
                            cam.targetTexture = m_renderRT;
                            m_hookedCameras.Add(hookedCam);
                        }
                    }
                }
                break;
            }

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Ejemplo n.º 3
0
        public override void NewFrameStarting(RecordingSession session)
        {
            switch (adamSettings.source)
            {
            case EImageSource.GameDisplay:
            {
                bool sort = false;

                // Find all cameras targetting Display
                foreach (var cam in Resources.FindObjectsOfTypeAll <Camera>())
                {
                    var hookedCam = m_hookedCameras.Find((x) => cam == x.camera);
                    if (hookedCam != null)
                    {
                        // Should we keep it?
                        if (cam.targetDisplay != 0 || !cam.enabled)
                        {
                            UnityHelpers.Destroy(cam.targetTexture);
                            cam.targetTexture = hookedCam.textureBackup;
                            m_hookedCameras.Remove(hookedCam);
                        }
                        continue;
                    }

                    if (!cam.enabled || !cam.gameObject.activeInHierarchy || cam.targetDisplay != 0)
                    {
                        continue;
                    }

                    hookedCam = new HookedCamera()
                    {
                        camera = cam, textureBackup = cam.targetTexture
                    };
                    var camRT = new RenderTexture((int)(m_renderWidth * cam.rect.width), (int)(m_renderHeight * cam.rect.height), 24, RenderTextureFormat.DefaultHDR, RenderTextureReadWrite.Linear);
                    cam.targetTexture = camRT;
                    m_hookedCameras.Add(hookedCam);
                    sort = true;
                }

                if (sort)
                {
                    m_hookedCameras = m_hookedCameras.OrderBy(x => x.camera.depth).ToList();
                }
                break;
            }

            case EImageSource.MainCamera:
            {
                var cam = Camera.main;
                if (m_hookedCameras.Count > 0)
                {
                    if (m_hookedCameras[0].camera != cam)
                    {
                        m_hookedCameras[0].camera.targetTexture = m_hookedCameras[0].textureBackup;
                        m_hookedCameras.Clear();
                    }
                    else
                    {
                        break;
                    }
                }
                if (!cam.enabled)
                {
                    break;
                }

                var hookedCam = new HookedCamera()
                {
                    camera = cam, textureBackup = cam.targetTexture
                };
                cam.targetTexture = m_renderRT;
                m_hookedCameras.Add(hookedCam);
                break;
            }

            case EImageSource.TaggedCamera:
                break;

            case EImageSource.RenderTexture:
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }