mirror of
https://github.com/GrahamKracker/UnityExplorer.git
synced 2025-07-01 19:13:03 +08:00
Code cleanup
This commit is contained in:
@ -111,7 +111,7 @@ namespace UnityExplorer.CSConsole
|
|||||||
|
|
||||||
if (suggestions.Any())
|
if (suggestions.Any())
|
||||||
{
|
{
|
||||||
AutoCompleteModal.Instance.TakeOwnership(this);
|
AutoCompleteModal.TakeOwnership(this);
|
||||||
AutoCompleteModal.Instance.SetSuggestions(suggestions);
|
AutoCompleteModal.Instance.SetSuggestions(suggestions);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -23,9 +23,9 @@ namespace UnityExplorer.CacheObject
|
|||||||
List<CacheMember> ctors = new();
|
List<CacheMember> ctors = new();
|
||||||
List<CacheMember> methods = new();
|
List<CacheMember> methods = new();
|
||||||
|
|
||||||
var types = ReflectionUtility.GetAllBaseTypes(type);
|
Type[] types = ReflectionUtility.GetAllBaseTypes(type);
|
||||||
|
|
||||||
var flags = BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static;
|
BindingFlags flags = BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static;
|
||||||
if (!inspector.StaticOnly)
|
if (!inspector.StaticOnly)
|
||||||
flags |= BindingFlags.Instance;
|
flags |= BindingFlags.Instance;
|
||||||
|
|
||||||
@ -34,7 +34,7 @@ namespace UnityExplorer.CacheObject
|
|||||||
// Get non-static constructors of the main type.
|
// Get non-static constructors of the main type.
|
||||||
// There's no reason to get the static cctor, it will be invoked when we inspect the class.
|
// There's no reason to get the static cctor, it will be invoked when we inspect the class.
|
||||||
// Also no point getting ctors on inherited types.
|
// Also no point getting ctors on inherited types.
|
||||||
foreach (var ctor in type.GetConstructors(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance))
|
foreach (ConstructorInfo ctor in type.GetConstructors(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance))
|
||||||
TryCacheMember(ctor, ctors, cachedSigs, type, inspector);
|
TryCacheMember(ctor, ctors, cachedSigs, type, inspector);
|
||||||
|
|
||||||
// structs always have a parameterless constructor
|
// structs always have a parameterless constructor
|
||||||
@ -47,23 +47,23 @@ namespace UnityExplorer.CacheObject
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var declaringType in types)
|
foreach (Type declaringType in types)
|
||||||
{
|
{
|
||||||
foreach (var prop in declaringType.GetProperties(flags))
|
foreach (PropertyInfo prop in declaringType.GetProperties(flags))
|
||||||
if (prop.DeclaringType == declaringType)
|
if (prop.DeclaringType == declaringType)
|
||||||
TryCacheMember(prop, props, cachedSigs, declaringType, inspector);
|
TryCacheMember(prop, props, cachedSigs, declaringType, inspector);
|
||||||
|
|
||||||
foreach (var field in declaringType.GetFields(flags))
|
foreach (FieldInfo field in declaringType.GetFields(flags))
|
||||||
if (field.DeclaringType == declaringType)
|
if (field.DeclaringType == declaringType)
|
||||||
TryCacheMember(field, fields, cachedSigs, declaringType, inspector);
|
TryCacheMember(field, fields, cachedSigs, declaringType, inspector);
|
||||||
|
|
||||||
foreach (var method in declaringType.GetMethods(flags))
|
foreach (MethodInfo method in declaringType.GetMethods(flags))
|
||||||
if (method.DeclaringType == declaringType)
|
if (method.DeclaringType == declaringType)
|
||||||
TryCacheMember(method, methods, cachedSigs, declaringType, inspector);
|
TryCacheMember(method, methods, cachedSigs, declaringType, inspector);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var sorted = new List<CacheMember>();
|
List<CacheMember> sorted = new();
|
||||||
sorted.AddRange(props.OrderBy(it => Array.IndexOf(types, it.DeclaringType))
|
sorted.AddRange(props.OrderBy(it => Array.IndexOf(types, it.DeclaringType))
|
||||||
.ThenBy(it => it.NameForFiltering));
|
.ThenBy(it => it.NameForFiltering));
|
||||||
sorted.AddRange(fields.OrderBy(it => Array.IndexOf(types, it.DeclaringType))
|
sorted.AddRange(fields.OrderBy(it => Array.IndexOf(types, it.DeclaringType))
|
||||||
@ -86,9 +86,7 @@ namespace UnityExplorer.CacheObject
|
|||||||
|
|
||||||
string sig = member switch
|
string sig = member switch
|
||||||
{
|
{
|
||||||
// method or constructor
|
MethodBase mb => mb.FullDescription(), // (method or constructor)
|
||||||
MethodBase mb => mb.FullDescription(),
|
|
||||||
// property or field
|
|
||||||
PropertyInfo or FieldInfo => $"{member.DeclaringType.FullDescription()}.{member.Name}",
|
PropertyInfo or FieldInfo => $"{member.DeclaringType.FullDescription()}.{member.Name}",
|
||||||
_ => throw new NotImplementedException(),
|
_ => throw new NotImplementedException(),
|
||||||
};
|
};
|
||||||
@ -105,7 +103,7 @@ namespace UnityExplorer.CacheObject
|
|||||||
{
|
{
|
||||||
case MemberTypes.Constructor:
|
case MemberTypes.Constructor:
|
||||||
{
|
{
|
||||||
var ci = member as ConstructorInfo;
|
ConstructorInfo ci = member as ConstructorInfo;
|
||||||
cached = new CacheConstructor(ci);
|
cached = new CacheConstructor(ci);
|
||||||
returnType = ci.DeclaringType;
|
returnType = ci.DeclaringType;
|
||||||
}
|
}
|
||||||
@ -113,7 +111,7 @@ namespace UnityExplorer.CacheObject
|
|||||||
|
|
||||||
case MemberTypes.Method:
|
case MemberTypes.Method:
|
||||||
{
|
{
|
||||||
var mi = member as MethodInfo;
|
MethodInfo mi = member as MethodInfo;
|
||||||
if (ignorePropertyMethodInfos
|
if (ignorePropertyMethodInfos
|
||||||
&& (mi.Name.StartsWith("get_") || mi.Name.StartsWith("set_")))
|
&& (mi.Name.StartsWith("get_") || mi.Name.StartsWith("set_")))
|
||||||
return;
|
return;
|
||||||
@ -125,12 +123,12 @@ namespace UnityExplorer.CacheObject
|
|||||||
|
|
||||||
case MemberTypes.Property:
|
case MemberTypes.Property:
|
||||||
{
|
{
|
||||||
var pi = member as PropertyInfo;
|
PropertyInfo pi = member as PropertyInfo;
|
||||||
|
|
||||||
if (!pi.CanRead && pi.CanWrite)
|
if (!pi.CanRead && pi.CanWrite)
|
||||||
{
|
{
|
||||||
// write-only property, cache the set method instead.
|
// write-only property, cache the set method instead.
|
||||||
var setMethod = pi.GetSetMethod(true);
|
MethodInfo setMethod = pi.GetSetMethod(true);
|
||||||
if (setMethod != null)
|
if (setMethod != null)
|
||||||
TryCacheMember(setMethod, list, cachedSigs, declaringType, inspector, false);
|
TryCacheMember(setMethod, list, cachedSigs, declaringType, inspector, false);
|
||||||
return;
|
return;
|
||||||
@ -143,7 +141,7 @@ namespace UnityExplorer.CacheObject
|
|||||||
|
|
||||||
case MemberTypes.Field:
|
case MemberTypes.Field:
|
||||||
{
|
{
|
||||||
var fi = member as FieldInfo;
|
FieldInfo fi = member as FieldInfo;
|
||||||
cached = new CacheField(fi);
|
cached = new CacheField(fi);
|
||||||
returnType = fi.FieldType;
|
returnType = fi.FieldType;
|
||||||
break;
|
break;
|
||||||
|
@ -15,8 +15,8 @@ namespace UnityExplorer.Hooks
|
|||||||
{
|
{
|
||||||
// Static
|
// Static
|
||||||
|
|
||||||
private static readonly StringBuilder evalOutput = new StringBuilder();
|
private static readonly StringBuilder evalOutput = new();
|
||||||
private static readonly ScriptEvaluator scriptEvaluator = new ScriptEvaluator(new StringWriter(evalOutput));
|
private static readonly ScriptEvaluator scriptEvaluator = new(new StringWriter(evalOutput));
|
||||||
|
|
||||||
static HookInstance()
|
static HookInstance()
|
||||||
{
|
{
|
||||||
|
@ -46,7 +46,7 @@ namespace UnityExplorer.Inspectors.MouseInspectors
|
|||||||
IEnumerator SetPanelActiveCoro()
|
IEnumerator SetPanelActiveCoro()
|
||||||
{
|
{
|
||||||
yield return null;
|
yield return null;
|
||||||
var panel = UIManager.GetPanel<UiInspectorResultsPanel>(UIManager.Panels.UIInspectorResults);
|
var panel = UIManager.GetPanel<MouseInspectorResultsPanel>(UIManager.Panels.UIInspectorResults);
|
||||||
panel.SetActive(true);
|
panel.SetActive(true);
|
||||||
panel.ShowResults();
|
panel.ShowResults();
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,7 @@ using UniverseLib.UI;
|
|||||||
using UniverseLib.UI.Widgets.ButtonList;
|
using UniverseLib.UI.Widgets.ButtonList;
|
||||||
using UniverseLib.UI.Widgets.ScrollView;
|
using UniverseLib.UI.Widgets.ScrollView;
|
||||||
using UniverseLib.Utility;
|
using UniverseLib.Utility;
|
||||||
|
using UniverseLib.UI.Models;
|
||||||
|
|
||||||
namespace UnityExplorer.UI.Widgets.AutoComplete
|
namespace UnityExplorer.UI.Widgets.AutoComplete
|
||||||
{
|
{
|
||||||
@ -53,7 +54,7 @@ namespace UnityExplorer.UI.Widgets.AutoComplete
|
|||||||
OnClickedOutsidePanels += AutoCompleter_OnClickedOutsidePanels;
|
OnClickedOutsidePanels += AutoCompleter_OnClickedOutsidePanels;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void TakeOwnership(ISuggestionProvider provider)
|
public static void TakeOwnership(ISuggestionProvider provider)
|
||||||
{
|
{
|
||||||
CurrentHandler = provider;
|
CurrentHandler = provider;
|
||||||
navigationTipRow.SetActive(provider.AllowNavigation);
|
navigationTipRow.SetActive(provider.AllowNavigation);
|
||||||
@ -152,7 +153,8 @@ namespace UnityExplorer.UI.Widgets.AutoComplete
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
SelectedIndex = index;
|
SelectedIndex = index;
|
||||||
scrollPool.Refresh(true, false);
|
|
||||||
|
scrollPool.JumpToIndex(index, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Internal update
|
// Internal update
|
||||||
@ -173,8 +175,8 @@ namespace UnityExplorer.UI.Widgets.AutoComplete
|
|||||||
|
|
||||||
// Setting autocomplete cell buttons
|
// Setting autocomplete cell buttons
|
||||||
|
|
||||||
private readonly Color selectedSuggestionColor = new Color(45 / 255f, 75 / 255f, 80 / 255f);
|
private readonly Color selectedSuggestionColor = new(45 / 255f, 75 / 255f, 80 / 255f);
|
||||||
private readonly Color inactiveSuggestionColor = new Color(0.11f, 0.11f, 0.11f);
|
private readonly Color inactiveSuggestionColor = new(0.11f, 0.11f, 0.11f);
|
||||||
|
|
||||||
private List<Suggestion> GetEntries() => Suggestions;
|
private List<Suggestion> GetEntries() => Suggestions;
|
||||||
|
|
||||||
@ -201,21 +203,6 @@ namespace UnityExplorer.UI.Widgets.AutoComplete
|
|||||||
|
|
||||||
if (CurrentHandler.AllowNavigation && index == SelectedIndex && setFirstCell)
|
if (CurrentHandler.AllowNavigation && index == SelectedIndex && setFirstCell)
|
||||||
{
|
{
|
||||||
float diff = 0f;
|
|
||||||
// if cell is too far down
|
|
||||||
if (cell.Rect.MinY() > scrollPool.Viewport.MinY())
|
|
||||||
diff = cell.Rect.MinY() - scrollPool.Viewport.MinY();
|
|
||||||
// if cell is too far up
|
|
||||||
else if (cell.Rect.MaxY() < scrollPool.Viewport.MaxY())
|
|
||||||
diff = cell.Rect.MaxY() - scrollPool.Viewport.MaxY();
|
|
||||||
|
|
||||||
if (diff != 0.0f)
|
|
||||||
{
|
|
||||||
var pos = scrollPool.Content.anchoredPosition;
|
|
||||||
pos.y -= diff;
|
|
||||||
scrollPool.Content.anchoredPosition = pos;
|
|
||||||
}
|
|
||||||
|
|
||||||
RuntimeHelper.SetColorBlock(cell.Button.Component, selectedSuggestionColor);
|
RuntimeHelper.SetColorBlock(cell.Button.Component, selectedSuggestionColor);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -234,9 +221,9 @@ namespace UnityExplorer.UI.Widgets.AutoComplete
|
|||||||
if (CurrentHandler == null)
|
if (CurrentHandler == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var input = CurrentHandler.InputField;
|
InputFieldRef input = CurrentHandler.InputField;
|
||||||
|
|
||||||
if (input.Component.caretPosition == lastCaretPosition && input.UIRoot.transform.position == lastInputPosition)
|
if (!input.Component.isFocused || input.Component.caretPosition == lastCaretPosition && input.UIRoot.transform.position == lastInputPosition)
|
||||||
return;
|
return;
|
||||||
lastInputPosition = input.UIRoot.transform.position;
|
lastInputPosition = input.UIRoot.transform.position;
|
||||||
lastCaretPosition = input.Component.caretPosition;
|
lastCaretPosition = input.Component.caretPosition;
|
||||||
@ -257,9 +244,6 @@ namespace UnityExplorer.UI.Widgets.AutoComplete
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
uiRoot.transform.position = input.Transform.position + new Vector3(-(input.Transform.rect.width / 2) + 10, -20, 0);
|
uiRoot.transform.position = input.Transform.position + new Vector3(-(input.Transform.rect.width / 2) + 10, -20, 0);
|
||||||
//var textGen = input.Component.textComponent.cachedTextGenerator;
|
|
||||||
//var pos = input.UIRoot.transform.TransformPoint(textGen.characters[0].cursorPos);
|
|
||||||
//uiRoot.transform.position = new Vector3(pos.x + 10, pos.y - 20, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.Dragger.OnEndResize();
|
this.Dragger.OnEndResize();
|
||||||
|
@ -14,7 +14,7 @@ using UniverseLib.Utility;
|
|||||||
|
|
||||||
namespace UnityExplorer.UI.Panels
|
namespace UnityExplorer.UI.Panels
|
||||||
{
|
{
|
||||||
public class UiInspectorResultsPanel : UIPanel
|
public class MouseInspectorResultsPanel : UIPanel
|
||||||
{
|
{
|
||||||
public override UIManager.Panels PanelType => UIManager.Panels.UIInspectorResults;
|
public override UIManager.Panels PanelType => UIManager.Panels.UIInspectorResults;
|
||||||
|
|
@ -37,18 +37,18 @@ namespace UnityExplorer.UI.Panels
|
|||||||
&& (InputManager.GetMouseButtonDown(0) || InputManager.GetMouseButtonDown(1)))
|
&& (InputManager.GetMouseButtonDown(0) || InputManager.GetMouseButtonDown(1)))
|
||||||
{
|
{
|
||||||
int count = UIManager.PanelHolder.transform.childCount;
|
int count = UIManager.PanelHolder.transform.childCount;
|
||||||
var mousePos = DisplayManager.MousePosition;
|
Vector3 mousePos = DisplayManager.MousePosition;
|
||||||
bool clickedInAny = false;
|
bool clickedInAny = false;
|
||||||
|
|
||||||
for (int i = count - 1; i >= 0; i--)
|
for (int i = count - 1; i >= 0; i--)
|
||||||
{
|
{
|
||||||
// make sure this is a real recognized panel
|
// make sure this is a real recognized panel
|
||||||
var transform = UIManager.PanelHolder.transform.GetChild(i);
|
Transform transform = UIManager.PanelHolder.transform.GetChild(i);
|
||||||
if (!transformToPanelDict.TryGetValue(transform.GetInstanceID(), out UIPanel panel))
|
if (!transformToPanelDict.TryGetValue(transform.GetInstanceID(), out UIPanel panel))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// check if our mouse is clicking inside the panel
|
// check if our mouse is clicking inside the panel
|
||||||
var pos = panel.Rect.InverseTransformPoint(mousePos);
|
Vector3 pos = panel.Rect.InverseTransformPoint(mousePos);
|
||||||
if (!panel.Enabled || !panel.Rect.rect.Contains(pos))
|
if (!panel.Enabled || !panel.Rect.rect.Contains(pos))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
@ -105,7 +105,7 @@ namespace UnityExplorer.UI
|
|||||||
UIPanels.Add(Panels.Clipboard, new ClipboardPanel());
|
UIPanels.Add(Panels.Clipboard, new ClipboardPanel());
|
||||||
UIPanels.Add(Panels.ConsoleLog, new LogPanel());
|
UIPanels.Add(Panels.ConsoleLog, new LogPanel());
|
||||||
UIPanels.Add(Panels.Options, new OptionsPanel());
|
UIPanels.Add(Panels.Options, new OptionsPanel());
|
||||||
UIPanels.Add(Panels.UIInspectorResults, new UiInspectorResultsPanel());
|
UIPanels.Add(Panels.UIInspectorResults, new MouseInspectorResultsPanel());
|
||||||
UIPanels.Add(Panels.MouseInspector, new MouseInspector());
|
UIPanels.Add(Panels.MouseInspector, new MouseInspector());
|
||||||
|
|
||||||
foreach (var panel in UIPanels.Values)
|
foreach (var panel in UIPanels.Values)
|
||||||
|
@ -101,7 +101,7 @@ namespace UnityExplorer.UI.Widgets.AutoComplete
|
|||||||
public void HelperButtonClicked()
|
public void HelperButtonClicked()
|
||||||
{
|
{
|
||||||
GetSuggestions("");
|
GetSuggestions("");
|
||||||
AutoCompleteModal.Instance.TakeOwnership(this);
|
AutoCompleteModal.TakeOwnership(this);
|
||||||
AutoCompleteModal.Instance.SetSuggestions(suggestions);
|
AutoCompleteModal.Instance.SetSuggestions(suggestions);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,7 +119,7 @@ namespace UnityExplorer.UI.Widgets.AutoComplete
|
|||||||
{
|
{
|
||||||
GetSuggestions(value);
|
GetSuggestions(value);
|
||||||
|
|
||||||
AutoCompleteModal.Instance.TakeOwnership(this);
|
AutoCompleteModal.TakeOwnership(this);
|
||||||
AutoCompleteModal.Instance.SetSuggestions(suggestions);
|
AutoCompleteModal.Instance.SetSuggestions(suggestions);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -106,7 +106,7 @@ namespace UnityExplorer.UI.Widgets.AutoComplete
|
|||||||
{
|
{
|
||||||
GetSuggestions(value);
|
GetSuggestions(value);
|
||||||
|
|
||||||
AutoCompleteModal.Instance.TakeOwnership(this);
|
AutoCompleteModal.TakeOwnership(this);
|
||||||
AutoCompleteModal.Instance.SetSuggestions(suggestions);
|
AutoCompleteModal.Instance.SetSuggestions(suggestions);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user