Skip to content

Commit 9f5ebdd

Browse files
ImageSequenceRecorder added
1 parent 42b3600 commit 9f5ebdd

6 files changed

Lines changed: 97 additions & 6 deletions

Editor/BezierPathEditor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ static BezierPathEditor()
1919

2020
private static void UndoRedoPerformed()
2121
{
22-
foreach ( BezierPath path in FindObjectsOfType<BezierPath>())
22+
foreach ( BezierPath path in FindObjectsByType(typeof(BezierPath), FindObjectsSortMode.None))
2323
{
2424
path.RefreshChildIndices();
2525
}

Editor/HideFlagsUtility.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public static class HideFlagsUtility
77
[MenuItem("Edit/Hide Flags/Show All In Hierarchy")]
88
private static void ShowAll()
99
{
10-
var allGameObjects = Object.FindObjectsOfType<GameObject>();
10+
var allGameObjects = Editor.FindObjectsByType(typeof(GameObject), FindObjectsSortMode.None);
1111
List<Object> newSelection = new List<Object>();
1212
int shown = 0;
1313
foreach (var go in allGameObjects)
@@ -39,7 +39,7 @@ private static void HideSelected()
3939
[MenuItem("Edit/Hide Flags/Log Hidden Objects")]
4040
private static void LogHidden()
4141
{
42-
var allGameObjects = Object.FindObjectsOfType<GameObject>();
42+
var allGameObjects = Editor.FindObjectsByType(typeof(GameObject), FindObjectsSortMode.None);
4343
int hiddenFound = 0;
4444

4545
foreach (var go in allGameObjects)

Editor/ImageSequenceRecorder.cs

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using UnityEngine;
5+
#if UNITY_EDITOR && RECORDER_AVAILABLE
6+
using UnityEditor.Recorder;
7+
using UnityEditor.Recorder.Input;
8+
#endif
9+
10+
namespace Wrj
11+
{
12+
public class ImageSequenceRecorder
13+
{
14+
#if UNITY_EDITOR && RECORDER_AVAILABLE
15+
static RecorderController m_RecorderController;
16+
static RecorderController recorderController
17+
{
18+
get
19+
{
20+
if (m_RecorderController == null)
21+
{
22+
var controllerSettings = ScriptableObject.CreateInstance<RecorderControllerSettings>();
23+
m_RecorderController = new RecorderController(controllerSettings);
24+
}
25+
return m_RecorderController;
26+
}
27+
}
28+
#endif
29+
static public void StartRecording(string recordingName, int framerate = 30)
30+
{
31+
#if UNITY_EDITOR && RECORDER_AVAILABLE
32+
StopRecording();
33+
34+
var mediaOutputFolder = Path.Combine(Application.dataPath, "..", "Recordings");
35+
// Image Sequence
36+
var imageRecorder = ScriptableObject.CreateInstance<ImageRecorderSettings>();
37+
imageRecorder.name = "ImageSequenceRecorder";
38+
imageRecorder.Enabled = true;
39+
40+
imageRecorder.OutputFormat = ImageRecorderSettings.ImageRecorderOutputFormat.PNG;
41+
imageRecorder.CaptureAlpha = false;
42+
imageRecorder.FrameRate = framerate;
43+
imageRecorder.FrameRatePlayback = FrameRatePlayback.Constant;
44+
imageRecorder.CapFrameRate = true;
45+
46+
imageRecorder.OutputFile = Path.Combine(mediaOutputFolder, recordingName) + "_" + DefaultWildcard.Frame;
47+
48+
imageRecorder.imageInputSettings = new GameViewInputSettings
49+
{
50+
OutputWidth = Screen.width,
51+
OutputHeight = Screen.height
52+
};
53+
54+
// Setup Recording
55+
recorderController.Settings.AddRecorderSettings(imageRecorder);
56+
recorderController.Settings.SetRecordModeToManual();
57+
RecorderOptions.VerboseMode = false;
58+
59+
try
60+
{
61+
recorderController.PrepareRecording();
62+
recorderController.StartRecording();
63+
}
64+
catch (System.Exception e)
65+
{
66+
Debug.LogError(e);
67+
}
68+
#else
69+
Debug.LogError("Recorder package not found. Install it via Package Manager.");
70+
#endif
71+
}
72+
73+
static public void StopRecording()
74+
{
75+
#if UNITY_EDITOR && RECORDER_AVAILABLE
76+
if (m_RecorderController != null && m_RecorderController.IsRecording())
77+
{
78+
m_RecorderController.StopRecording();
79+
}
80+
#endif
81+
}
82+
}
83+
}

Editor/ImageSequenceRecorder.cs.meta

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Editor/PaletteGenerator.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,6 @@ private bool ProcessCode(string code)
382382
}
383383
return true;
384384
}
385-
return false;
386385
}
387386
private string[] ExtractTagLines(string tag, string code)
388387
{

Editor/wrj.utils.editor.asmdef

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
"name": "wrj.utils.editor",
33
"rootNamespace": "Wrj",
44
"references": [
5-
"wrj.utils"
5+
"wrj.utils",
6+
"Unity.Recorder.Editor"
67
],
78
"includePlatforms": [
89
"Editor"
@@ -13,6 +14,12 @@
1314
"precompiledReferences": [],
1415
"autoReferenced": true,
1516
"defineConstraints": [],
16-
"versionDefines": [],
17+
"versionDefines": [
18+
{
19+
"name": "com.unity.recorder",
20+
"expression": "",
21+
"define": "RECORDER_AVAILABLE"
22+
}
23+
],
1724
"noEngineReferences": false
1825
}

0 commit comments

Comments
 (0)