Skip to content

Commit dee7273

Browse files
authored
Inspector - Fix context menu not working on non-enterable members; also fixes opening exceptions thrown by method invoking (#91)
1 parent 9571a3c commit dee7273

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

RuntimeUnityEditor.Core/Features/ContextMenu.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -254,11 +254,9 @@ public void Show(object obj, ICacheEntry objEntry)
254254
{
255255
if (objEntry == null) throw new ArgumentNullException(nameof(objEntry));
256256

257-
if (obj == null && objEntry.CanEnterValue())
257+
if (obj == null && objEntry.CanEnterValue()) //todo this is a bit of a hack, maybe add a CanGetValue to ICacheEntry? This is conservative to avoid triggering side effects
258258
obj = objEntry.GetValue();
259259

260-
if (obj == null) throw new ArgumentException($"{nameof(obj)} needs to be not null or {nameof(objEntry)} has to be gettable");
261-
262260
string name;
263261
switch (objEntry)
264262
{
@@ -309,11 +307,11 @@ public void Show(object obj, MemberInfo memberInfo, string memberFullName, Actio
309307
if (obj == null && getObj != null)
310308
obj = getObj();
311309

312-
if (obj != null)
310+
if (obj != null || memberInfo != null)
313311
{
314312
_obj = obj;
315313
_objMemberInfo = memberInfo ?? obj as MemberInfo;
316-
_objName = memberFullName; //parentMemberInfo != null ? $"{parentMemberInfo.DeclaringType?.Name}.{parentMemberInfo.Name}" : obj.GetType().FullDescription();
314+
_objName = memberFullName ?? (_objMemberInfo != null ? $"{_objMemberInfo.DeclaringType?.Name}.{_objMemberInfo.Name}" : obj?.GetType().FullDescription());
317315
_setValue = setObj;
318316
_getValue = getObj;
319317

RuntimeUnityEditor.Core/Windows/Inspector/Inspector.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public sealed partial class Inspector : Window<Inspector>
2323
private InspectorTab GetCurrentTab() => _currentTab ?? (_currentTab = _tabs.FirstOrDefault());
2424
private Vector2 _tabScrollPos = Vector2.zero;
2525

26-
private GUIStyle _alignedButtonStyle;
26+
private GUIStyle _alignedButtonStyle, _alignedButtonStyleUnclickable;
2727

2828
internal static int MaxWindowY => (int)Instance.WindowRect.height;
2929

@@ -76,16 +76,20 @@ public string SearchString
7676

7777
private void DrawVariableNameEnterButton(ICacheEntry field)
7878
{
79-
if (_alignedButtonStyle == null)
79+
if (_alignedButtonStyle == null || _alignedButtonStyleUnclickable == null)
8080
{
8181
_alignedButtonStyle = GUI.skin.button.CreateCopy();
8282
_alignedButtonStyle.alignment = TextAnchor.MiddleLeft;
8383
_alignedButtonStyle.wordWrap = true;
84+
85+
_alignedButtonStyleUnclickable = _alignedButtonStyle.CreateCopy();
86+
_alignedButtonStyleUnclickable.normal.background = null;
87+
_alignedButtonStyleUnclickable.onNormal.background = null;
8488
}
8589

8690
var canEnterValue = field.CanEnterValue();
8791
var val = field.GetValue();
88-
if (GUILayout.Button(field.GetNameContent(), canEnterValue ? _alignedButtonStyle : GUI.skin.label, _inspectorNameWidth))
92+
if (GUILayout.Button(field.GetNameContent(), canEnterValue ? _alignedButtonStyle : _alignedButtonStyleUnclickable, _inspectorNameWidth))
8993
{
9094
if (IMGUIUtils.IsMouseRightClick())
9195
{

0 commit comments

Comments
 (0)