Skip to content

Commit 00d1de5

Browse files
committed
- Added a ScreenCapture image input
- Added ImageInputSettings abstract base class - Added resolution selector
1 parent 61e474b commit 00d1de5

25 files changed

Lines changed: 463 additions & 50 deletions

source/FrameRecorder/Core/Editor/EnumHelper.cs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,22 @@ public static int GetEnumValueFromMaskedIndex<TEnum>(int index, int mask)
2121
throw new ArgumentException("invalid masked index");
2222
}
2323

24+
public static int GetEnumValueFromClippedIndex<TEnum>(int index, int start, int end)
25+
{
26+
if (!typeof(TEnum).IsEnum) throw new ArgumentException("Arg not an enum");
27+
var values = Enum.GetValues(typeof(TEnum));
28+
for( int i = 0, j = -1; i < values.Length; i++ )
29+
{
30+
if ((int)values.GetValue(i) >= start && (int)values.GetValue(i) <= end )
31+
j++;
32+
33+
if (j == index)
34+
return (int)values.GetValue(i);
35+
}
36+
throw new ArgumentException("invalid clipped index");
37+
}
38+
39+
2440
public static int GetMaskedIndexFromEnumValue<TEnum>(int value, int mask)
2541
{
2642
if (!typeof(TEnum).IsEnum) throw new ArgumentException("Arg not an enum");
@@ -38,6 +54,23 @@ public static int GetMaskedIndexFromEnumValue<TEnum>(int value, int mask)
3854
return 0;
3955
}
4056

57+
public static int GetClippedIndexFromEnumValue<TEnum>(int value, int start, int end)
58+
{
59+
if (!typeof(TEnum).IsEnum) throw new ArgumentException("Arg not an enum");
60+
var values = Enum.GetValues(typeof(TEnum));
61+
for( int i = 0, j = -1; i < values.Length; i++ )
62+
{
63+
var v = (int)values.GetValue(i);
64+
if (v >= start && v <= end)
65+
{
66+
j++;
67+
if (v == value)
68+
return j;
69+
}
70+
}
71+
return 0;
72+
}
73+
4174
public delegate string EnumToStringDelegate(int value);
4275
public static string[] MaskOutEnumNames<TEnum>(int mask, EnumToStringDelegate toString )
4376
{
@@ -66,6 +99,22 @@ public static string[] MaskOutEnumNames<TEnum>(int mask )
6699
return result.ToArray();
67100
}
68101

102+
public static string[] ClipOutEnumNames<TEnum>(int start, int end )
103+
{
104+
if (!typeof(TEnum).IsEnum) throw new ArgumentException("Arg not an enum");
105+
var names = Enum.GetNames(typeof(TEnum));
106+
var values = Enum.GetValues(typeof(TEnum));
107+
var result = new List<String>();
108+
for( int i = 0; i < values.Length; i++ )
109+
{
110+
if( (int)values.GetValue(i) >= start && (int)values.GetValue(i) <= end )
111+
result.Add( (string)names.GetValue(i) );
112+
}
113+
return result.ToArray();
114+
}
115+
116+
117+
69118
}
70119

71120
}

source/FrameRecorder/Core/Editor/RTInputSelector.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4-
using UnityEngine;
54
using UnityEngine.Recorder;
6-
using UnityEngine.Recorder.Input;
75

86
namespace UnityEditor.Recorder
97
{
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using UnityEditor;
4+
using UnityEditor.Recorder;
5+
using UnityEngine;
6+
using UnityEngine.Recorder;
7+
using UnityEngine.Recorder.Input;
8+
9+
namespace UnityEditor.Recorder
10+
{
11+
public class ResolutionSelector
12+
{
13+
string[] m_MaskedNames;
14+
EImageDimension m_MaxRes = EImageDimension.Window;
15+
16+
public void OnInspectorGUI(EImageDimension max, SerializedProperty size )
17+
{
18+
if (m_MaskedNames == null || max != m_MaxRes)
19+
{
20+
m_MaskedNames = EnumHelper.ClipOutEnumNames<EImageDimension>((int)EImageDimension.Window, (int)max);
21+
m_MaxRes = max;
22+
}
23+
24+
using (var check = new EditorGUI.ChangeCheckScope())
25+
{
26+
var index = EnumHelper.GetClippedIndexFromEnumValue<EImageDimension>(size.intValue, (int)EImageDimension.Window, (int)m_MaxRes);
27+
index = EditorGUILayout.Popup("Output Resolution", index, m_MaskedNames);
28+
29+
if (check.changed)
30+
size.intValue = EnumHelper.GetEnumValueFromClippedIndex<EImageDimension>(index, (int)EImageDimension.Window, (int)m_MaxRes);
31+
32+
if (size.intValue > (int)m_MaxRes)
33+
size.intValue = (int)m_MaxRes;
34+
}
35+
}
36+
}
37+
}

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

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using UnityEngine;
4+
5+
namespace UnityEngine.Recorder.Input
6+
{
7+
public abstract class ImageInputSettings : RecorderInputSetting
8+
{
9+
public EImageDimension maxSupportedSize { get; set; } // dynamic & contextual: do not save
10+
public EImageDimension m_OutputSize = EImageDimension.x720p_HD;
11+
public EImageAspect m_AspectRatio = EImageAspect.x16_9;
12+
public bool m_ForceEvenSize = false;
13+
14+
public override bool isValid
15+
{
16+
get { return m_OutputSize <= maxSupportedSize; }
17+
}
18+
}
19+
}

source/FrameRecorder/Core/Engine/ImageInputSettings.cs.meta

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

source/FrameRecorder/Core/Engine/InputSettings.cs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,4 @@ public bool storeInScene
2828
}
2929
}
3030

31-
/// <summary>
32-
/// What is this:
33-
/// Motivation :
34-
/// Notes:
35-
/// </summary>
36-
public abstract class InputSettings<TInput> : RecorderInputSetting
37-
{
38-
public override Type inputType
39-
{
40-
get { return typeof(TInput); }
41-
}
42-
}
4331
}

source/FrameRecorder/Inputs/Animation/Editor/AnimationInputSettings.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace UnityEditor.Experimental.Recorder.Input
88
{
99
[Serializable]
1010
[StoreInScene]
11-
public class AnimationInputSettings : InputSettings<AnimationInput>
11+
public class AnimationInputSettings : RecorderInputSetting
1212
{
1313
public GameObject gameObject;
1414
public bool enabled = false;
@@ -31,6 +31,11 @@ public List<Type> bindingType
3131
}
3232
}
3333

34+
public override Type inputType
35+
{
36+
get { return typeof(AnimationInput); }
37+
}
38+
3439
public override bool isValid
3540
{
3641
get

source/FrameRecorder/Inputs/CBRenderTexture/Editor/CBRenderTextureInputSettingsEditor.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ public class CBRenderTextureInputSettingsEditor : InputEditor
99
{
1010
static EImageSource m_SupportedSources = EImageSource.MainCamera | EImageSource.ActiveCameras | EImageSource.TaggedCamera;
1111
string[] m_MaskedSourceNames;
12+
ResolutionSelector m_ResSelector;
13+
1214
SerializedProperty m_Source;
1315
SerializedProperty m_CameraTag;
1416
SerializedProperty m_RenderSize;
@@ -22,14 +24,18 @@ protected void OnEnable()
2224
if (target == null)
2325
return;
2426

27+
2528
var pf = new PropertyFinder<CBRenderTextureInputSettings>(serializedObject);
2629
m_Source = pf.Find(w => w.source);
2730
m_CameraTag = pf.Find(w => w.m_CameraTag);
28-
m_RenderSize = pf.Find(w => w.m_RenderSize);
29-
m_RenderAspect = pf.Find(w => w.m_RenderAspect);
31+
32+
m_RenderSize = pf.Find(w => w.m_OutputSize);
33+
m_RenderAspect = pf.Find(w => w.m_AspectRatio);
3034
m_FlipFinalOutput = pf.Find( w => w.m_FlipFinalOutput );
3135
m_Transparency = pf.Find(w => w.m_AllowTransparency);
3236
m_CaptureUI = pf.Find(w => w.m_CaptureUI);
37+
38+
m_ResSelector = new ResolutionSelector();
3339
}
3440

3541
public override void OnInspectorGUI()
@@ -58,7 +64,11 @@ public override void OnInspectorGUI()
5864

5965
if (inputType != EImageSource.RenderTexture)
6066
{
61-
AddProperty(m_RenderSize, () => EditorGUILayout.PropertyField(m_RenderSize, new GUIContent("Resolution")));
67+
AddProperty(m_RenderSize, () =>
68+
{
69+
m_ResSelector.OnInspectorGUI( (target as ImageInputSettings).maxSupportedSize, m_RenderSize );
70+
});
71+
6272
if (m_RenderSize.intValue > (int)EImageDimension.Window)
6373
{
6474
AddProperty(m_RenderAspect, () => EditorGUILayout.PropertyField(m_RenderAspect, new GUIContent("Aspect Ratio")));

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public override void BeginRecording(RecordingSession session)
9393
int screenWidth = Screen.width;
9494
int screenHeight = Screen.height;
9595
#if UNITY_EDITOR
96-
switch (cbSettings.m_RenderSize)
96+
switch (cbSettings.m_OutputSize)
9797
{
9898
case EImageDimension.Window:
9999
{
@@ -112,8 +112,8 @@ public override void BeginRecording(RecordingSession session)
112112

113113
default:
114114
{
115-
outputHeight = (int)cbSettings.m_RenderSize;
116-
outputWidth = (int)(outputHeight * AspectRatioHelper.GetRealAR(cbSettings.m_RenderAspect));
115+
outputHeight = (int)cbSettings.m_OutputSize;
116+
outputWidth = (int)(outputHeight * AspectRatioHelper.GetRealAR(cbSettings.m_AspectRatio));
117117

118118
if (cbSettings.m_ForceEvenSize)
119119
{

0 commit comments

Comments
 (0)