Automatic code cleanup (no real changes)

- Use explicit type of var
- Use 'new()'
- Remove unnecessary usings
- Sort usings
- Apply formatting
This commit is contained in:
Sinai
2022-04-12 05:20:35 +10:00
parent 693f5818be
commit 7e0f98ef91
95 changed files with 732 additions and 1073 deletions

View File

@ -2,8 +2,6 @@
using System.Collections.Generic;
using System.Collections.Specialized;
using UnityExplorer.CacheObject.IValues;
using UniverseLib;
using UniverseLib.UI;
using UniverseLib.UI.Models;
using UniverseLib.Utility;
@ -30,8 +28,8 @@ namespace UnityExplorer.UI.Widgets.AutoComplete
public InputFieldRef InputField { get; }
public bool AnchorToCaretPosition => false;
private readonly List<Suggestion> suggestions = new List<Suggestion>();
private readonly HashSet<string> suggestedValues = new HashSet<string>();
private readonly List<Suggestion> suggestions = new();
private readonly HashSet<string> suggestedValues = new();
private OrderedDictionary enumValues;
@ -58,7 +56,7 @@ namespace UnityExplorer.UI.Widgets.AutoComplete
private string GetLastSplitInput(string fullInput)
{
string ret = fullInput;
int lastSplit = fullInput.LastIndexOf(',');
if (lastSplit >= 0)
{
@ -139,13 +137,13 @@ namespace UnityExplorer.UI.Widgets.AutoComplete
for (int i = 0; i < this.enumValues.Count; i++)
{
var enumValue = (CachedEnumValue)enumValues[i];
CachedEnumValue enumValue = (CachedEnumValue)enumValues[i];
if (enumValue.Name.ContainsIgnoreCase(value))
AddSuggestion(enumValue.Name);
}
}
internal static readonly Dictionary<string, string> sharedValueToLabel = new Dictionary<string, string>(4096);
internal static readonly Dictionary<string, string> sharedValueToLabel = new(4096);
void AddSuggestion(string value)
{

View File

@ -1,11 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using UnityEngine.UI;
using UniverseLib.UI;
using UniverseLib.UI.Models;
using UniverseLib.UI.Models;
namespace UnityExplorer.UI.Widgets.AutoComplete
{

View File

@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using UnityEngine;
namespace UnityExplorer.UI.Widgets.AutoComplete
namespace UnityExplorer.UI.Widgets.AutoComplete
{
public struct Suggestion
{

View File

@ -1,9 +1,7 @@
using HarmonyLib;
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using UniverseLib;
using UniverseLib.UI;
using UniverseLib.UI.Models;
using UniverseLib.Utility;
@ -67,10 +65,10 @@ namespace UnityExplorer.UI.Widgets.AutoComplete
else
{
allowedTypes = new();
foreach (var entry in ReflectionUtility.AllTypes)
foreach (KeyValuePair<string, Type> entry in ReflectionUtility.AllTypes)
{
// skip <PrivateImplementationDetails> and <AnonymousClass> classes
var type = entry.Value;
Type type = entry.Value;
if (type.FullName.Contains("PrivateImplementationDetails")
|| type.FullName.Contains("DisplayClass")
|| type.FullName.Contains('<'))
@ -126,7 +124,7 @@ namespace UnityExplorer.UI.Widgets.AutoComplete
if (ReflectionUtility.GetTypeByName(value) is Type t && allowedTypes.Contains(t))
AddSuggestion(t);
foreach (var entry in allowedTypes)
foreach (Type entry in allowedTypes)
{
if (entry.FullName.ContainsIgnoreCase(value))
AddSuggestion(entry);

View File

@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using UnityEngine;
using UnityEngine.UI;
using UnityExplorer.UI.Widgets.AutoComplete;
using UniverseLib.UI;
@ -41,8 +37,10 @@ namespace UnityExplorer.UI.Widgets
inputField.Component.lineType = InputField.LineType.MultiLineNewline;
inputField.UIRoot.AddComponent<ContentSizeFitter>().verticalFit = ContentSizeFitter.FitMode.PreferredSize;
typeCompleter = new TypeCompleter(typeof(object), this.inputField);
typeCompleter.Enabled = false;
typeCompleter = new TypeCompleter(typeof(object), this.inputField)
{
Enabled = false
};
CreateSpecialContent();

View File

@ -1,16 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using UnityEngine;
using UnityEngine.UI;
using UnityExplorer.UI;
using UniverseLib.UI.Models;
using UnityExplorer.UI.Widgets.AutoComplete;
using UniverseLib.UI;
using UniverseLib;
using UnityExplorer.CacheObject;
using UniverseLib.UI;
using UniverseLib.UI.Models;
using UniverseLib.UI.ObjectPool;
using UniverseLib.Utility;
@ -48,14 +43,14 @@ namespace UnityExplorer.UI.Widgets
public void OnReturnToPool()
{
foreach (var widget in paramHandlers)
foreach (ParameterHandler widget in paramHandlers)
{
widget.OnReturned();
Pool<ParameterHandler>.Return(widget);
}
paramHandlers = null;
foreach (var widget in genericHandlers)
foreach (GenericArgumentHandler widget in genericHandlers)
{
widget.OnReturned();
Pool<GenericArgumentHandler>.Return(widget);
@ -111,9 +106,9 @@ namespace UnityExplorer.UI.Widgets
{
for (int i = 0; i < genericArguments.Length; i++)
{
var type = genericArguments[i];
Type type = genericArguments[i];
var holder = genericHandlers[i] = Pool<GenericArgumentHandler>.Borrow();
GenericArgumentHandler holder = genericHandlers[i] = Pool<GenericArgumentHandler>.Borrow();
holder.UIRoot.transform.SetParent(this.genericArgumentsHolder.transform, false);
holder.OnBorrowed(this, type);
}
@ -123,9 +118,9 @@ namespace UnityExplorer.UI.Widgets
{
for (int i = 0; i < parameters.Length; i++)
{
var param = parameters[i];
ParameterInfo param = parameters[i];
var holder = paramHandlers[i] = Pool<ParameterHandler>.Borrow();
ParameterHandler holder = paramHandlers[i] = Pool<ParameterHandler>.Borrow();
holder.UIRoot.transform.SetParent(this.parametersHolder.transform, false);
holder.OnBorrowed(this, param);
}
@ -142,7 +137,7 @@ namespace UnityExplorer.UI.Widgets
// generic args
this.genericArgumentsHolder = UIFactory.CreateUIObject("GenericHolder", UIRoot);
UIFactory.SetLayoutElement(genericArgumentsHolder, flexibleWidth: 1000);
var genericsTitle = UIFactory.CreateLabel(genericArgumentsHolder, "GenericsTitle", "Generic Arguments", TextAnchor.MiddleLeft);
Text genericsTitle = UIFactory.CreateLabel(genericArgumentsHolder, "GenericsTitle", "Generic Arguments", TextAnchor.MiddleLeft);
UIFactory.SetLayoutElement(genericsTitle.gameObject, minHeight: 25, flexibleWidth: 1000);
UIFactory.SetLayoutGroup<VerticalLayoutGroup>(genericArgumentsHolder, false, false, true, true, 3);
UIFactory.SetLayoutElement(genericArgumentsHolder, minHeight: 25, flexibleHeight: 750, minWidth: 50, flexibleWidth: 9999);
@ -151,14 +146,14 @@ namespace UnityExplorer.UI.Widgets
// args
this.parametersHolder = UIFactory.CreateUIObject("ArgHolder", UIRoot);
UIFactory.SetLayoutElement(parametersHolder, flexibleWidth: 1000);
var argsTitle = UIFactory.CreateLabel(parametersHolder, "ArgsTitle", "Arguments", TextAnchor.MiddleLeft);
Text argsTitle = UIFactory.CreateLabel(parametersHolder, "ArgsTitle", "Arguments", TextAnchor.MiddleLeft);
UIFactory.SetLayoutElement(argsTitle.gameObject, minHeight: 25, flexibleWidth: 1000);
UIFactory.SetLayoutGroup<VerticalLayoutGroup>(parametersHolder, false, false, true, true, 3);
UIFactory.SetLayoutElement(parametersHolder, minHeight: 25, flexibleHeight: 750, minWidth: 50, flexibleWidth: 9999);
//argHolder.AddComponent<ContentSizeFitter>().verticalFit = ContentSizeFitter.FitMode.PreferredSize;
// evaluate button
var evalButton = UIFactory.CreateButton(UIRoot, "EvaluateButton", "Evaluate", new Color(0.2f, 0.2f, 0.2f));
ButtonRef evalButton = UIFactory.CreateButton(UIRoot, "EvaluateButton", "Evaluate", new Color(0.2f, 0.2f, 0.2f));
UIFactory.SetLayoutElement(evalButton.Component.gameObject, minHeight: 25, minWidth: 150, flexibleWidth: 0);
evalButton.OnClick += () =>
{

View File

@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UniverseLib;
using UniverseLib.Utility;
@ -20,10 +18,10 @@ namespace UnityExplorer.UI.Widgets
typeCompleter.BaseType = genericType;
typeCompleter.CacheTypes();
var constraints = genericType.GetGenericParameterConstraints();
Type[] constraints = genericType.GetGenericParameterConstraints();
typeCompleter.GenericConstraints = constraints;
var sb = new StringBuilder($"<color={SignatureHighlighter.CONST}>{genericType.Name}</color>");
StringBuilder sb = new($"<color={SignatureHighlighter.CONST}>{genericType.Name}</color>");
for (int j = 0; j < constraints.Length; j++)
{

View File

@ -1,11 +1,8 @@
using HarmonyLib;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Reflection;
using UnityEngine;
using UnityEngine.UI;
using UnityExplorer.CacheObject.IValues;
using UnityExplorer.UI.Panels;
using UnityExplorer.UI.Widgets.AutoComplete;
using UniverseLib;
@ -38,7 +35,7 @@ namespace UnityExplorer.UI.Widgets
if (paramType.IsByRef)
paramType = paramType.GetElementType();
this.argNameLabel.text =
this.argNameLabel.text =
$"{SignatureHighlighter.Parse(paramType, false)} <color={SignatureHighlighter.LOCAL_ARG}>{paramInfo.Name}</color>";
if (ParseUtility.CanParse(paramType) || typeof(Type).IsAssignableFrom(paramType))
@ -105,7 +102,7 @@ namespace UnityExplorer.UI.Widgets
if (usingBasicLabel)
return basicValue;
var input = this.inputField.Text;
string input = this.inputField.Text;
if (typeof(Type).IsAssignableFrom(paramType))
return ReflectionUtility.GetTypeByName(input);

View File

@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using UnityEngine;
namespace UnityExplorer.UI.Widgets
{

View File

@ -1,17 +1,9 @@
using HarmonyLib;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System;
using UnityEngine;
using UnityEngine.UI;
using UnityExplorer.Inspectors;
using UnityExplorer.UI.Widgets;
using UniverseLib;
using UniverseLib.UI;
using UniverseLib.UI.Models;
using UniverseLib.UI.Widgets;
using UniverseLib.UI.Widgets.ScrollView;
using UniverseLib.Utility;
@ -136,7 +128,7 @@ namespace UnityExplorer.UI.Widgets
if (int.TryParse(input.Trim(), out int index))
this.cachedTransform.Value.SetSiblingIndex(index);
this.SiblingIndex.Text = this.cachedTransform.Value.GetSiblingIndex().ToString();
}
@ -168,7 +160,7 @@ namespace UnityExplorer.UI.Widgets
// Name button
GameObject nameBtnHolder = UIFactory.CreateHorizontalGroup(this.UIRoot, "NameButtonHolder",
GameObject nameBtnHolder = UIFactory.CreateHorizontalGroup(this.UIRoot, "NameButtonHolder",
false, false, true, true, childAlignment: TextAnchor.MiddleLeft);
UIFactory.SetLayoutElement(nameBtnHolder, flexibleWidth: 9999, minHeight: 25, flexibleHeight: 0);
nameBtnHolder.AddComponent<Mask>().showMaskGraphic = false;

View File

@ -116,7 +116,7 @@ namespace UnityExplorer.UI.Widgets
public void JumpAndExpandToTransform(Transform transform)
{
// make sure all parents of the object are expanded
var parent = transform.parent;
Transform parent = transform.parent;
while (parent)
{
int pid = parent.GetInstanceID();
@ -136,7 +136,7 @@ namespace UnityExplorer.UI.Widgets
int idx;
for (idx = 0; idx < cachedTransforms.Count; idx++)
{
var cache = (CachedTransform)cachedTransforms[idx];
CachedTransform cache = (CachedTransform)cachedTransforms[idx];
if (cache.InstanceID == transformID)
break;
}
@ -151,7 +151,7 @@ namespace UnityExplorer.UI.Widgets
private IEnumerator HighlightCellCoroutine(TransformCell cell)
{
var button = cell.NameButton.Component;
UnityEngine.UI.Button button = cell.NameButton.Component;
button.StartColorTween(new Color(0.2f, 0.3f, 0.2f), false);
float start = Time.realtimeSinceStartup;
@ -191,7 +191,7 @@ namespace UnityExplorer.UI.Widgets
bool filtering = Filtering;
IEnumerable<GameObject> rootObjects = GetRootEntriesMethod();
foreach (var gameObj in rootObjects)
foreach (GameObject gameObj in rootObjects)
{
if (!gameObj)
continue;
@ -214,7 +214,7 @@ namespace UnityExplorer.UI.Widgets
traversedThisFrame.Start();
}
var cached = (CachedTransform)cachedTransforms[i];
CachedTransform cached = (CachedTransform)cachedTransforms[i];
if (!visited.Contains(cached.InstanceID))
{
cachedTransforms.RemoveAt(i);
@ -227,7 +227,7 @@ namespace UnityExplorer.UI.Widgets
prevDisplayIndex = displayIndex;
refreshCoroutine = null;
}
}
// Recursive method to check a Transform and its children (if expanded).
// Parent and depth can be null/default.
@ -293,7 +293,7 @@ namespace UnityExplorer.UI.Widgets
{
for (int i = 0; i < transform.childCount; i++)
{
var enumerator = Traverse(transform.GetChild(i), cached, depth + 1, oneShot, filtering);
IEnumerator enumerator = Traverse(transform.GetChild(i), cached, depth + 1, oneShot, filtering);
while (enumerator.MoveNext())
{
if (!oneShot)
@ -350,7 +350,7 @@ namespace UnityExplorer.UI.Widgets
public void OnCellExpandToggled(CachedTransform cache)
{
var instanceID = cache.InstanceID;
int instanceID = cache.InstanceID;
if (expandedInstanceIDs.Contains(instanceID))
expandedInstanceIDs.Remove(instanceID);
else

View File

@ -1,8 +1,6 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using UnityEngine;
using UnityEngine.UI;
@ -273,7 +271,7 @@ namespace UnityExplorer.UI.Widgets
}
}
#region SavWav
#region SavWav
// Copyright (c) 2012 Calvin Rien
// http://the.darktable.com
@ -404,6 +402,6 @@ namespace UnityExplorer.UI.Widgets
stream.Seek(0, SeekOrigin.Begin);
}
#endregion
#endregion
}
}

View File

@ -1,9 +1,6 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using UnityEngine;
using UnityEngine.UI;
using UnityExplorer.Config;
@ -223,15 +220,15 @@ namespace UnityExplorer.UI.Widgets
// Actual texture viewer
GameObject imageViewport = UIFactory.CreateVerticalGroup(textureViewerRoot, "ImageViewport", false, false, true, true,
bgColor: new(1,1,1,0), childAlignment: TextAnchor.MiddleCenter);
GameObject imageViewport = UIFactory.CreateVerticalGroup(textureViewerRoot, "ImageViewport", false, false, true, true,
bgColor: new(1, 1, 1, 0), childAlignment: TextAnchor.MiddleCenter);
UIFactory.SetLayoutElement(imageViewport, flexibleWidth: 9999, flexibleHeight: 9999);
GameObject imageHolder = UIFactory.CreateUIObject("ImageHolder", imageViewport);
imageLayout = UIFactory.SetLayoutElement(imageHolder, 1, 1, 0, 0);
var actualImageObj = UIFactory.CreateUIObject("ActualImage", imageHolder);
var actualRect = actualImageObj.GetComponent<RectTransform>();
GameObject actualImageObj = UIFactory.CreateUIObject("ActualImage", imageHolder);
RectTransform actualRect = actualImageObj.GetComponent<RectTransform>();
actualRect.anchorMin = new(0, 0);
actualRect.anchorMax = new(1, 1);
image = actualImageObj.AddComponent<Image>();

View File

@ -105,7 +105,7 @@ namespace UnityExplorer.UI.Widgets
UIFactory.SetLayoutGroup<HorizontalLayoutGroup>(UIRoot, false, false, true, true, 5);
UIFactory.SetLayoutElement(UIRoot, minHeight: 25, flexibleHeight: 0, flexibleWidth: 9999);
var nameLabel = UIFactory.CreateLabel(UIRoot, "NameLabel", "Name:", TextAnchor.MiddleLeft, Color.grey);
Text nameLabel = UIFactory.CreateLabel(UIRoot, "NameLabel", "Name:", TextAnchor.MiddleLeft, Color.grey);
UIFactory.SetLayoutElement(nameLabel.gameObject, minHeight: 25, minWidth: 45, flexibleWidth: 0);
nameInput = UIFactory.CreateInputField(UIRoot, "NameInput", "untitled");
@ -116,7 +116,7 @@ namespace UnityExplorer.UI.Widgets
UIFactory.SetLayoutElement(gameObjectButton.Component.gameObject, minHeight: 25, minWidth: 160);
gameObjectButton.OnClick += OnGameObjectButtonClicked;
var instanceLabel = UIFactory.CreateLabel(UIRoot, "InstanceLabel", "Instance ID:", TextAnchor.MiddleRight, Color.grey);
Text instanceLabel = UIFactory.CreateLabel(UIRoot, "InstanceLabel", "Instance ID:", TextAnchor.MiddleRight, Color.grey);
UIFactory.SetLayoutElement(instanceLabel.gameObject, minHeight: 25, minWidth: 100, flexibleWidth: 0);
instanceIdInput = UIFactory.CreateInputField(UIRoot, "InstanceIDInput", "ERROR");