Skip to content
This repository was archived by the owner on May 9, 2023. It is now read-only.

Commit e585fc6

Browse files
committed
Allow evaluating non-primitive methods
1 parent 0dd1934 commit e585fc6

File tree

4 files changed

+148
-57
lines changed

4 files changed

+148
-57
lines changed

src/CacheObject/CacheMember.cs

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -162,22 +162,22 @@ public void OnEvaluateClicked()
162162

163163
#region Cache Member Util
164164

165-
public static bool CanParseArgs(ParameterInfo[] parameters)
166-
{
167-
foreach (var param in parameters)
168-
{
169-
var pType = param.ParameterType;
170-
171-
if (pType.IsByRef && pType.HasElementType)
172-
pType = pType.GetElementType();
173-
174-
if (pType != null && ParseUtility.CanParse(pType))
175-
continue;
176-
else
177-
return false;
178-
}
179-
return true;
180-
}
165+
//public static bool CanParseArgs(ParameterInfo[] parameters)
166+
//{
167+
// foreach (var param in parameters)
168+
// {
169+
// var pType = param.ParameterType;
170+
//
171+
// if (pType.IsByRef && pType.HasElementType)
172+
// pType = pType.GetElementType();
173+
//
174+
// if (pType != null && ParseUtility.CanParse(pType))
175+
// continue;
176+
// else
177+
// return false;
178+
// }
179+
// return true;
180+
//}
181181

182182
public static List<CacheMember> GetCacheMembers(object inspectorTarget, Type _type, ReflectionInspector _inspector)
183183
{
@@ -250,11 +250,11 @@ private static void TryCacheMember(MemberInfo member, List<CacheMember> list, Ha
250250
&& (mi.Name.StartsWith("get_") || mi.Name.StartsWith("set_")))
251251
return;
252252

253-
var args = mi.GetParameters();
254-
if (!CanParseArgs(args))
255-
return;
253+
//var args = mi.GetParameters();
254+
//if (!CanParseArgs(args))
255+
// return;
256256

257-
sig += GetArgumentString(args);
257+
sig += GetArgumentString(mi.GetParameters());
258258
if (cachedSigs.Contains(sig))
259259
return;
260260

@@ -267,9 +267,9 @@ private static void TryCacheMember(MemberInfo member, List<CacheMember> list, Ha
267267
{
268268
var pi = member as PropertyInfo;
269269

270-
var args = pi.GetIndexParameters();
271-
if (!CanParseArgs(args))
272-
return;
270+
//var args = pi.GetIndexParameters();
271+
//if (!CanParseArgs(args))
272+
// return;
273273

274274
if (!pi.CanRead && pi.CanWrite)
275275
{
@@ -280,7 +280,7 @@ private static void TryCacheMember(MemberInfo member, List<CacheMember> list, Ha
280280
return;
281281
}
282282

283-
sig += GetArgumentString(args);
283+
sig += GetArgumentString(pi.GetIndexParameters());
284284
if (cachedSigs.Contains(sig))
285285
return;
286286

src/CacheObject/Views/EvaluateWidget.cs

Lines changed: 117 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ public class EvaluateWidget : IPooledObject
2626
private GameObject argHolder;
2727
private readonly List<GameObject> argRows = new List<GameObject>();
2828
private readonly List<Text> argLabels = new List<Text>();
29+
private readonly List<InputFieldRef> argInputFields = new List<InputFieldRef>();
30+
private readonly List<Dropdown> argDropdowns = new List<Dropdown>();
2931

3032
private Type[] genericArguments;
3133
private string[] genericInput;
@@ -34,9 +36,6 @@ public class EvaluateWidget : IPooledObject
3436
private readonly List<GameObject> genericArgRows = new List<GameObject>();
3537
private readonly List<Text> genericArgLabels = new List<Text>();
3638
private readonly List<TypeCompleter> genericAutocompleters = new List<TypeCompleter>();
37-
38-
//private readonly List<InputFieldRef> inputFields = new List<InputFieldRef>();
39-
private readonly List<InputFieldRef> argInputFields = new List<InputFieldRef>();
4039
private readonly List<InputFieldRef> genericInputFields = new List<InputFieldRef>();
4140

4241
public void OnBorrowedFromPool(CacheMember owner)
@@ -52,6 +51,8 @@ public void OnBorrowedFromPool(CacheMember owner)
5251
SetArgRows();
5352

5453
this.UIRoot.SetActive(true);
54+
55+
InspectorManager.OnInspectedTabsChanged += InspectorManager_OnInspectedTabsChanged;
5556
}
5657

5758
public void OnReturnToPool()
@@ -62,6 +63,17 @@ public void OnReturnToPool()
6263
input.Text = "";
6364

6465
this.Owner = null;
66+
67+
InspectorManager.OnInspectedTabsChanged -= InspectorManager_OnInspectedTabsChanged;
68+
}
69+
70+
private void InspectorManager_OnInspectedTabsChanged()
71+
{
72+
for (int i = 0; i < argDropdowns.Count; i++)
73+
{
74+
var drop = argDropdowns[i];
75+
PopulateNonPrimitiveArgumentDropdown(drop, i);
76+
}
6577
}
6678

6779
public Type[] TryParseGenericArguments()
@@ -83,33 +95,62 @@ public object[] TryParseArguments()
8395

8496
for (int i = 0; i < arguments.Length; i++)
8597
{
86-
var arg = arguments[i];
87-
var input = argumentInput[i];
98+
var paramInfo = arguments[i];
8899

89-
var type = arg.ParameterType;
90-
if (type.IsByRef)
91-
type = type.GetElementType();
100+
var argType = paramInfo.ParameterType;
101+
if (argType.IsByRef)
102+
argType = argType.GetElementType();
92103

93-
if (type == typeof(string))
104+
if (ParseUtility.CanParse(argType))
94105
{
95-
outArgs[i] = input;
96-
continue;
97-
}
98-
99-
if (string.IsNullOrEmpty(input))
100-
{
101-
if (arg.IsOptional)
102-
outArgs[i] = arg.DefaultValue;
103-
else
106+
var input = argumentInput[i];
107+
108+
if (argType == typeof(string))
109+
{
110+
outArgs[i] = input;
111+
continue;
112+
}
113+
114+
if (string.IsNullOrEmpty(input))
115+
{
116+
if (paramInfo.IsOptional)
117+
outArgs[i] = paramInfo.DefaultValue;
118+
else
119+
outArgs[i] = null;
120+
continue;
121+
}
122+
123+
if (!ParseUtility.TryParse(input, argType, out outArgs[i], out Exception ex))
124+
{
104125
outArgs[i] = null;
105-
continue;
126+
ExplorerCore.LogWarning($"Cannot parse argument '{paramInfo.Name}' ({paramInfo.ParameterType.Name})" +
127+
$"{(ex == null ? "" : $", {ex.GetType().Name}: {ex.Message}")}");
128+
}
106129
}
107-
108-
if (!ParseUtility.TryParse(input, type, out outArgs[i], out Exception ex))
130+
else
109131
{
110-
outArgs[i] = null;
111-
ExplorerCore.LogWarning($"Cannot parse argument '{arg.Name}' ({arg.ParameterType.Name})" +
112-
$"{(ex == null ? "" : $", {ex.GetType().Name}: {ex.Message}")}");
132+
var dropdown = argDropdowns[i];
133+
if (dropdown.value == 0)
134+
{
135+
outArgs[i] = null;
136+
}
137+
else
138+
{
139+
// Probably should do this in a better way...
140+
// Parse the text of the dropdown option to get the inspector tab index.
141+
string tabIndexString = "";
142+
for (int j = 4; ; j++)
143+
{
144+
char c = dropdown.options[dropdown.value].text[j];
145+
if (c == ':')
146+
break;
147+
tabIndexString += c;
148+
}
149+
int tabIndex = int.Parse(tabIndexString);
150+
var tab = InspectorManager.Inspectors[tabIndex - 1];
151+
152+
outArgs[i] = tab.Target;
153+
}
113154
}
114155
}
115156

@@ -195,25 +236,54 @@ private void SetNormalArgRows()
195236
}
196237

197238
var arg = arguments[i];
198-
239+
var argType = arg.ParameterType;
240+
if (argType.IsByRef)
241+
argType = argType.GetElementType();
199242

200243
if (i >= argRows.Count)
201244
AddArgRow(i, false);
202245

203246
argRows[i].SetActive(true);
204-
argLabels[i].text = $"{SignatureHighlighter.Parse(arg.ParameterType, false)} <color={SignatureHighlighter.LOCAL_ARG}>{arg.Name}</color>";
205-
if (arg.ParameterType == typeof(string))
206-
argInputFields[i].PlaceholderText.text = "";
247+
argLabels[i].text =
248+
$"{SignatureHighlighter.Parse(argType, false)} <color={SignatureHighlighter.LOCAL_ARG}>{arg.Name}</color>";
249+
250+
if (ParseUtility.CanParse(argType))
251+
{
252+
argInputFields[i].Component.gameObject.SetActive(true);
253+
argDropdowns[i].gameObject.SetActive(false);
254+
255+
if (arg.ParameterType == typeof(string))
256+
argInputFields[i].PlaceholderText.text = "";
257+
else
258+
argInputFields[i].PlaceholderText.text = $"eg. {ParseUtility.GetExampleInput(argType)}";
259+
}
207260
else
208261
{
209-
var elemType = arg.ParameterType;
210-
if (elemType.IsByRef)
211-
elemType = elemType.GetElementType();
212-
argInputFields[i].PlaceholderText.text = $"eg. {ParseUtility.GetExampleInput(elemType)}";
262+
argInputFields[i].Component.gameObject.SetActive(false);
263+
argDropdowns[i].gameObject.SetActive(true);
264+
265+
PopulateNonPrimitiveArgumentDropdown(argDropdowns[i], i);
213266
}
214267
}
215268
}
216269

270+
private void PopulateNonPrimitiveArgumentDropdown(Dropdown dropdown, int argIndex)
271+
{
272+
dropdown.options.Clear();
273+
dropdown.options.Add(new Dropdown.OptionData("null"));
274+
275+
var argType = arguments[argIndex].ParameterType;
276+
277+
int tabIndex = 0;
278+
foreach (var tab in InspectorManager.Inspectors)
279+
{
280+
tabIndex++;
281+
282+
if (argType.IsAssignableFrom(tab.Target.GetActualType()))
283+
dropdown.options.Add(new Dropdown.OptionData($"Tab {tabIndex}: {tab.Tab.TabText.text}"));
284+
}
285+
}
286+
217287
private void AddArgRow(int index, bool generic)
218288
{
219289
if (!generic)
@@ -242,14 +312,29 @@ private void AddArgRow(int index, GameObject parent, List<GameObject> objectList
242312
inputField.OnValueChanged += (string val) => { inputArray[index] = val; };
243313

244314
if (!generic)
315+
{
316+
var dropdownObj = UIFactory.CreateDropdown(horiGroup, out Dropdown dropdown, "Select argument...", 14, (int val) =>
317+
{
318+
ArgDropdownChanged(index, val);
319+
});
320+
UIFactory.SetLayoutElement(dropdownObj, minHeight: 25, flexibleHeight: 50, minWidth: 100, flexibleWidth: 1000);
321+
dropdownObj.AddComponent<ContentSizeFitter>().verticalFit = ContentSizeFitter.FitMode.PreferredSize;
322+
245323
argInputFields.Add(inputField);
324+
argDropdowns.Add(dropdown);
325+
}
246326
else
247327
genericInputFields.Add(inputField);
248328

249329
if (generic)
250330
genericAutocompleters.Add(new TypeCompleter(null, inputField));
251331
}
252332

333+
private void ArgDropdownChanged(int argIndex, int value)
334+
{
335+
// not sure if necessary
336+
}
337+
253338
public GameObject CreateContent(GameObject parent)
254339
{
255340
UIRoot = UIFactory.CreateVerticalGroup(parent, "EvaluateWidget", false, false, true, true, 3, new Vector4(2, 2, 2, 2),

src/ExplorerCore.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace UnityExplorer
1616
public static class ExplorerCore
1717
{
1818
public const string NAME = "UnityExplorer";
19-
public const string VERSION = "4.4.2";
19+
public const string VERSION = "4.4.3";
2020
public const string AUTHOR = "Sinai";
2121
public const string GUID = "com.sinai.unityexplorer";
2222

src/Inspectors/InspectorManager.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ public static class InspectorManager
2323

2424
public static float PanelWidth;
2525

26+
public static event Action OnInspectedTabsChanged;
27+
2628
public static void Inspect(object obj, CacheObjectBase sourceCache = null)
2729
{
2830
if (obj.IsNullOrDestroyed())
@@ -111,6 +113,8 @@ private static void CreateInspector<T>(object target, bool staticReflection = fa
111113

112114
inspector.OnBorrowedFromPool(target);
113115
SetInspectorActive(inspector);
116+
117+
OnInspectedTabsChanged?.Invoke();
114118
}
115119

116120
internal static void ReleaseInspector<T>(T inspector) where T : InspectorBase
@@ -144,6 +148,8 @@ internal static void ReleaseInspector<T>(T inspector) where T : InspectorBase
144148
UIManager.SetPanelActive(UIManager.Panels.Inspector, false);
145149
}
146150
}
151+
152+
OnInspectedTabsChanged?.Invoke();
147153
}
148154

149155
internal static void Update()

0 commit comments

Comments
 (0)