Skip to content

Commit 251b1b3

Browse files
committed
improved how input lists are handled.
added a shared implementation of render Texture input selector.
1 parent fb03191 commit 251b1b3

File tree

10 files changed

+158
-64
lines changed

10 files changed

+158
-64
lines changed

source/FrameRecorder/Core/Editor/InputEditor.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
52

63
namespace UnityEditor.FrameRecorder
74
{
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using System;
2+
using UnityEngine;
3+
using UnityEngine.FrameRecorder;
4+
using UnityEngine.FrameRecorder.Input;
5+
6+
namespace UnityEditor.FrameRecorder
7+
{
8+
public class RTInputSelector
9+
{
10+
public string title { get; set; }
11+
string[] candidates = { "Camera output", "Offscreen rendering", "Render Texture" };
12+
13+
public RTInputSelector(string title)
14+
{
15+
this.title = title;
16+
}
17+
18+
public bool OnInputGui( ref RecorderInputSetting input)
19+
{
20+
var index = input.GetType() == typeof(CBRenderTextureInputSettings) ? 0 :
21+
input.GetType() == typeof(AdamBeautyInputSettings) ? 1 : 2;
22+
var newIndex = EditorGUILayout.Popup("Collection method", index, candidates);
23+
24+
if (index != newIndex)
25+
{
26+
Type newType = null;
27+
switch (newIndex)
28+
{
29+
case 0:
30+
newType = typeof(CBRenderTextureInputSettings);
31+
break;
32+
case 1:
33+
newType = typeof(AdamBeautyInputSettings);
34+
break;
35+
case 2:
36+
newType = typeof(RenderTextureInputSettings);
37+
break;
38+
}
39+
var newSettings = ScriptableObject.CreateInstance(newType) as RecorderInputSetting;
40+
newSettings.m_DisplayName = title;
41+
input = newSettings;
42+
return true;
43+
}
44+
45+
return false;
46+
}
47+
}
48+
49+
}

source/FrameRecorder/Core/Editor/RTInputSelector.cs.meta

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

source/FrameRecorder/Core/Editor/RecorderEditor.cs

Lines changed: 68 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
using UnityEngine;
34
using UnityEngine.FrameRecorder;
45

@@ -13,8 +14,38 @@ public enum EFieldDisplayState
1314

1415
public abstract class RecorderEditor : Editor
1516
{
17+
protected class InputEditorState
18+
{
19+
InputEditor.IsFieldAvailableDelegate m_Validator;
20+
public bool visible;
21+
public Editor editor { get; private set; }
22+
23+
RecorderInputSetting m_SettingsObj;
24+
public RecorderInputSetting settingsObj
25+
{
26+
get { return m_SettingsObj; }
27+
set
28+
{
29+
m_SettingsObj = value;
30+
if( editor != null )
31+
UnityHelpers.Destroy(editor);
32+
33+
editor = Editor.CreateEditor(m_SettingsObj);
34+
if (editor is InputEditor)
35+
(editor as InputEditor).IsFieldAvailableForHost = m_Validator;
36+
}
37+
}
38+
39+
public InputEditorState(InputEditor.IsFieldAvailableDelegate validator, RecorderInputSetting settings)
40+
{
41+
m_Validator = validator;
42+
settingsObj = settings;
43+
}
44+
}
45+
protected List<InputEditorState> m_InputEditors;
46+
1647
protected SerializedProperty m_Inputs;
17-
bool[] m_ShowInputEditor;
48+
1849
SerializedProperty m_Verbose;
1950
SerializedProperty m_FrameRateMode;
2051
SerializedProperty m_FrameRate;
@@ -36,6 +67,7 @@ protected virtual void OnEnable()
3667
{
3768
if (target != null)
3869
{
70+
m_InputEditors = new List<InputEditorState>();
3971
m_FrameRateLabels = EnumHelper.MaskOutEnumNames<EFrameRate>(0xFFFF, (x) => FrameRateHelper.ToLable( (EFrameRate)x) );
4072

4173
var pf = new PropertyFinder<RecorderSettings>(serializedObject);
@@ -53,6 +85,11 @@ protected virtual void OnEnable()
5385
m_FrameRateExact = pf.Find(x => x.m_FrameRateExact);
5486
m_DestinationPath = pf.Find(w => w.m_DestinationPath);
5587
m_BaseFileName = pf.Find(w => w.m_BaseFileName);
88+
89+
foreach (var input in (target as RecorderSettings).m_SourceSettings)
90+
{
91+
m_InputEditors.Add( new InputEditorState(GetFieldDisplayState, input) { visible = true} );
92+
}
5693
}
5794
}
5895

@@ -103,18 +140,31 @@ protected void AddSourceSettings(RecorderInputSetting sourceSettings)
103140
m_Inputs.InsertArrayElementAtIndex(m_Inputs.arraySize);
104141
var arryItem = m_Inputs.GetArrayElementAtIndex(m_Inputs.arraySize-1);
105142
arryItem.objectReferenceValue = sourceSettings;
143+
144+
m_InputEditors.Add( new InputEditorState(GetFieldDisplayState, sourceSettings) { visible = true} );
145+
146+
serializedObject.ApplyModifiedProperties();
106147
}
107148

108-
protected void ChangeInputSettings(int atIndex, RecorderInputSetting newSettings)
149+
public void ChangeInputSettings(int atIndex, RecorderInputSetting newSettings)
109150
{
110-
newSettings.name = GUID.Generate().ToString();
151+
if (newSettings != null)
152+
{
153+
newSettings.name = GUID.Generate().ToString();
111154

112-
AssetDatabase.AddObjectToAsset(newSettings, serializedObject.targetObject);
113-
AssetDatabase.SaveAssets();
155+
AssetDatabase.AddObjectToAsset(newSettings, serializedObject.targetObject);
156+
AssetDatabase.SaveAssets();
114157

115-
var arryItem = m_Inputs.GetArrayElementAtIndex(atIndex);
116-
UnityHelpers.Destroy(arryItem.objectReferenceValue, true);
117-
arryItem.objectReferenceValue = newSettings;
158+
var arryItem = m_Inputs.GetArrayElementAtIndex(atIndex);
159+
UnityHelpers.Destroy(arryItem.objectReferenceValue, true);
160+
arryItem.objectReferenceValue = newSettings;
161+
162+
m_InputEditors[atIndex].settingsObj = newSettings;
163+
}
164+
else if(m_InputEditors.Count == 0)
165+
{
166+
throw new Exception("Source removal not implemented");
167+
}
118168
}
119169

120170
protected void PrepareInitialSources()
@@ -127,14 +177,6 @@ protected void PrepareInitialSources()
127177
{
128178
AddSourceSettings(newSetting);
129179
}
130-
}
131-
132-
if (m_ShowInputEditor == null || m_ShowInputEditor.Length != m_Inputs.arraySize)
133-
{
134-
var oldLength = m_ShowInputEditor == null ? 0 : m_ShowInputEditor.Length;
135-
m_ShowInputEditor = new bool[m_Inputs.arraySize];
136-
for (int i = oldLength; i < m_ShowInputEditor.Length; ++i)
137-
m_ShowInputEditor[i] = true;
138180
}
139181
}
140182

@@ -146,25 +188,22 @@ protected virtual void OnInputGui()
146188
if (multiInputs)
147189
{
148190
EditorGUI.indentLevel++;
149-
m_ShowInputEditor[i] =
150-
EditorGUILayout.Foldout(m_ShowInputEditor[i], "Input " + (i + 1));
151-
}
152-
var arrItem = m_Inputs.GetArrayElementAtIndex(i);
153-
if (m_ShowInputEditor[i])
154-
{
155-
var editor = Editor.CreateEditor(arrItem.objectReferenceValue);
156-
if (editor != null)
157-
{
158-
if (editor is InputEditor)
159-
(editor as InputEditor).IsFieldAvailableForHost = GetFieldDisplayState;
160-
editor.OnInspectorGUI();
161-
}
191+
m_InputEditors[i].visible = EditorGUILayout.Foldout( m_InputEditors[i].visible, m_InputEditors[i].settingsObj.m_DisplayName ?? "Input " + (i+1));
162192
}
193+
194+
if( m_InputEditors[i].visible )
195+
OnInputGui(i);
196+
163197
if (multiInputs)
164198
EditorGUI.indentLevel--;
165199
}
166200
}
167201

202+
protected virtual void OnInputGui( int inputIndex )
203+
{
204+
m_InputEditors[inputIndex].editor.OnInspectorGUI();
205+
}
206+
168207
protected virtual void OnOutputGui()
169208
{
170209
AddProperty(m_DestinationPath, () => { EditorGUILayout.PropertyField(m_DestinationPath, new GUIContent("Output path")); });

source/FrameRecorder/Core/Editor/RecorderSelector.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,14 +130,14 @@ public void OnGui()
130130
if (!m_CategoryIsReadonly)
131131
{
132132
EditorGUILayout.BeginHorizontal();
133-
SetCategoryFromIndex(EditorGUILayout.Popup("Record what:", GetCategoryIndex(), m_Categories));
133+
SetCategoryFromIndex(EditorGUILayout.Popup("Recorder category:", GetCategoryIndex(), m_Categories));
134134
EditorGUILayout.EndHorizontal();
135135
}
136136

137137
// Recorder in group selection
138138
EditorGUILayout.BeginHorizontal();
139139
var oldIndex = GetRecorderIndex();
140-
var newIndex = EditorGUILayout.Popup("Output type:", oldIndex, m_RecorderNames);
140+
var newIndex = EditorGUILayout.Popup("Selected recorder:", oldIndex, m_RecorderNames);
141141
SelectRecorder(GetRecorderFromIndex(newIndex));
142142

143143
EditorGUILayout.EndHorizontal();

source/FrameRecorder/Core/Engine/InputSettings.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ public abstract class RecorderInputSetting : ScriptableObject
1111
{
1212
public abstract Type inputType { get; }
1313
public abstract bool isValid { get; }
14+
public string m_DisplayName;
1415
}
1516

1617
/// <summary>

source/FrameRecorder/Inputs/Adam/Engine/AdamBeautyInputSettings.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ public class AdamBeautyInputSettings : InputSettings<AdamBeautyInput>
1212
public RenderTexture m_RenderTexture;
1313
public string m_CameraTag;
1414

15+
public AdamBeautyInputSettings()
16+
{
17+
m_DisplayName = "Pixels";
18+
}
19+
1520
public override bool isValid {
1621
get
1722
{

source/FrameRecorder/Inputs/CBRenderTexture/Engine/CBRenderTextureInputSettings.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ public class CBRenderTextureInputSettings : InputSettings<CBRenderTextureInput>
1010
public bool m_PadSize = false;
1111
public bool m_AllowTransparency = false;
1212

13+
public CBRenderTextureInputSettings()
14+
{
15+
m_DisplayName = "Pixels";
16+
}
17+
1318
public override bool isValid {
1419
get { return source != EImageSource.TaggedCamera || !string.IsNullOrEmpty(m_CameraTag); }
1520
}

source/FrameRecorder/Inputs/RenderTexture/Engine/RenderTextureInputSettings.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ public class RenderTextureInputSettings : InputSettings<RenderTextureInput>
44
{
55
public RenderTexture m_SourceRTxtr;
66

7+
public RenderTextureInputSettings()
8+
{
9+
m_DisplayName = "Pixels";
10+
}
11+
712
public override bool isValid {
813
get
914
{

source/FrameRecorder/Recorders/ImageRecorder/Editor/ImageRecorderEditor.cs

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@ namespace UnityEditor.FrameRecorder
88
[CustomEditor(typeof(ImageRecorderSettings))]
99
public class ImageRecorderEditor : RecorderEditor
1010
{
11-
1211
SerializedProperty m_OutputFormat;
13-
14-
string[] m_Candidates;
12+
RTInputSelector m_RTInputSelector;
1513

1614
[MenuItem("Window/Recorder/Video")]
1715
static void ShowRecorderWindow()
@@ -26,7 +24,8 @@ protected override void OnEnable()
2624
if (target == null)
2725
return;
2826

29-
m_Candidates = new [] { "Command Buffered Camera", "Offscreen rendering", "Render Texture" };
27+
m_RTInputSelector = new RTInputSelector("Pixels");
28+
3029
var pf = new PropertyFinder<ImageRecorderSettings>(serializedObject);
3130
m_Inputs = pf.Find(w => w.m_SourceSettings);
3231
m_OutputFormat = pf.Find(w => w.m_OutputFormat);
@@ -37,37 +36,18 @@ protected override void OnEncodingGroupGui()
3736
// hiding this group by not calling parent class's implementation.
3837
}
3938

40-
protected override void OnInputGui()
39+
protected override void OnInputGui( int inputIndex)
4140
{
42-
var input = m_Inputs.GetArrayElementAtIndex(0).objectReferenceValue;
43-
44-
var index = input.GetType() == typeof(CBRenderTextureInputSettings) ? 0 :
45-
input.GetType() == typeof(AdamBeautyInputSettings) ? 1 : 2;
46-
var newIndex = EditorGUILayout.Popup("Image Generator", index, m_Candidates);
47-
48-
if (index != newIndex)
41+
var input = m_Inputs.GetArrayElementAtIndex(inputIndex).objectReferenceValue as RecorderInputSetting;
42+
if (m_RTInputSelector.OnInputGui(ref input))
4943
{
50-
Type newType = null;
51-
switch (newIndex)
52-
{
53-
case 0:
54-
newType = typeof(CBRenderTextureInputSettings);
55-
break;
56-
case 1:
57-
newType = typeof(AdamBeautyInputSettings);
58-
break;
59-
case 2:
60-
newType = typeof(RenderTextureInputSettings);
61-
break;
62-
}
63-
var newSettings = ScriptableObject.CreateInstance(newType) as RecorderInputSetting;
64-
if( newIndex == 0 )
65-
(newSettings as CBRenderTextureInputSettings).m_FlipVertical = true;
44+
if( input is CBRenderTextureInputSettings )
45+
(input as CBRenderTextureInputSettings).m_FlipVertical = true;
6646

67-
ChangeInputSettings(0, newSettings);
47+
ChangeInputSettings(inputIndex, input);
6848
}
6949

70-
base.OnInputGui();
50+
base.OnInputGui(inputIndex);
7151
}
7252

7353
protected override void OnOutputGui()

0 commit comments

Comments
 (0)