1
1
using System ;
2
2
using System . Collections ;
3
3
using System . Collections . Generic ;
4
+ using System . Diagnostics ;
4
5
using System . IO ;
5
6
using System . Reflection ;
6
7
using System . Reflection . Emit ;
7
8
using UnityEngine ;
8
9
using UnityEngine . UI ;
9
10
using UnityExplorer . CacheObject ;
10
11
using UnityExplorer . CacheObject . Views ;
12
+ using UnityExplorer . Config ;
13
+ using UnityExplorer . UI ;
11
14
using UnityExplorer . UI . Panels ;
12
15
using UnityExplorer . UI . Widgets ;
13
16
using UniverseLib ;
@@ -33,7 +36,6 @@ public enum MemberFilter
33
36
public class ReflectionInspector : InspectorBase , ICellPoolDataSource < CacheMemberCell > , ICacheObjectController
34
37
{
35
38
public CacheObjectBase ParentCacheObject { get ; set ; }
36
- //public Type TargetType { get; private set; }
37
39
public bool StaticOnly { get ; internal set ; }
38
40
public bool CanWrite => true ;
39
41
@@ -73,6 +75,8 @@ public class ReflectionInspector : InspectorBase, ICellPoolDataSource<CacheMembe
73
75
Text assemblyText ;
74
76
Toggle autoUpdateToggle ;
75
77
78
+ ButtonRef dnSpyButton ;
79
+
76
80
ButtonRef makeGenericButton ;
77
81
GenericConstructorWidget genericConstructor ;
78
82
@@ -155,9 +159,15 @@ private void SetTarget(object target)
155
159
156
160
string asmText ;
157
161
if ( TargetType . Assembly is AssemblyBuilder || string . IsNullOrEmpty ( TargetType . Assembly . Location ) )
162
+ {
158
163
asmText = $ "{ TargetType . Assembly . GetName ( ) . Name } <color=grey><i>(in memory)</i></color>";
164
+ dnSpyButton . GameObject . SetActive ( false ) ;
165
+ }
159
166
else
167
+ {
160
168
asmText = Path . GetFileName ( TargetType . Assembly . Location ) ;
169
+ dnSpyButton . GameObject . SetActive ( true ) ;
170
+ }
161
171
assemblyText . text = $ "<color=grey>Assembly:</color> { asmText } ";
162
172
163
173
// Unity object helper widget
@@ -350,6 +360,25 @@ void OnCopyClicked()
350
360
ClipboardPanel . Copy ( this . Target ?? this . TargetType ) ;
351
361
}
352
362
363
+ void OnDnSpyButtonClicked ( )
364
+ {
365
+ string path = ConfigManager . DnSpy_Path . Value ;
366
+ if ( File . Exists ( path ) && path . EndsWith ( "dnspy.exe" , StringComparison . OrdinalIgnoreCase ) )
367
+ {
368
+ Type type = TargetType ;
369
+ // if constructed generic type, use the generic type definition
370
+ if ( type . IsGenericType && ! type . IsGenericTypeDefinition )
371
+ type = type . GetGenericTypeDefinition ( ) ;
372
+
373
+ string args = $ "\" { type . Assembly . Location } \" --select T:{ type . FullName } ";
374
+ Process . Start ( path , args ) ;
375
+ }
376
+ else
377
+ {
378
+ Notification . ShowMessage ( $ "Please set a valid dnSpy path in UnityExplorer Settings.") ;
379
+ }
380
+ }
381
+
353
382
void OnMakeGenericClicked ( )
354
383
{
355
384
ContentRoot . SetActive ( false ) ;
@@ -425,10 +454,21 @@ public override GameObject CreateContent(GameObject parent)
425
454
UIFactory . SetLayoutElement ( copyButton . Component . gameObject , minHeight : 25 , minWidth : 120 , flexibleWidth : 0 ) ;
426
455
copyButton . OnClick += OnCopyClicked ;
427
456
428
- assemblyText = UIFactory . CreateLabel ( UIRoot , "AssemblyLabel" , "not set" , TextAnchor . MiddleLeft ) ;
457
+ // Assembly row
458
+
459
+ GameObject asmRow = UIFactory . CreateHorizontalGroup ( UIRoot , "AssemblyRow" , false , false , true , true , 5 , default , new ( 1 , 1 , 1 , 0 ) ) ;
460
+ UIFactory . SetLayoutElement ( asmRow , flexibleWidth : 9999 , minHeight : 25 ) ;
461
+
462
+ assemblyText = UIFactory . CreateLabel ( asmRow , "AssemblyLabel" , "not set" , TextAnchor . MiddleLeft ) ;
429
463
UIFactory . SetLayoutElement ( assemblyText . gameObject , minHeight : 25 , flexibleWidth : 9999 ) ;
430
464
431
- ContentRoot = UIFactory . CreateVerticalGroup ( UIRoot , "MemberHolder" , false , false , true , true , 5 , new Vector4 ( 2 , 2 , 2 , 2 ) ,
465
+ dnSpyButton = UIFactory . CreateButton ( asmRow , "DnSpyButton" , "View in dnSpy" ) ;
466
+ UIFactory . SetLayoutElement ( dnSpyButton . GameObject , minWidth : 120 , minHeight : 25 ) ;
467
+ dnSpyButton . OnClick += OnDnSpyButtonClicked ;
468
+
469
+ // Content
470
+
471
+ ContentRoot = UIFactory . CreateVerticalGroup ( UIRoot , "ContentRoot" , false , false , true , true , 5 , new Vector4 ( 2 , 2 , 2 , 2 ) ,
432
472
new Color ( 0.12f , 0.12f , 0.12f ) ) ;
433
473
UIFactory . SetLayoutElement ( ContentRoot , flexibleWidth : 9999 , flexibleHeight : 9999 ) ;
434
474
0 commit comments