Exemple #1
0
        void SaveRT(RenderTexture input)
        {
            if (input == null)
            {
                return;
            }

            var width  = input.width;
            var height = input.height;

            var tex          = new Texture2D(width, height, TextureFormat.RGBA32, false);
            var backupActive = RenderTexture.active;

            RenderTexture.active = input;
            tex.ReadPixels(new Rect(0, 0, width, height), 0, 0);
            tex.Apply();
            RenderTexture.active = backupActive;

            byte[] bytes;
            bytes = tex.EncodeToPNG();

            UnityHelpers.Destroy(tex);

            File.WriteAllBytes("Recorder/DebugDump.png", bytes);
        }
Exemple #2
0
        public void OnRecorderSelected()
        {
            if (m_Editor != null)
            {
                UnityHelpers.Destroy(m_Editor);
                m_Editor = null;
            }

            if (m_recorderSelector.selectedRecorder == null)
            {
                return;
            }

            if (m_WindowSettingsAsset.m_Settings != null && RecordersInventory.GetRecorderInfo(m_recorderSelector.selectedRecorder).settings != m_WindowSettingsAsset.m_Settings.GetType())
            {
                UnityHelpers.Destroy(m_WindowSettingsAsset.m_Settings, true);
                m_WindowSettingsAsset.m_Settings = null;
            }

            if (m_WindowSettingsAsset.m_Settings == null)
            {
                m_WindowSettingsAsset.m_Settings = RecordersInventory.GenerateNewSettingsAsset(m_WindowSettingsAsset, m_recorderSelector.selectedRecorder);
            }
            m_Editor = Editor.CreateEditor(m_WindowSettingsAsset.m_Settings) as RecorderEditor;
            AssetDatabase.Refresh();
        }
Exemple #3
0
 void ResetSettings()
 {
     UnityHelpers.Destroy(m_Editor);
     m_Editor           = null;
     m_recorderSelector = null;
     UnityHelpers.Destroy((target as RecorderClip).m_Settings, true);
 }
        public void OnRecorderSelected()
        {
            var clip = this.target as RecorderClip;

            if (m_Editor != null)
            {
                UnityHelpers.Destroy(m_Editor);
                m_Editor = null;
            }

            if (m_recorderSelector.selectedRecorder == null)
            {
                return;
            }

            if (clip.m_Settings != null && RecordersInventory.GetRecorderInfo(m_recorderSelector.selectedRecorder).settings != clip.m_Settings.GetType())
            {
                UnityHelpers.Destroy(clip.m_Settings, true);
                clip.m_Settings = null;
            }

            if (clip.m_Settings == null)
            {
                clip.m_Settings = RecordersInventory.GenerateNewSettingsAsset(clip, m_recorderSelector.selectedRecorder);
            }
            m_Editor = Editor.CreateEditor(clip.m_Settings) as RecorderEditor;
            AssetDatabase.Refresh();
        }
Exemple #5
0
        void OnRecorderSelected(Type selectedRecorder)
        {
            var clip = (RecorderClip)target;

            if (m_Editor != null)
            {
                UnityHelpers.Destroy(m_Editor);
                m_Editor = null;
            }

            if (selectedRecorder == null)
            {
                return;
            }

            if (clip.settings != null && RecordersInventory.GetRecorderInfo(selectedRecorder).settingsType != clip.settings.GetType())
            {
                UnityHelpers.Destroy(clip.settings, true);
                clip.settings = null;
            }

            if (clip.settings == null)
            {
                clip.settings = RecordersInventory.CreateDefaultRecorderSettings(selectedRecorder);

                AssetDatabase.AddObjectToAsset(clip.settings, clip);
                AssetDatabase.SaveAssets();
                AssetDatabase.Refresh();
            }

            m_Editor = (RecorderEditor)CreateEditorWithContext(new UnityObject[] { clip.settings }, SceneHook.GetRecorderBindings());
            AssetDatabase.Refresh();
        }
        void OnRecorderSelected(Type selectedRecorder)
        {
            var clip = (RecorderClip)target;

            if (m_Editor != null)
            {
                UnityHelpers.Destroy(m_Editor);
                m_Editor = null;
            }

            if (selectedRecorder == null)
            {
                return;
            }

            if (clip.settings != null && RecordersInventory.GetRecorderInfo(selectedRecorder).settingsType != clip.settings.GetType())
            {
                Undo.DestroyObjectImmediate(clip.settings);
                clip.settings = null;
            }

            if (clip.settings == null)
            {
                clip.settings = RecordersInventory.CreateDefaultRecorderSettings(selectedRecorder);
                Undo.RegisterCreatedObjectUndo(clip.settings, "Recorder Create Settings");
                AssetDatabase.AddObjectToAsset(clip.settings, clip);
            }

            m_Editor = (RecorderEditor)CreateEditor(clip.settings);
        }
Exemple #7
0
        /// <inheritdoc/>
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                m_InputStrategy.ReleaseCamera();
                UnityHelpers.Destroy(m_UICamera);

                if (m_ModifiedResolution)
                {
                    if (GameViewSize.modifiedResolutionCount > 0)
                    {
                        GameViewSize.modifiedResolutionCount--; // don't allow negative if called twice
                    }
                    if (GameViewSize.modifiedResolutionCount == 0)
                    {
                        GameViewSize.RestoreSize();
                    }
                }

                if (m_VFlipper != null)
                {
                    m_VFlipper.Dispose();
                }
            }

            base.Dispose(disposing);
        }
Exemple #8
0
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (m_hookedCameras != null)
                {
                    foreach (var c in m_hookedCameras)
                    {
                        if (c != null)
                        {
                            if (c.camera.rect.width == 1f && c.camera.rect.height == 1f)
                            {
                                UnityHelpers.Destroy(c.camera.targetTexture);
                            }
                            c.camera.targetTexture = c.textureBackup;
                        }
                    }
                    m_hookedCameras.Clear();
                }

                UnityHelpers.Destroy(m_renderRT);
                foreach (var rt in m_accumulateRTs)
                {
                    UnityHelpers.Destroy(rt);
                }
                UnityHelpers.Destroy(m_superMaterial);
                UnityHelpers.Destroy(m_accumulateMaterial);
                UnityHelpers.Destroy(m_normalizeMaterial);
            }

            base.Dispose(disposing);
        }
 void ResetSettings()
 {
     UnityHelpers.Destroy(m_Editor);
     m_Editor           = null;
     m_RecorderSelector = null;
     UnityHelpers.Destroy(((RecorderClip)target).settings, true);
 }
Exemple #10
0
 public virtual void ReleaseCamera()
 {
     UnityHelpers.Destroy(m_CopyMaterial);
     // Case REC-62 Multiple Recorder produce flipped content
     // Important to set m_CopyMaterial to null because the getter
     // might try to return a material that already was destroyed.
     m_CopyMaterial = null;
 }
Exemple #11
0
        /// <summary>
        ///
        /// </summary>
        public override void PreSetup()
        {
            if (this._manager == null)
            {
                this._manager = FindObjectOfType <AbstractNeodroidManager>();
            }

            if (this._camera == null)
            {
                this._camera = this.GetComponent <Camera>();
            }

            if (this._texture)
            {
                UnityHelpers.Destroy(this._texture);
            }

            if (this._manager?.SimulatorConfiguration?.SimulationType != SimulationType.Frame_dependent_)
            {
                if (this.disable_camera_when_unused)
                {
                    this._camera.enabled = false;
                }
            }

            var target_texture = this._camera.targetTexture;

            if (!target_texture)
            {
        #if NEODROID_DEBUG
                Debug.LogWarning($"RenderTexture target not available on {this.Identifier} not available, allocating a default!");
        #endif
                this._rt = new RenderTexture(NeodroidConstants._Default_Width,
                                             NeodroidConstants._Default_Height,
                                             0,
                                             RenderTextureFormat.ARGBFloat)
                {
                    filterMode        = FilterMode.Point,
                    name              = $"rt_{this.Identifier}",
                    enableRandomWrite = true
                };
                this._rt.Create();
                this._camera.targetTexture = this._rt;
                this._texture = new Texture2D(NeodroidConstants._Default_Width,
                                              NeodroidConstants._Default_Height,
                                              NeodroidConstants._Default_TextureFormat,
                                              false,
                                              this.linear_space);
            }
            else
            {
                this._texture = new Texture2D(target_texture.width,
                                              target_texture.height,
                                              target_texture.graphicsFormat,
                                              _flags);
            }
        }
Exemple #12
0
        protected internal override void EndRecording(RecordingSession session)
        {
            base.EndRecording(session);

            if (workTexture != null)
            {
                UnityHelpers.Destroy(workTexture);
                workTexture = null;
            }
        }
        public void OnGUI()
        {
            m_LastRepaint = DateTime.Now;

            // Bug? work arround: on Stop play, Enable is not called.
            if (m_Editor != null && m_Editor.target == null)
            {
                UnityHelpers.Destroy(m_Editor);
                m_Editor           = null;
                m_recorderSelector = null;
            }

            if (m_recorderSelector == null)
            {
                if (m_WindowSettingsAsset == null)
                {
                    var candidates = AssetDatabase.FindAssets("t:RecorderWindowSettings");
                    if (candidates.Length > 0)
                    {
                        var path = AssetDatabase.GUIDToAssetPath(candidates[0]);
                        m_WindowSettingsAsset = AssetDatabase.LoadAssetAtPath <RecorderWindowSettings>(path);
                    }
                    else
                    {
                        m_WindowSettingsAsset = ScriptableObject.CreateInstance <RecorderWindowSettings>();
                        AssetDatabase.CreateAsset(m_WindowSettingsAsset, "Assets/FrameRecordingSettings.asset");
                        AssetDatabase.SaveAssets();
                    }
                }

                m_recorderSelector = new RecorderSelector(OnRecorderSelected, true);
                m_recorderSelector.Init(m_WindowSettingsAsset.m_Settings, m_StartingCategory);
            }

            if (m_State == EState.WaitingForPlayModeToStartRecording && EditorApplication.isPlaying)
            {
                DelayedStartRecording();
            }

            using (new EditorGUI.DisabledScope(EditorApplication.isPlaying))
                m_recorderSelector.OnGui();

            if (m_Editor != null)
            {
                m_Editor.showBounds = true;
                using (new EditorGUI.DisabledScope(EditorApplication.isPlaying))
                {
                    EditorGUILayout.Separator();
                    m_Editor.OnInspectorGUI();
                    EditorGUILayout.Separator();
                }
                RecordButtonOnGui();
            }
        }
Exemple #14
0
 protected internal override void EndRecording(RecordingSession session)
 {
     base.EndRecording(session);
     if (m_ColorRT != null)
     {
         UnityHelpers.Destroy(m_ColorRT);
     }
     if (m_TempRT != null)
     {
         UnityHelpers.Destroy(m_TempRT);
     }
 }
Exemple #15
0
        protected internal override void EndRecording(RecordingSession session)
        {
            base.EndRecording(session);

            if (workTexture != null)
            {
                UnityHelpers.Destroy(workTexture);
                workTexture = null;
            }

            NeedToFlipVertically = null; // This variable is not valid anymore
        }
        protected void ChangeInputSettings(int atIndex, RecorderInputSetting newSettings)
        {
            newSettings.name = GUID.Generate().ToString();

            AssetDatabase.AddObjectToAsset(newSettings, serializedObject.targetObject);
            AssetDatabase.SaveAssets();

            var arryItem = m_Inputs.GetArrayElementAtIndex(atIndex);

            UnityHelpers.Destroy(arryItem.objectReferenceValue, true);
            arryItem.objectReferenceValue = newSettings;
        }
Exemple #17
0
        void ResetSettings()
        {
            UnityHelpers.Destroy(m_Editor);
            m_Editor           = null;
            m_recorderSelector = null;
            var path = AssetDatabase.GetAssetPath(m_WindowSettingsAsset);

            UnityHelpers.Destroy(m_WindowSettingsAsset, true);
            AssetDatabase.DeleteAsset(path);
            AssetDatabase.Refresh(ImportAssetOptions.Default);
            m_WindowSettingsAsset = null;
        }
Exemple #18
0
 void StopRecording()
 {
     if (m_Editor != null)
     {
         var settings = (RecorderSettings)m_Editor.target;
         if (settings != null)
         {
             var recorderGO = FrameRecorderGOControler.FindRecorder(settings);
             if (recorderGO != null)
             {
                 UnityHelpers.Destroy(recorderGO);
             }
         }
     }
 }
Exemple #19
0
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (m_Cubemap1)
                {
                    UnityHelpers.Destroy(m_Cubemap1);
                }

                if (m_Cubemap2)
                {
                    UnityHelpers.Destroy(m_Cubemap2);
                }
            }

            base.Dispose(disposing);
        }
Exemple #20
0
        public void ChangeInputSettings(int atIndex, RecorderInputSetting newSettings)
        {
            if (newSettings != null)
            {
                AssetDatabase.AddObjectToAsset(newSettings, serializedObject.targetObject);
                AssetDatabase.Refresh();

                var arryItem = m_Inputs.GetArrayElementAtIndex(atIndex);
                UnityHelpers.Destroy(arryItem.objectReferenceValue, true);
                arryItem.objectReferenceValue = newSettings;

                m_InputEditors[atIndex].settingsObj = newSettings;
            }
            else if (m_InputEditors.Count == 0)
            {
                throw new Exception("Source removal not implemented");
            }
        }
Exemple #21
0
        protected virtual void ReleaseCamera()
        {
            if (m_cbCopyFB != null)
            {
                if (m_Camera != null)
                {
                    m_Camera.RemoveCommandBuffer(CameraEvent.AfterEverything, m_cbCopyFB);
                }

                m_cbCopyFB.Release();
                m_cbCopyFB = null;
            }

            if (m_CopyMaterial != null)
            {
                UnityHelpers.Destroy(m_CopyMaterial);
            }
        }
        public override void OnInspectorGUI()
        {
            if (target == null)
            {
                return;
            }

            // Bug? work arround: on Stop play, Enable is not called.
            if (m_Editor != null && m_Editor.target == null)
            {
                UnityHelpers.Destroy(m_Editor);
                m_Editor           = null;
                m_recorderSelector = null;
            }

            if (m_recorderSelector == null)
            {
                m_recorderSelector = new RecorderSelector(OnRecorderSelected, false);
                m_recorderSelector.Init((target as RecorderClip).m_Settings);
            }

            m_recorderSelector.OnGui();

            if (m_Editor != null)
            {
                m_Editor.showBounds = false;
                m_Timeline          = FindTimelineAsset();

                PushTimelineIntoRecorder();

                using (new EditorGUI.DisabledScope(EditorApplication.isPlaying))
                {
                    EditorGUILayout.Separator();

                    m_Editor.OnInspectorGUI();

                    EditorGUILayout.Separator();

                    PushRecorderIntoTimeline();

                    serializedObject.Update();
                }
            }
        }
Exemple #23
0
        // Don't override in derived classes, override PostAwake instead
        void Awake( )
        {
            if (instance != null)
            {
                // The call to Instance will cache the instance static var
                if (!instance.Equals(this))
                {
                    Debug.LogWarning("Attempting to instantiate a second instance of application singleton of type " + typeof(GameObjectType).ToString( ) + "! Destroying it");
                    UnityHelpers.Destroy(gameObject);
                }
            }
            else
            {
#if DEBUG_SINGLETONS
                Debug.Log("Awaking application lazy singleton of type " + typeof(GameObjectType).ToString( ));
#endif //DEBUG_SINGLETONS
                PostAwake( );
            }
        }
        /// <summary>
        /// This is called when the Recorder Clip is being destroyed.
        /// For more information see: https://docs.unity3d.com/ScriptReference/ScriptableObject.OnDestroy.html
        /// </summary>
        public void OnDestroy()
        {
#if UNITY_EDITOR
            var path = AssetDatabase.GetAssetPath(this);
            if (string.IsNullOrEmpty(path))
            {
                return;
            }

            var objs = AssetDatabase.LoadAllAssetsAtPath(path);

            foreach (var obj in objs)
            {
                if (obj is RecorderClip rc && rc != this && rc.settings == settings)
                {
                    return;
                }
            }
            UnityHelpers.Destroy(settings, true);
#endif
        }
Exemple #25
0
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                ReleaseCamera();
                UnityHelpers.Destroy(m_UICamera);
#if UNITY_EDITOR
                if (m_ModifiedResolution)
                {
                    GameViewSize.m_ModifiedResolutionCount--;
                    if (GameViewSize.m_ModifiedResolutionCount == 0)
                    {
                        GameViewSize.RestoreSize();
                    }
                }
#endif
                if (m_VFlipper != null)
                {
                    m_VFlipper.Dispose();
                }
            }

            base.Dispose(disposing);
        }
Exemple #26
0
 public virtual void OnDestroy()
 {
     UnityHelpers.Destroy(m_Settings, true);
 }
Exemple #27
0
 public virtual void ReleaseCamera()
 {
     UnityHelpers.Destroy(m_CopyMaterial);
 }
Exemple #28
0
 public override void FrameDone(RecordingSession session)
 {
     UnityHelpers.Destroy(readbackTexture);
     readbackTexture = null;
 }
Exemple #29
0
 protected internal override void FrameDone(RecordingSession session)
 {
     UnityHelpers.Destroy(ReadbackTexture);
     ReadbackTexture = null;
 }
 public override void FrameDone(RecordingSession session)
 {
     UnityHelpers.Destroy(image);
     image = null;
 }