13
13
14
14
namespace Explorer
15
15
{
16
- // This is a manual unstrip of UnityEngine.GUI and UnityEngine.GUILayout methods.
17
- // This code is provided "as-is".
16
+ // This is a copy+paste of UnityEngine source code, fixed for Il2Cpp.
18
17
// Taken from dnSpy output using Unity 2018.4.20.
19
18
20
- // "Unity", Unity logos, and other Unity trademarks are trademarks or
21
- // registered trademarks of Unity Technologies or its affiliates in the
22
- // U.S. and elsewhere.
19
+ // Subject to Unity's License and ToS.
23
20
// https://unity3d.com/legal/terms-of-service
24
21
// https://unity3d.com/legal/terms-of-service/software
25
22
@@ -45,7 +42,7 @@ private static GenericStack ScrollStack
45
42
// ======= public methods ======= //
46
43
47
44
// Fix for GUILayoutUtility.GetLastRect().
48
- // Calls UnstripExtensions.GetLastUnstripped.
45
+ // Calls UnstripExtensions.GetLastUnstripped() .
49
46
50
47
public static Rect GetLastRect ( )
51
48
{
@@ -62,24 +59,24 @@ public static Rect GetLastRect()
62
59
return last ;
63
60
}
64
61
65
- // Fix for GUILayout.Scroller and GUILayout.ScrollerRepeatButton, just calling fixed implementations.
66
-
67
- public static float Scroller ( Rect position , float value , float size , float leftValue , float rightValue , GUIStyle slider , GUIStyle thumb , GUIStyle leftButton , GUIStyle rightButton , bool horiz )
68
- => Scroller_Impl ( position , value , size , leftValue , rightValue , slider , thumb , leftButton , rightButton , horiz ) ;
69
-
70
- public static bool ScrollerRepeatButton ( int scrollerID , Rect rect , GUIStyle style )
71
- => ScrollerRepeatButton_Impl ( scrollerID , rect , style ) ;
72
-
73
62
// Simple unstrips for HorizontalScrollbar and VerticalScrollbar, they just call the Scroller unstrip.
74
63
75
64
public static float HorizontalScrollbar ( Rect position , float value , float size , float leftValue , float rightValue , GUIStyle style )
76
65
{
77
- return Scroller ( position , value , size , leftValue , rightValue , style , GUI . skin . GetStyle ( style . name + "thumb" ) , GUI . skin . GetStyle ( style . name + "leftbutton" ) , GUI . skin . GetStyle ( style . name + "rightbutton" ) , true ) ;
66
+ return Scroller_Impl ( position , value , size , leftValue , rightValue , style ,
67
+ GUI . skin . GetStyle ( style . name + "thumb" ) ,
68
+ GUI . skin . GetStyle ( style . name + "leftbutton" ) ,
69
+ GUI . skin . GetStyle ( style . name + "rightbutton" ) ,
70
+ true ) ;
78
71
}
79
72
80
73
public static float VerticalScrollbar ( Rect position , float value , float size , float topValue , float bottomValue , GUIStyle style )
81
74
{
82
- return Scroller ( position , value , size , topValue , bottomValue , style , GUI . skin . GetStyle ( style . name + "thumb" ) , GUI . skin . GetStyle ( style . name + "upbutton" ) , GUI . skin . GetStyle ( style . name + "downbutton" ) , false ) ;
75
+ return Scroller_Impl ( position , value , size , topValue , bottomValue , style ,
76
+ GUI . skin . GetStyle ( style . name + "thumb" ) ,
77
+ GUI . skin . GetStyle ( style . name + "upbutton" ) ,
78
+ GUI . skin . GetStyle ( style . name + "downbutton" ) ,
79
+ false ) ;
83
80
}
84
81
85
82
// Fix for BeginScrollView.
@@ -106,7 +103,7 @@ public static Vector2 BeginScrollView(Vector2 scroll, params GUILayoutOption[] o
106
103
{
107
104
try
108
105
{
109
- return BeginScrollView_Impl ( scroll , false , false , GUI . skin . horizontalScrollbar , GUI . skin . verticalScrollbar , GUI . skin . scrollView , options ) ;
106
+ return BeginScrollView_ImplLayout ( scroll , false , false , GUI . skin . horizontalScrollbar , GUI . skin . verticalScrollbar , GUI . skin . scrollView , options ) ;
110
107
}
111
108
catch ( Exception e )
112
109
{
@@ -141,16 +138,13 @@ public static void EndScrollView(bool handleScrollWheel = true)
141
138
142
139
// Actual unstrip of GUILayout.BeginScrollView()
143
140
144
- private static Vector2 BeginScrollView_Impl ( Vector2 scrollPosition , bool alwaysShowHorizontal , bool alwaysShowVertical , GUIStyle horizontalScrollbar ,
145
- GUIStyle verticalScrollbar , GUIStyle background , params GUILayoutOption [ ] options )
141
+ private static Vector2 BeginScrollView_ImplLayout ( Vector2 scrollPosition , bool alwaysShowHorizontal , bool alwaysShowVertical ,
142
+ GUIStyle horizontalScrollbar , GUIStyle verticalScrollbar , GUIStyle background , params GUILayoutOption [ ] options )
146
143
{
147
144
GUIUtility . CheckOnGUI ( ) ;
148
145
149
- var guiscrollGroup = ( GUIScrollGroup ) GUILayoutUtility . BeginLayoutGroup (
150
- background ,
151
- null ,
152
- Il2CppType . Of < GUIScrollGroup > ( )
153
- ) . Il2CppCast ( typeof ( GUIScrollGroup ) ) ;
146
+ var guiscrollGroup = GUILayoutUtility . BeginLayoutGroup ( background , null , Il2CppType . Of < GUIScrollGroup > ( ) )
147
+ . TryCast < GUIScrollGroup > ( ) ;
154
148
155
149
EventType type = Event . current . type ;
156
150
if ( type == EventType . Layout )
@@ -177,16 +171,16 @@ private static Vector2 BeginScrollView_Impl(Vector2 scrollPosition, bool alwaysS
177
171
) ;
178
172
}
179
173
180
- // Actual unstrip of GUI.BeginScrollView() -- note: not GUILayout.
174
+ // Actual unstrip of GUI.BeginScrollView()
181
175
182
- private static Vector2 BeginScrollView_Impl ( Rect position , Vector2 scrollPosition , Rect viewRect , bool alwaysShowHorizontal , bool alwaysShowVertical ,
183
- GUIStyle horizontalScrollbar , GUIStyle verticalScrollbar , GUIStyle background )
176
+ private static Vector2 BeginScrollView_Impl ( Rect position , Vector2 scrollPosition , Rect viewRect , bool alwaysShowHorizontal ,
177
+ bool alwaysShowVertical , GUIStyle horizontalScrollbar , GUIStyle verticalScrollbar , GUIStyle background )
184
178
{
185
179
GUIUtility . CheckOnGUI ( ) ;
186
180
187
181
int controlID = GUIUtility . GetControlID ( GUI . s_ScrollviewHash , FocusType . Passive ) ;
188
182
189
- var scrollViewState = ( ScrollViewState ) GUIUtility . GetStateObject ( Il2CppType . Of < ScrollViewState > ( ) , controlID ) . Il2CppCast ( typeof ( ScrollViewState ) ) ;
183
+ var scrollViewState = GUIUtility . GetStateObject ( Il2CppType . Of < ScrollViewState > ( ) , controlID ) . TryCast < ScrollViewState > ( ) ;
190
184
191
185
var scrollExt = ScrollViewStateUnstrip . FromPointer ( scrollViewState . Pointer ) ;
192
186
@@ -310,16 +304,13 @@ private static void EndScrollView_Impl(bool handleScrollWheel)
310
304
311
305
if ( ScrollStack . Count <= 0 ) return ;
312
306
313
- //ScrollViewState scrollViewState = (ScrollViewState)GUI.s_ScrollViewStates.Peek();
314
- var state = ( ScrollViewState ) ScrollStack . Peek ( ) . Il2CppCast ( typeof ( ScrollViewState ) ) ;
315
- //ScrollViewExtensions.Dict.TryGetValue(state.Pointer, out ScrollViewExtensions scrollExt);
307
+ var state = ScrollStack . Peek ( ) . TryCast < ScrollViewState > ( ) ;
316
308
var scrollExt = ScrollViewStateUnstrip . FromPointer ( state . Pointer ) ;
317
309
318
310
if ( scrollExt == null ) throw new Exception ( "Could not get scrollExt!" ) ;
319
311
320
312
GUIClip . Pop ( ) ;
321
313
322
- //GUI.s_ScrollViewStates.Pop();
323
314
ScrollStack . Pop ( ) ;
324
315
325
316
var position = scrollExt . position ;
@@ -339,7 +330,6 @@ private static void EndScrollView_Impl(bool handleScrollWheel)
339
330
pos . y = 0f ;
340
331
}
341
332
342
- // state.apply = true;
343
333
scrollExt . apply = true ;
344
334
345
335
Event . current . Use ( ) ;
@@ -368,7 +358,6 @@ private static float Scroller_Impl(Rect position, float value, float size, float
368
358
rect2 = new Rect ( position . x , position . yMax - rightButton . fixedHeight , position . width , rightButton . fixedHeight ) ;
369
359
}
370
360
371
- //value = GUI.Slider(position2, value, size, leftValue, rightValue, slider, thumb, horiz, controlID);
372
361
value = Slider ( position2 , value , size , leftValue , rightValue , slider , thumb , horiz , controlID ) ;
373
362
374
363
bool flag = Event . current . type == EventType . MouseUp ;
@@ -382,8 +371,7 @@ private static float Scroller_Impl(Rect position, float value, float size, float
382
371
}
383
372
if ( flag && Event . current . type == EventType . Used )
384
373
{
385
- //GUI.s_ScrollControlId = 0;
386
- GUIUnstrip . s_ScrollControlId = 0 ;
374
+ s_ScrollControlId = 0 ;
387
375
}
388
376
if ( leftValue < rightValue )
389
377
{
@@ -400,7 +388,6 @@ private static float Scroller_Impl(Rect position, float value, float size, float
400
388
401
389
public static float Slider ( Rect position , float value , float size , float start , float end , GUIStyle slider , GUIStyle thumb , bool horiz , int id )
402
390
{
403
- //GUIUtility.CheckOnGUI();
404
391
if ( id == 0 )
405
392
{
406
393
id = GUIUtility . GetControlID ( GUI . s_SliderHash , FocusType . Passive , position ) ;
@@ -416,11 +403,8 @@ private static bool ScrollerRepeatButton_Impl(int scrollerID, Rect rect, GUIStyl
416
403
bool result = false ;
417
404
if ( GUI . DoRepeatButton ( rect , GUIContent . none , style , FocusType . Passive ) )
418
405
{
419
- //bool flag = GUI.s_ScrollControlId != scrollerID;
420
- //GUI.s_ScrollControlId = scrollerID;
421
-
422
- bool flag = GUIUnstrip . s_ScrollControlId != scrollerID ;
423
- GUIUnstrip . s_ScrollControlId = scrollerID ;
406
+ bool flag = s_ScrollControlId != scrollerID ;
407
+ s_ScrollControlId = scrollerID ;
424
408
425
409
if ( flag )
426
410
{
0 commit comments