1
1
#if UNITY_EDITOR
2
2
3
3
using System ;
4
+ using System . Collections . Generic ;
4
5
using System . Reflection ;
5
6
using UnityEditor ;
6
7
@@ -9,10 +10,8 @@ namespace UnityEngine.FrameRecorder.Input
9
10
10
11
public class GameViewSize
11
12
{
12
-
13
13
static object m_InitialSizeObj ;
14
14
15
-
16
15
public static EditorWindow GetMainGameView ( )
17
16
{
18
17
System . Type T = System . Type . GetType ( "UnityEditor.GameView,UnityEditor" ) ;
@@ -63,28 +62,58 @@ static void SizeOf(object gameViewSize, out int width, out int height)
63
62
height = ( int ) gameViewSize . GetType ( ) . GetProperty ( "height" , System . Reflection . BindingFlags . Public | System . Reflection . BindingFlags . Instance ) . GetValue ( gameViewSize , new object [ 0 ] { } ) ;
64
63
}
65
64
66
- public static object FindSize ( int width , int height )
65
+ public static object SetCustomSize ( int width , int height )
66
+ {
67
+ // Find recorder size object
68
+ var sizeObj = FindRecorderSizeObj ( ) ;
69
+ if ( sizeObj != null )
70
+ {
71
+ sizeObj . GetType ( ) . GetField ( "m_Width" , System . Reflection . BindingFlags . NonPublic | System . Reflection . BindingFlags . Instance ) . SetValue ( sizeObj , width ) ;
72
+ sizeObj . GetType ( ) . GetField ( "m_Height" , System . Reflection . BindingFlags . NonPublic | System . Reflection . BindingFlags . Instance ) . SetValue ( sizeObj , height ) ;
73
+ }
74
+ else
75
+ {
76
+ sizeObj = AddSize ( width , height ) ;
77
+ }
78
+
79
+ return sizeObj ;
80
+ }
81
+
82
+
83
+ private static object FindRecorderSizeObj ( )
67
84
{
68
85
var group = Group ( ) ;
69
86
70
- int total = TotalCount ( ) ;
71
- for ( int i = 0 ; i < total ; i ++ )
87
+ var customs = group . GetType ( ) . GetField ( "m_Custom" , BindingFlags . NonPublic | BindingFlags . Instance ) . GetValue ( group ) ;
88
+
89
+ var itr = ( System . Collections . IEnumerator ) customs . GetType ( ) . GetMethod ( "GetEnumerator" ) . Invoke ( customs , new object [ ] { } ) ;
90
+ while ( itr . MoveNext ( ) )
72
91
{
73
- var sizeObj = GetGameViewSize ( group , i ) ;
74
- int x , y ;
75
- SizeOf ( sizeObj , out x , out y ) ;
76
- if ( x == width && y == height )
77
- return sizeObj ;
92
+ var txt = ( string ) itr . Current . GetType ( ) . GetField ( "m_BaseText" , BindingFlags . NonPublic | BindingFlags . Instance ) . GetValue ( itr . Current ) ;
93
+ if ( txt == "(Recording resolution)" )
94
+ return itr . Current ;
78
95
}
79
96
80
97
return null ;
81
98
}
82
99
100
+
83
101
public static int IndexOf ( object sizeObj )
84
102
{
85
103
var group = Group ( ) ;
86
- var obj = group . GetType ( ) . GetMethod ( "IndexOf" , System . Reflection . BindingFlags . Public | System . Reflection . BindingFlags . Instance ) ;
87
- return ( int ) obj . Invoke ( group , new object [ ] { sizeObj } ) ;
104
+ var method = group . GetType ( ) . GetMethod ( "IndexOf" , System . Reflection . BindingFlags . Public | System . Reflection . BindingFlags . Instance ) ;
105
+ int index = ( int ) method . Invoke ( group , new object [ ] { sizeObj } ) ;
106
+
107
+ var builtinList = group . GetType ( ) . GetField ( "m_Builtin" , System . Reflection . BindingFlags . NonPublic | System . Reflection . BindingFlags . Instance ) . GetValue ( group ) ;
108
+
109
+ method = builtinList . GetType ( ) . GetMethod ( "Contains" ) ;
110
+ if ( ( bool ) method . Invoke ( builtinList , new object [ ] { sizeObj } ) )
111
+ return index ;
112
+
113
+ method = group . GetType ( ) . GetMethod ( "GetBuiltinCount" ) ;
114
+ index += ( int ) method . Invoke ( group , new object [ ] { } ) ;
115
+
116
+ return index ;
88
117
}
89
118
90
119
static object NewSizeObj ( int width , int height )
@@ -95,7 +124,7 @@ static object NewSizeObj(int width, int height)
95
124
T . GetProperty ( "sizeType" , System . Reflection . BindingFlags . Public | System . Reflection . BindingFlags . Instance ) . SetValue ( sizeObj , 1 , new object [ 0 ] { } ) ;
96
125
T . GetProperty ( "width" , System . Reflection . BindingFlags . Public | System . Reflection . BindingFlags . Instance ) . SetValue ( sizeObj , width , new object [ 0 ] { } ) ;
97
126
T . GetProperty ( "height" , System . Reflection . BindingFlags . Public | System . Reflection . BindingFlags . Instance ) . SetValue ( sizeObj , height , new object [ 0 ] { } ) ;
98
- T . GetProperty ( "baseText" , System . Reflection . BindingFlags . Public | System . Reflection . BindingFlags . Instance ) . SetValue ( sizeObj , string . Format ( "FR:{0}x{1}" , width , height ) , new object [ 0 ] { } ) ;
127
+ T . GetProperty ( "baseText" , System . Reflection . BindingFlags . Public | System . Reflection . BindingFlags . Instance ) . SetValue ( sizeObj , "(Recording resolution)" , new object [ 0 ] { } ) ;
99
128
100
129
return sizeObj ;
101
130
}
@@ -113,7 +142,7 @@ public static object AddSize(int width, int height)
113
142
114
143
public static void SelectSize ( object size )
115
144
{
116
- var index = IndexOf ( size ) + 7 ;
145
+ var index = IndexOf ( size ) ;
117
146
118
147
var gameView = GetMainGameView ( ) ;
119
148
var obj = gameView . GetType ( ) . GetMethod ( "SizeSelectionCallback" , System . Reflection . BindingFlags . Public | System . Reflection . BindingFlags . Instance ) ;
0 commit comments