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

Commit 6989ea1

Browse files
committed
Misc cleanups
1 parent fcdfeb2 commit 6989ea1

File tree

7 files changed

+24
-18
lines changed

7 files changed

+24
-18
lines changed

src/CSConsole/ScriptEvaluator.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class ScriptEvaluator : Evaluator, IDisposable
1616
"mscorlib", "System.Core", "System", "System.Xml"
1717
};
1818

19-
internal static TextWriter _textWriter;
19+
internal TextWriter _textWriter;
2020
internal static StreamReportPrinter _reportPrinter;
2121

2222
public ScriptEvaluator(TextWriter tw) : base(BuildContext(tw))
@@ -51,8 +51,13 @@ private void Reference(Assembly asm)
5151
ReferenceAssembly(asm);
5252
}
5353

54+
private static CompilerContext context;
55+
5456
private static CompilerContext BuildContext(TextWriter tw)
5557
{
58+
if (context != null)
59+
return context;
60+
5661
_reportPrinter = new StreamReportPrinter(tw);
5762

5863
var settings = new CompilerSettings
@@ -65,7 +70,7 @@ private static CompilerContext BuildContext(TextWriter tw)
6570
EnhancedWarnings = false
6671
};
6772

68-
return new CompilerContext(settings, _reportPrinter);
73+
return context = new CompilerContext(settings, _reportPrinter);
6974
}
7075

7176
private static void ImportAppdomainAssemblies(Action<Assembly> import)

src/CacheObject/CacheMember.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ namespace UnityExplorer.CacheObject
1414
{
1515
public abstract class CacheMember : CacheObjectBase
1616
{
17-
//public ReflectionInspector ParentInspector { get; internal set; }
18-
//public bool AutoUpdateWanted { get; internal set; }
19-
2017
public abstract Type DeclaringType { get; }
2118
public string NameForFiltering { get; protected set; }
2219
public object DeclaringInstance => IsStatic ? null : (m_declaringInstance ?? (m_declaringInstance = Owner.Target.TryCast(DeclaringType)));
@@ -133,7 +130,6 @@ protected override bool SetCellEvaluateState(CacheObjectCell objectcell)
133130
return false;
134131
}
135132

136-
137133
public void OnEvaluateClicked()
138134
{
139135
if (!HasArguments)

src/Core/Reflection/Extensions.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@ public static T TryCast<T>(this object obj)
3131
}
3232
}
3333

34-
public static HashSet<Type> GetImplementationsOf(this Type baseType, bool allowAbstract, bool allowGeneric)
35-
=> ReflectionUtility.GetImplementationsOf(baseType, allowAbstract, allowGeneric);
36-
3734
// ------- Misc extensions --------
3835

3936
/// <summary>

src/Core/Reflection/ReflectionUtility.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -251,27 +251,25 @@ public static string GetImplementationKey(Type type)
251251
/// </summary>
252252
/// <param name="baseType">The base type, which can optionally be abstract / interface.</param>
253253
/// <returns>All implementations of the type in the current AppDomain.</returns>
254-
public static HashSet<Type> GetImplementationsOf(Type baseType, bool allowAbstract, bool allowGeneric, bool allowRecursive = true)
254+
public static HashSet<Type> GetImplementationsOf(Type baseType, bool allowAbstract, bool allowGeneric, bool allowEnum, bool allowRecursive = true)
255255
{
256256
var key = GetImplementationKey(baseType);
257257

258258
int count = AllTypes.Count;
259259
HashSet<Type> ret;
260260
if (!baseType.IsGenericParameter)
261-
ret = GetImplementations(key, baseType, allowAbstract, allowGeneric);
261+
ret = GetImplementations(key, baseType, allowAbstract, allowGeneric, allowEnum);
262262
else
263263
ret = GetGenericParameterImplementations(key, baseType, allowAbstract, allowGeneric);
264264

265265
// types were resolved during the parse, do it again if we're not already rebuilding.
266266
if (allowRecursive && AllTypes.Count != count)
267-
{
268267
ret = GetImplementationsOf(baseType, allowAbstract, allowGeneric, false);
269-
}
270268

271269
return ret;
272270
}
273271

274-
private static HashSet<Type> GetImplementations(string key, Type baseType, bool allowAbstract, bool allowGeneric)
272+
private static HashSet<Type> GetImplementations(string key, Type baseType, bool allowAbstract, bool allowGeneric, bool allowEnum)
275273
{
276274
if (!typeInheritance.ContainsKey(key))
277275
{
@@ -287,7 +285,8 @@ private static HashSet<Type> GetImplementations(string key, Type baseType, bool
287285
if (set.Contains(type)
288286
|| (type.IsAbstract && type.IsSealed) // ignore static classes
289287
|| (!allowAbstract && type.IsAbstract)
290-
|| (!allowGeneric && (type.IsGenericType || type.IsGenericTypeDefinition)))
288+
|| (!allowGeneric && (type.IsGenericType || type.IsGenericTypeDefinition))
289+
|| (!allowEnum && type.IsEnum))
291290
continue;
292291

293292
if (type.FullName.Contains("PrivateImplementationDetails")

src/Core/Runtime/RuntimeProvider.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ public static void Init() =>
5656

5757
public abstract int GetRootCount(Scene scene);
5858

59+
public void SetColorBlockAuto(Selectable selectable, Color baseColor)
60+
=> SetColorBlock(selectable, baseColor, baseColor * 1.2f, baseColor * 0.8f);
61+
5962
public abstract void SetColorBlock(Selectable selectable, ColorBlock colors);
6063

6164
public abstract void SetColorBlock(Selectable selectable, Color? normal = null, Color? highlighted = null, Color? pressed = null,

src/UI/Panels/ObjectExplorerPanel.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ protected internal override void DoSetDefaultPosAndAnchors()
102102
Rect.pivot = new Vector2(0f, 1f);
103103
Rect.anchorMin = new Vector2(0.125f, 0.175f);
104104
Rect.anchorMax = new Vector2(0.325f, 0.925f);
105-
//mainPanelRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 350);
106105
}
107106

108107
public override void ConstructPanelContent()

src/UI/Widgets/AutoComplete/TypeCompleter.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ public class TypeCompleter : ISuggestionProvider
2020

2121
public Type BaseType { get; set; }
2222
public Type[] GenericConstraints { get; set; }
23+
private bool allowAbstract;
24+
private bool allowEnum;
2325

2426
public InputFieldRef InputField { get; }
2527
public bool AnchorToCaretPosition => false;
@@ -33,11 +35,16 @@ public class TypeCompleter : ISuggestionProvider
3335

3436
bool ISuggestionProvider.AllowNavigation => false;
3537

36-
public TypeCompleter(Type baseType, InputFieldRef inputField)
38+
public TypeCompleter(Type baseType, InputFieldRef inputField) : this(baseType, inputField, true, true) { }
39+
40+
public TypeCompleter(Type baseType, InputFieldRef inputField, bool allowAbstract, bool allowEnum)
3741
{
3842
BaseType = baseType;
3943
InputField = inputField;
4044

45+
this.allowAbstract = allowAbstract;
46+
this.allowEnum = allowEnum;
47+
4148
inputField.OnValueChanged += OnInputFieldChanged;
4249

4350
if (BaseType != null)
@@ -46,7 +53,7 @@ public TypeCompleter(Type baseType, InputFieldRef inputField)
4653

4754
public void CacheTypes()
4855
{
49-
allowedTypes = ReflectionUtility.GetImplementationsOf(BaseType, true, false);
56+
allowedTypes = ReflectionUtility.GetImplementationsOf(BaseType, allowAbstract, allowEnum, false);
5057
}
5158

5259
public void OnSuggestionClicked(Suggestion suggestion)

0 commit comments

Comments
 (0)