mirror of
https://github.com/sinai-dev/UnityExplorer.git
synced 2024-12-23 01:59:40 +08:00
Code cleanup
This commit is contained in:
parent
47629d4764
commit
f19a1dd25e
@ -111,7 +111,7 @@ namespace UnityExplorer.CSConsole
|
||||
|
||||
if (suggestions.Any())
|
||||
{
|
||||
AutoCompleteModal.Instance.TakeOwnership(this);
|
||||
AutoCompleteModal.TakeOwnership(this);
|
||||
AutoCompleteModal.Instance.SetSuggestions(suggestions);
|
||||
}
|
||||
else
|
||||
|
@ -23,9 +23,9 @@ namespace UnityExplorer.CacheObject
|
||||
List<CacheMember> ctors = 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)
|
||||
flags |= BindingFlags.Instance;
|
||||
|
||||
@ -34,7 +34,7 @@ namespace UnityExplorer.CacheObject
|
||||
// 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.
|
||||
// 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);
|
||||
|
||||
// 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)
|
||||
TryCacheMember(prop, props, cachedSigs, declaringType, inspector);
|
||||
|
||||
foreach (var field in declaringType.GetFields(flags))
|
||||
foreach (FieldInfo field in declaringType.GetFields(flags))
|
||||
if (field.DeclaringType == declaringType)
|
||||
TryCacheMember(field, fields, cachedSigs, declaringType, inspector);
|
||||
|
||||
foreach (var method in declaringType.GetMethods(flags))
|
||||
foreach (MethodInfo method in declaringType.GetMethods(flags))
|
||||
if (method.DeclaringType == declaringType)
|
||||
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))
|
||||
.ThenBy(it => it.NameForFiltering));
|
||||
sorted.AddRange(fields.OrderBy(it => Array.IndexOf(types, it.DeclaringType))
|
||||
@ -86,9 +86,7 @@ namespace UnityExplorer.CacheObject
|
||||
|
||||
string sig = member switch
|
||||
{
|
||||
// method or constructor
|
||||
MethodBase mb => mb.FullDescription(),
|
||||
// property or field
|
||||
MethodBase mb => mb.FullDescription(), // (method or constructor)
|
||||
PropertyInfo or FieldInfo => $"{member.DeclaringType.FullDescription()}.{member.Name}",
|
||||
_ => throw new NotImplementedException(),
|
||||
};
|
||||
@ -105,7 +103,7 @@ namespace UnityExplorer.CacheObject
|
||||
{
|
||||
case MemberTypes.Constructor:
|
||||
{
|
||||
var ci = member as ConstructorInfo;
|
||||
ConstructorInfo ci = member as ConstructorInfo;
|
||||
cached = new CacheConstructor(ci);
|
||||
returnType = ci.DeclaringType;
|
||||
}
|
||||
@ -113,7 +111,7 @@ namespace UnityExplorer.CacheObject
|
||||
|
||||
case MemberTypes.Method:
|
||||
{
|
||||
var mi = member as MethodInfo;
|
||||
MethodInfo mi = member as MethodInfo;
|
||||
if (ignorePropertyMethodInfos
|
||||
&& (mi.Name.StartsWith("get_") || mi.Name.StartsWith("set_")))
|
||||
return;
|
||||
@ -125,12 +123,12 @@ namespace UnityExplorer.CacheObject
|
||||
|
||||
case MemberTypes.Property:
|
||||
{
|
||||
var pi = member as PropertyInfo;
|
||||
PropertyInfo pi = member as PropertyInfo;
|
||||
|
||||
if (!pi.CanRead && pi.CanWrite)
|
||||
{
|
||||
// write-only property, cache the set method instead.
|
||||
var setMethod = pi.GetSetMethod(true);
|
||||
MethodInfo setMethod = pi.GetSetMethod(true);
|
||||
if (setMethod != null)
|
||||
TryCacheMember(setMethod, list, cachedSigs, declaringType, inspector, false);
|
||||
return;
|
||||
@ -143,7 +141,7 @@ namespace UnityExplorer.CacheObject
|
||||
|
||||
case MemberTypes.Field:
|
||||
{
|
||||
var fi = member as FieldInfo;
|
||||
FieldInfo fi = member as FieldInfo;
|
||||
cached = new CacheField(fi);
|
||||
returnType = fi.FieldType;
|
||||
break;
|
||||
|
@ -15,8 +15,8 @@ namespace UnityExplorer.Hooks
|
||||
{
|
||||
// Static
|
||||
|
||||
private static readonly StringBuilder evalOutput = new StringBuilder();
|
||||
private static readonly ScriptEvaluator scriptEvaluator = new ScriptEvaluator(new StringWriter(evalOutput));
|
||||
private static readonly StringBuilder evalOutput = new();
|
||||
private static readonly ScriptEvaluator scriptEvaluator = new(new StringWriter(evalOutput));
|
||||
|
||||
static HookInstance()
|
||||
{
|
||||
|
@ -46,7 +46,7 @@ namespace UnityExplorer.Inspectors.MouseInspectors
|
||||
IEnumerator SetPanelActiveCoro()
|
||||
{
|
||||
yield return null;
|
||||
var panel = UIManager.GetPanel<UiInspectorResultsPanel>(UIManager.Panels.UIInspectorResults);
|
||||
var panel = UIManager.GetPanel<MouseInspectorResultsPanel>(UIManager.Panels.UIInspectorResults);
|
||||
panel.SetActive(true);
|
||||
panel.ShowResults();
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ using UniverseLib.UI;
|
||||
using UniverseLib.UI.Widgets.ButtonList;
|
||||
using UniverseLib.UI.Widgets.ScrollView;
|
||||
using UniverseLib.Utility;
|
||||
using UniverseLib.UI.Models;
|
||||
|
||||
namespace UnityExplorer.UI.Widgets.AutoComplete
|
||||
{
|
||||
@ -53,7 +54,7 @@ namespace UnityExplorer.UI.Widgets.AutoComplete
|
||||
OnClickedOutsidePanels += AutoCompleter_OnClickedOutsidePanels;
|
||||
}
|
||||
|
||||
public void TakeOwnership(ISuggestionProvider provider)
|
||||
public static void TakeOwnership(ISuggestionProvider provider)
|
||||
{
|
||||
CurrentHandler = provider;
|
||||
navigationTipRow.SetActive(provider.AllowNavigation);
|
||||
@ -152,7 +153,8 @@ namespace UnityExplorer.UI.Widgets.AutoComplete
|
||||
return;
|
||||
|
||||
SelectedIndex = index;
|
||||
scrollPool.Refresh(true, false);
|
||||
|
||||
scrollPool.JumpToIndex(index, null);
|
||||
}
|
||||
|
||||
// Internal update
|
||||
@ -173,8 +175,8 @@ namespace UnityExplorer.UI.Widgets.AutoComplete
|
||||
|
||||
// Setting autocomplete cell buttons
|
||||
|
||||
private readonly Color selectedSuggestionColor = new Color(45 / 255f, 75 / 255f, 80 / 255f);
|
||||
private readonly Color inactiveSuggestionColor = new Color(0.11f, 0.11f, 0.11f);
|
||||
private readonly Color selectedSuggestionColor = new(45 / 255f, 75 / 255f, 80 / 255f);
|
||||
private readonly Color inactiveSuggestionColor = new(0.11f, 0.11f, 0.11f);
|
||||
|
||||
private List<Suggestion> GetEntries() => Suggestions;
|
||||
|
||||
@ -201,21 +203,6 @@ namespace UnityExplorer.UI.Widgets.AutoComplete
|
||||
|
||||
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);
|
||||
}
|
||||
else
|
||||
@ -234,9 +221,9 @@ namespace UnityExplorer.UI.Widgets.AutoComplete
|
||||
if (CurrentHandler == null)
|
||||
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;
|
||||
lastInputPosition = input.UIRoot.transform.position;
|
||||
lastCaretPosition = input.Component.caretPosition;
|
||||
@ -257,9 +244,6 @@ namespace UnityExplorer.UI.Widgets.AutoComplete
|
||||
else
|
||||
{
|
||||
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();
|
||||
|
@ -14,7 +14,7 @@ using UniverseLib.Utility;
|
||||
|
||||
namespace UnityExplorer.UI.Panels
|
||||
{
|
||||
public class UiInspectorResultsPanel : UIPanel
|
||||
public class MouseInspectorResultsPanel : UIPanel
|
||||
{
|
||||
public override UIManager.Panels PanelType => UIManager.Panels.UIInspectorResults;
|
||||
|
@ -37,18 +37,18 @@ namespace UnityExplorer.UI.Panels
|
||||
&& (InputManager.GetMouseButtonDown(0) || InputManager.GetMouseButtonDown(1)))
|
||||
{
|
||||
int count = UIManager.PanelHolder.transform.childCount;
|
||||
var mousePos = DisplayManager.MousePosition;
|
||||
Vector3 mousePos = DisplayManager.MousePosition;
|
||||
bool clickedInAny = false;
|
||||
|
||||
for (int i = count - 1; i >= 0; i--)
|
||||
{
|
||||
// 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))
|
||||
continue;
|
||||
|
||||
// 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))
|
||||
continue;
|
||||
|
||||
|
@ -105,7 +105,7 @@ namespace UnityExplorer.UI
|
||||
UIPanels.Add(Panels.Clipboard, new ClipboardPanel());
|
||||
UIPanels.Add(Panels.ConsoleLog, new LogPanel());
|
||||
UIPanels.Add(Panels.Options, new OptionsPanel());
|
||||
UIPanels.Add(Panels.UIInspectorResults, new UiInspectorResultsPanel());
|
||||
UIPanels.Add(Panels.UIInspectorResults, new MouseInspectorResultsPanel());
|
||||
UIPanels.Add(Panels.MouseInspector, new MouseInspector());
|
||||
|
||||
foreach (var panel in UIPanels.Values)
|
||||
|
@ -101,7 +101,7 @@ namespace UnityExplorer.UI.Widgets.AutoComplete
|
||||
public void HelperButtonClicked()
|
||||
{
|
||||
GetSuggestions("");
|
||||
AutoCompleteModal.Instance.TakeOwnership(this);
|
||||
AutoCompleteModal.TakeOwnership(this);
|
||||
AutoCompleteModal.Instance.SetSuggestions(suggestions);
|
||||
}
|
||||
|
||||
@ -119,7 +119,7 @@ namespace UnityExplorer.UI.Widgets.AutoComplete
|
||||
{
|
||||
GetSuggestions(value);
|
||||
|
||||
AutoCompleteModal.Instance.TakeOwnership(this);
|
||||
AutoCompleteModal.TakeOwnership(this);
|
||||
AutoCompleteModal.Instance.SetSuggestions(suggestions);
|
||||
}
|
||||
}
|
||||
|
@ -106,7 +106,7 @@ namespace UnityExplorer.UI.Widgets.AutoComplete
|
||||
{
|
||||
GetSuggestions(value);
|
||||
|
||||
AutoCompleteModal.Instance.TakeOwnership(this);
|
||||
AutoCompleteModal.TakeOwnership(this);
|
||||
AutoCompleteModal.Instance.SetSuggestions(suggestions);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user