Compare commits

..

8 Commits

Author SHA1 Message Date
3b71b40843 More accurate check if enum value has flag 2022-03-15 01:51:27 +11:00
1292affe6d Fix autocomplete panel resizing 2022-03-15 01:50:50 +11:00
6614762fe8 Bump version 2022-03-15 01:19:52 +11:00
d81d6d034b Implement support for implicit struct constructors 2022-03-15 01:19:48 +11:00
5dfe3bbf0c Fix missing and incorrect ctor caching
- Shouldn't include ctors on abstract types
- Missing parameterless ctors for structs (implicit)
2022-03-15 01:19:01 +11:00
dc81451ce5 Make Constructor toggle button actually do something 2022-03-15 01:18:12 +11:00
d7ab0a23c6 Skip private/anonymous types in TypeCompleter results 2022-03-15 01:17:54 +11:00
1a01c740e2 Move AutoCompleteModal into Panels folder 2022-03-15 01:17:35 +11:00
8 changed files with 89 additions and 30 deletions

View File

@ -11,8 +11,9 @@ namespace UnityExplorer.CacheObject
public class CacheConstructor : CacheMember public class CacheConstructor : CacheMember
{ {
public ConstructorInfo CtorInfo { get; } public ConstructorInfo CtorInfo { get; }
readonly Type typeForStructConstructor;
public override Type DeclaringType => CtorInfo.DeclaringType; public override Type DeclaringType => typeForStructConstructor ?? CtorInfo.DeclaringType;
public override bool IsStatic => true; public override bool IsStatic => true;
public override bool ShouldAutoEvaluate => false; public override bool ShouldAutoEvaluate => false;
public override bool CanWrite => false; public override bool CanWrite => false;
@ -22,8 +23,27 @@ namespace UnityExplorer.CacheObject
this.CtorInfo = ci; this.CtorInfo = ci;
} }
public CacheConstructor(Type typeForStructConstructor)
{
this.typeForStructConstructor = typeForStructConstructor;
}
public override void SetInspectorOwner(ReflectionInspector inspector, MemberInfo member) public override void SetInspectorOwner(ReflectionInspector inspector, MemberInfo member)
{ {
// if is parameterless struct ctor
if (typeForStructConstructor != null)
{
this.Owner = inspector;
// eg. Vector3.Vector3()
this.NameLabelText = SignatureHighlighter.Parse(typeForStructConstructor, false);
NameLabelText += $".{NameLabelText}()";
this.NameForFiltering = SignatureHighlighter.RemoveHighlighting(NameLabelText);
this.NameLabelTextRaw = NameForFiltering;
return;
}
base.SetInspectorOwner(inspector, member); base.SetInspectorOwner(inspector, member);
Arguments = CtorInfo.GetParameters(); Arguments = CtorInfo.GetParameters();

View File

@ -187,11 +187,23 @@ namespace UnityExplorer.CacheObject
if (!inspector.StaticOnly) if (!inspector.StaticOnly)
flags |= BindingFlags.Instance; flags |= BindingFlags.Instance;
// Get non-static constructors of the main type. if (!type.IsAbstract)
// 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. // Get non-static constructors of the main type.
foreach (var ctor in type.GetConstructors(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)) // There's no reason to get the static cctor, it will be invoked when we inspect the class.
TryCacheMember(ctor, ctors, cachedSigs, type, inspector); // Also no point getting ctors on inherited types.
foreach (var ctor in type.GetConstructors(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance))
TryCacheMember(ctor, ctors, cachedSigs, type, inspector);
// structs always have a parameterless constructor
if (type.IsValueType)
{
CacheConstructor cached = new(type);
cached.SetFallbackType(type);
cached.SetInspectorOwner(inspector, null);
ctors.Add(cached);
}
}
foreach (var declaringType in types) foreach (var declaringType in types)
{ {

View File

@ -29,8 +29,11 @@ namespace UnityExplorer.CacheObject.IValues
private EnumCompleter enumCompleter; private EnumCompleter enumCompleter;
private GameObject toggleHolder; private GameObject toggleHolder;
private readonly List<Toggle> flagToggles = new List<Toggle>(); private readonly List<Toggle> flagToggles = new();
private readonly List<Text> flagTexts = new List<Text>(); private readonly List<Text> flagTexts = new();
public CachedEnumValue ValueAtIndex(int idx) => (CachedEnumValue)CurrentValues[idx];
public CachedEnumValue ValueAtKey(object key) => (CachedEnumValue)CurrentValues[key];
// Setting value from owner // Setting value from owner
public override void SetValue(object value) public override void SetValue(object value)
@ -70,13 +73,8 @@ namespace UnityExplorer.CacheObject.IValues
{ {
try try
{ {
var split = value.ToString().Split(',');
var set = new HashSet<string>();
foreach (var s in split)
set.Add(s.Trim());
for (int i = 0; i < CurrentValues.Count; i++) for (int i = 0; i < CurrentValues.Count; i++)
flagToggles[i].isOn = set.Contains(ValueAtIdx(i).Name); flagToggles[i].isOn = (value as Enum).HasFlag(ValueAtIndex(i).ActualValue as Enum);
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -116,7 +114,7 @@ namespace UnityExplorer.CacheObject.IValues
for (int i = 0; i < CurrentValues.Count; i++) for (int i = 0; i < CurrentValues.Count; i++)
{ {
if (flagToggles[i].isOn) if (flagToggles[i].isOn)
values.Add(ValueAtIdx(i).Name); values.Add(ValueAtIndex(i).Name);
} }
CurrentOwner.SetUserValue(Enum.Parse(EnumType, string.Join(", ", values.ToArray()))); CurrentOwner.SetUserValue(Enum.Parse(EnumType, string.Join(", ", values.ToArray())));
@ -166,9 +164,6 @@ namespace UnityExplorer.CacheObject.IValues
return UIRoot; return UIRoot;
} }
public CachedEnumValue ValueAtIdx(int idx) => (CachedEnumValue)CurrentValues[idx];
public CachedEnumValue ValueAtKey(object key) => (CachedEnumValue)CurrentValues[key];
private void SetupTogglesForEnumType() private void SetupTogglesForEnumType()
{ {
toggleHolder.SetActive(true); toggleHolder.SetActive(true);
@ -191,7 +186,7 @@ namespace UnityExplorer.CacheObject.IValues
AddToggleRow(); AddToggleRow();
flagToggles[i].isOn = false; flagToggles[i].isOn = false;
flagTexts[i].text = ValueAtIdx(i).Name; flagTexts[i].text = ValueAtIndex(i).Name;
} }
} }

View File

@ -18,7 +18,7 @@ namespace UnityExplorer
public static class ExplorerCore public static class ExplorerCore
{ {
public const string NAME = "UnityExplorer"; public const string NAME = "UnityExplorer";
public const string VERSION = "4.5.11"; public const string VERSION = "4.5.12";
public const string AUTHOR = "Sinai"; public const string AUTHOR = "Sinai";
public const string GUID = "com.sinai.unityexplorer"; public const string GUID = "com.sinai.unityexplorer";

View File

@ -262,7 +262,8 @@ namespace UnityExplorer.Inspectors
if ((member is CacheMethod && !MemberFilter.HasFlag(MemberFlags.Method)) if ((member is CacheMethod && !MemberFilter.HasFlag(MemberFlags.Method))
|| (member is CacheField && !MemberFilter.HasFlag(MemberFlags.Field)) || (member is CacheField && !MemberFilter.HasFlag(MemberFlags.Field))
|| (member is CacheProperty && !MemberFilter.HasFlag(MemberFlags.Property))) || (member is CacheProperty && !MemberFilter.HasFlag(MemberFlags.Property))
|| (member is CacheConstructor && !MemberFilter.HasFlag(MemberFlags.Constructor)))
continue; continue;
if (!string.IsNullOrEmpty(NameFilter) && !member.NameForFiltering.ContainsIgnoreCase(NameFilter)) if (!string.IsNullOrEmpty(NameFilter) && !member.NameForFiltering.ContainsIgnoreCase(NameFilter))

View File

@ -30,13 +30,13 @@ namespace UnityExplorer.UI.Widgets.AutoComplete
public override int MinWidth => -1; public override int MinWidth => -1;
public override int MinHeight => -1; public override int MinHeight => -1;
public override bool CanDragAndResize => false; public override bool CanDragAndResize => true;
public override bool ShouldSaveActiveState => false; public override bool ShouldSaveActiveState => false;
public override bool NavButtonWanted => false; public override bool NavButtonWanted => false;
public static ISuggestionProvider CurrentHandler { get; private set; } public static ISuggestionProvider CurrentHandler { get; private set; }
public static ButtonListHandler<Suggestion, ButtonCell> dataHandler; public static ButtonListHandler<Suggestion, ButtonCell> buttonListDataHandler;
public static ScrollPool<ButtonCell> scrollPool; public static ScrollPool<ButtonCell> scrollPool;
private static GameObject navigationTipRow; private static GameObject navigationTipRow;
@ -82,7 +82,7 @@ namespace UnityExplorer.UI.Widgets.AutoComplete
{ {
base.UIRoot.SetActive(true); base.UIRoot.SetActive(true);
base.UIRoot.transform.SetAsLastSibling(); base.UIRoot.transform.SetAsLastSibling();
dataHandler.RefreshData(); buttonListDataHandler.RefreshData();
scrollPool.Refresh(true, true); scrollPool.Refresh(true, true);
} }
} }
@ -294,20 +294,40 @@ namespace UnityExplorer.UI.Widgets.AutoComplete
// UI Construction // UI Construction
const float MIN_X = 0.42f;
const float MAX_Y = 0.6f;
protected internal override void DoSetDefaultPosAndAnchors() protected internal override void DoSetDefaultPosAndAnchors()
{ {
Rect.pivot = new Vector2(0f, 1f); Rect.pivot = new Vector2(0f, 1f);
Rect.anchorMin = new Vector2(0.42f, 0.4f); Rect.anchorMin = new Vector2(MIN_X, 0.4f);
Rect.anchorMax = new Vector2(0.68f, 0.6f); Rect.anchorMax = new Vector2(0.68f, MAX_Y);
}
public override void OnFinishResize(RectTransform panel)
{
float xDiff = panel.anchorMin.x - MIN_X;
float yDiff = panel.anchorMax.y - MAX_Y;
if (xDiff != 0 || yDiff != 0)
{
panel.anchorMin = new(MIN_X, panel.anchorMin.y - yDiff);
panel.anchorMax = new(panel.anchorMax.x - xDiff, MAX_Y);
}
base.OnFinishResize(panel);
} }
public override void ConstructPanelContent() public override void ConstructPanelContent()
{ {
dataHandler = new ButtonListHandler<Suggestion, ButtonCell>(scrollPool, GetEntries, SetCell, ShouldDisplay, OnCellClicked); // hide the titlebar
this.TitleBar.gameObject.SetActive(false);
buttonListDataHandler = new ButtonListHandler<Suggestion, ButtonCell>(scrollPool, GetEntries, SetCell, ShouldDisplay, OnCellClicked);
scrollPool = UIFactory.CreateScrollPool<ButtonCell>(this.uiContent, "AutoCompleter", out GameObject scrollObj, scrollPool = UIFactory.CreateScrollPool<ButtonCell>(this.uiContent, "AutoCompleter", out GameObject scrollObj,
out GameObject scrollContent); out GameObject scrollContent);
scrollPool.Initialize(dataHandler); scrollPool.Initialize(buttonListDataHandler);
UIFactory.SetLayoutElement(scrollObj, flexibleHeight: 9999); UIFactory.SetLayoutElement(scrollObj, flexibleHeight: 9999);
UIFactory.SetLayoutGroup<VerticalLayoutGroup>(scrollContent, true, false, true, false); UIFactory.SetLayoutGroup<VerticalLayoutGroup>(scrollContent, true, false, true, false);

View File

@ -1,6 +1,7 @@
using HarmonyLib; using HarmonyLib;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using UniverseLib; using UniverseLib;
using UniverseLib.UI; using UniverseLib.UI;
using UniverseLib.UI.Models; using UniverseLib.UI.Models;
@ -67,7 +68,17 @@ namespace UnityExplorer.UI.Widgets.AutoComplete
{ {
allowedTypes = new(); allowedTypes = new();
foreach (var entry in ReflectionUtility.AllTypes) foreach (var entry in ReflectionUtility.AllTypes)
allowedTypes.Add(entry.Value); {
// skip <PrivateImplementationDetails> and <AnonymousClass> classes
var type = entry.Value;
if (type.FullName.Contains("PrivateImplementationDetails")
|| type.FullName.Contains("DisplayClass")
|| type.FullName.Contains('<'))
{
continue;
}
allowedTypes.Add(type);
}
} }
} }

View File

@ -313,7 +313,7 @@
<Compile Include="UI\Panels\ObjectExplorerPanel.cs" /> <Compile Include="UI\Panels\ObjectExplorerPanel.cs" />
<Compile Include="UI\UIManager.cs" /> <Compile Include="UI\UIManager.cs" />
<Compile Include="UI\Panels\PanelDragger.cs" /> <Compile Include="UI\Panels\PanelDragger.cs" />
<Compile Include="UI\Widgets\AutoComplete\AutoCompleteModal.cs" /> <Compile Include="UI\Panels\AutoCompleteModal.cs" />
<Compile Include="UI\Widgets\AutoComplete\TypeCompleter.cs" /> <Compile Include="UI\Widgets\AutoComplete\TypeCompleter.cs" />
<Compile Include="ObjectExplorer\ObjectSearch.cs" /> <Compile Include="ObjectExplorer\ObjectSearch.cs" />
<Compile Include="ObjectExplorer\SceneExplorer.cs" /> <Compile Include="ObjectExplorer\SceneExplorer.cs" />