Finished argument inputs for Method/Props, some UI cleanups and fixes

This commit is contained in:
sinaioutlander
2020-11-14 19:51:16 +11:00
parent 755eae293e
commit 2819ced303
18 changed files with 613 additions and 183 deletions

View File

@ -86,9 +86,7 @@ namespace UnityExplorer.Inspectors.Reflection
public object[] ParseArguments()
{
if (m_arguments.Length < 1)
{
return new object[0];
}
var parsedArgs = new List<object>();
for (int i = 0; i < m_arguments.Length; i++)
@ -97,9 +95,7 @@ namespace UnityExplorer.Inspectors.Reflection
var type = m_arguments[i].ParameterType;
if (type.IsByRef)
{
type = type.GetElementType();
}
if (!string.IsNullOrEmpty(input))
{
@ -120,7 +116,7 @@ namespace UnityExplorer.Inspectors.Reflection
}
catch
{
ExplorerCore.Log($"Argument #{i} '{m_arguments[i].Name}' ({type.Name}), could not parse input '{input}'.");
ExplorerCore.Log($"Could not parse input '{input}' for argument #{i} '{m_arguments[i].Name}' ({type.FullName})");
}
}
}
@ -300,46 +296,12 @@ namespace UnityExplorer.Inspectors.Reflection
rightGroup.padding.top = 2;
rightGroup.padding.bottom = 2;
// evaluate button
if (this is CacheMethod || HasParameters)
{
var color = HasParameters ? new Color(0.4f, 0.4f, 0.4f) : new Color(0.3f, 0.6f, 0.3f);
ConstructArgInput(out GameObject argsHolder);
var evalButtonObj = UIFactory.CreateButton(m_rightGroup, color);
var evalLayout = evalButtonObj.AddComponent<LayoutElement>();
evalLayout.minWidth = 100;
evalLayout.minHeight = 22;
evalLayout.flexibleWidth = 0;
var evalText = evalButtonObj.GetComponentInChildren<Text>();
evalText.text = HasParameters
? $"Evaluate ({ParamCount})"
: "Evaluate";
var evalButton = evalButtonObj.GetComponent<Button>();
var colors = evalButton.colors;
colors.highlightedColor = new Color(0.4f, 0.7f, 0.4f);
evalButton.colors = colors;
evalButton.onClick.AddListener(OnMainEvaluateButton);
void OnMainEvaluateButton()
{
if (HasParameters)
{
// todo show parameter input
ExplorerCore.Log("TODO params");
}
else
{
// method with no parameters
(this as CacheMethod).Evaluate();
}
}
}
ConstructEvaluateButtons(argsHolder);
// subcontent
// todo check if IValue actually has subcontent
m_subContent = UIFactory.CreateHorizontalGroup(m_parentContent, new Color(1, 1, 1, 0));
var subGroup = m_subContent.GetComponent<HorizontalLayoutGroup>();
subGroup.childForceExpandWidth = true;
@ -352,11 +314,174 @@ namespace UnityExplorer.Inspectors.Reflection
m_subContent.SetActive(false);
// Construct InteractiveValue UI
// Construct InteractiveValue's actual UI
IValue.ConstructUI(m_rightGroup, m_subContent);
}
internal void ConstructArgInput(out GameObject argsHolder)
{
argsHolder = null;
if (HasParameters)
{
argsHolder = UIFactory.CreateVerticalGroup(m_rightGroup, new Color(1, 1, 1, 0));
var argsGroup = argsHolder.GetComponent<VerticalLayoutGroup>();
argsGroup.spacing = 4;
if (this is CacheMethod cm && cm.GenericArgs.Length > 0)
{
cm.ConstructGenericArgInput(argsHolder);
}
// todo normal args
if (m_arguments.Length > 0)
{
var titleObj = UIFactory.CreateLabel(argsHolder, TextAnchor.MiddleLeft);
var titleText = titleObj.GetComponent<Text>();
titleText.text = "<b>Arguments:</b>";
for (int i = 0; i < m_arguments.Length; i++)
{
AddArgRow(i, argsHolder);
}
}
argsHolder.SetActive(false);
}
}
internal void AddArgRow(int i, GameObject parent)
{
var arg = m_arguments[i];
var rowObj = UIFactory.CreateHorizontalGroup(parent, new Color(1, 1, 1, 0));
var rowLayout = rowObj.AddComponent<LayoutElement>();
rowLayout.minHeight = 25;
rowLayout.flexibleWidth = 5000;
var rowGroup = rowObj.GetComponent<HorizontalLayoutGroup>();
rowGroup.childForceExpandHeight = true;
rowGroup.spacing = 4;
var argLabelObj = UIFactory.CreateLabel(rowObj, TextAnchor.MiddleLeft);
//var argLayout = argLabelObj.AddComponent<LayoutElement>();
//argLayout.minWidth = 20;
var argText = argLabelObj.GetComponent<Text>();
var argTypeTxt = UISyntaxHighlight.ParseFullSyntax(arg.ParameterType, false);
argText.text = $"{argTypeTxt} <color={UISyntaxHighlight.Local}>{arg.Name}</color>";
var argInputObj = UIFactory.CreateInputField(rowObj, 14, (int)TextAnchor.MiddleLeft, 1);
var argInputLayout = argInputObj.AddComponent<LayoutElement>();
argInputLayout.flexibleWidth = 1200;
var argInput = argInputObj.GetComponent<InputField>();
argInput.onValueChanged.AddListener((string val) => { m_argumentInput[i] = val; });
if (arg.IsOptional)
{
var phInput = argInput.placeholder.GetComponent<Text>();
phInput.text = " = " + arg.DefaultValue?.ToString() ?? "null";
}
}
internal void ConstructEvaluateButtons(GameObject argsHolder)
{
if (HasParameters)
{
var evalGroupObj = UIFactory.CreateHorizontalGroup(m_rightGroup, new Color(1, 1, 1, 0));
var evalGroup = evalGroupObj.GetComponent<HorizontalLayoutGroup>();
evalGroup.childForceExpandWidth = false;
evalGroup.childForceExpandHeight = false;
evalGroup.spacing = 5;
var evalGroupLayout = evalGroupObj.AddComponent<LayoutElement>();
evalGroupLayout.minHeight = 25;
evalGroupLayout.flexibleHeight = 0;
evalGroupLayout.flexibleWidth = 5000;
var evalButtonObj = UIFactory.CreateButton(evalGroupObj, new Color(0.4f, 0.4f, 0.4f));
var evalLayout = evalButtonObj.AddComponent<LayoutElement>();
evalLayout.minWidth = 100;
evalLayout.minHeight = 22;
evalLayout.flexibleWidth = 0;
var evalText = evalButtonObj.GetComponentInChildren<Text>();
evalText.text = $"Evaluate ({ParamCount})";
var evalButton = evalButtonObj.GetComponent<Button>();
var colors = evalButton.colors;
colors.highlightedColor = new Color(0.4f, 0.7f, 0.4f);
evalButton.colors = colors;
var cancelButtonObj = UIFactory.CreateButton(evalGroupObj, new Color(0.6f, 0.3f, 0.3f));
var cancelLayout = cancelButtonObj.AddComponent<LayoutElement>();
cancelLayout.minWidth = 100;
cancelLayout.minHeight = 22;
cancelLayout.flexibleWidth = 0;
var cancelText = cancelButtonObj.GetComponentInChildren<Text>();
cancelText.text = "Cancel";
cancelButtonObj.SetActive(false);
evalButton.onClick.AddListener(() =>
{
if (!m_isEvaluating)
{
argsHolder.SetActive(true);
m_isEvaluating = true;
evalText.text = "Evaluate";
colors = evalButton.colors;
colors.normalColor = new Color(0.3f, 0.6f, 0.3f);
evalButton.colors = colors;
cancelButtonObj.SetActive(true);
}
else
{
if (this is CacheMethod cm)
cm.Evaluate();
else
UpdateValue();
}
});
var cancelButton = cancelButtonObj.GetComponent<Button>();
cancelButton.onClick.AddListener(() =>
{
cancelButtonObj.SetActive(false);
argsHolder.SetActive(false);
m_isEvaluating = false;
evalText.text = $"Evaluate ({ParamCount})";
colors = evalButton.colors;
colors.normalColor = new Color(0.4f, 0.4f, 0.4f);
evalButton.colors = colors;
});
}
else if (this is CacheMethod)
{
// simple method evaluate button
var evalButtonObj = UIFactory.CreateButton(m_rightGroup, new Color(0.3f, 0.6f, 0.3f));
var evalLayout = evalButtonObj.AddComponent<LayoutElement>();
evalLayout.minWidth = 100;
evalLayout.minHeight = 22;
evalLayout.flexibleWidth = 0;
var evalText = evalButtonObj.GetComponentInChildren<Text>();
evalText.text = "Evaluate";
var evalButton = evalButtonObj.GetComponent<Button>();
var colors = evalButton.colors;
colors.highlightedColor = new Color(0.4f, 0.7f, 0.4f);
evalButton.colors = colors;
evalButton.onClick.AddListener(OnMainEvaluateButton);
void OnMainEvaluateButton()
{
(this as CacheMethod).Evaluate();
}
}
}
#endregion
}
}

View File

@ -3,7 +3,8 @@ using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using UnityEngine;
using UnityExplorer.UI.Shared;
using UnityEngine.UI;
using UnityExplorer.UI;
using UnityExplorer.Helpers;
namespace UnityExplorer.Inspectors.Reflection
@ -28,6 +29,7 @@ namespace UnityExplorer.Inspectors.Reflection
GenericArgs = methodInfo.GetGenericArguments();
GenericConstraints = GenericArgs.Select(x => x.GetGenericParameterConstraints())
.Where(x => x != null)
.ToArray();
m_genericArgInput = new string[GenericArgs.Length];
@ -77,7 +79,7 @@ namespace UnityExplorer.Inspectors.Reflection
}
IValue.Value = ret;
IValue.UpdateValue();
IValue.OnValueUpdated();
//if (ret != null)
//{
@ -133,5 +135,68 @@ namespace UnityExplorer.Inspectors.Reflection
return mi;
}
#region UI CONSTRUCTION
internal void ConstructGenericArgInput(GameObject parent)
{
var titleObj = UIFactory.CreateLabel(parent, TextAnchor.MiddleLeft);
var titleText = titleObj.GetComponent<Text>();
titleText.text = "<b>Generic Arguments:</b>";
for (int i = 0; i < GenericArgs.Length; i++)
{
AddGenericArgRow(i, parent);
}
}
internal void AddGenericArgRow(int i, GameObject parent)
{
var arg = GenericArgs[i];
string constrainTxt = "";
if (this.GenericConstraints[i].Length > 0)
{
foreach (var constraint in this.GenericConstraints[i])
{
if (constrainTxt != "")
constrainTxt += ", ";
constrainTxt += $"{UISyntaxHighlight.ParseFullSyntax(constraint, false)}";
}
}
else
constrainTxt = $"Any";
var rowObj = UIFactory.CreateHorizontalGroup(parent, new Color(1, 1, 1, 0));
var rowLayout = rowObj.AddComponent<LayoutElement>();
rowLayout.minHeight = 25;
rowLayout.flexibleWidth = 5000;
var rowGroup = rowObj.GetComponent<HorizontalLayoutGroup>();
rowGroup.childForceExpandHeight = true;
rowGroup.spacing = 4;
var argLabelObj = UIFactory.CreateLabel(rowObj, TextAnchor.MiddleLeft);
//var argLayout = argLabelObj.AddComponent<LayoutElement>();
//argLayout.minWidth = 20;
var argText = argLabelObj.GetComponent<Text>();
argText.text = $"{constrainTxt} <color={UISyntaxHighlight.Enum}>{arg.Name}</color>";
var argInputObj = UIFactory.CreateInputField(rowObj, 14, (int)TextAnchor.MiddleLeft, 1);
var argInputLayout = argInputObj.AddComponent<LayoutElement>();
argInputLayout.flexibleWidth = 1200;
var argInput = argInputObj.GetComponent<InputField>();
argInput.onValueChanged.AddListener((string val) => { m_genericArgInput[i] = val; });
//var constraintLabelObj = UIFactory.CreateLabel(rowObj, TextAnchor.MiddleLeft);
//var constraintLayout = constraintLabelObj.AddComponent<LayoutElement>();
//constraintLayout.minWidth = 60;
//constraintLayout.flexibleWidth = 100;
//var constraintText = constraintLabelObj.GetComponent<Text>();
//constraintText.text = ;
}
#endregion
}
}

View File

@ -24,14 +24,18 @@ namespace UnityExplorer.Inspectors.Reflection
{
if (valueType == null && value == null)
{
ExplorerCore.LogWarning("CacheObjectBase: Trying to init with no default value or valueType!");
ExplorerCore.Log(Environment.StackTrace);
return;
}
// TEMP
IValue = new InteractiveValue
// temp (havent made rest of InteractiveValue classes yet, just using base class always)
valueType = ReflectionHelpers.GetActualType(value) ?? valueType;
IValue = new InteractiveValue(valueType)
{
OwnerCacheObject = this,
ValueType = ReflectionHelpers.GetActualType(value) ?? valueType,
OwnerCacheObject = this
};
UpdateValue();
}
@ -45,6 +49,7 @@ namespace UnityExplorer.Inspectors.Reflection
}
m_mainContent.SetActive(true);
m_mainContent.transform.SetAsLastSibling();
}
public virtual void Disable()
@ -54,7 +59,7 @@ namespace UnityExplorer.Inspectors.Reflection
public virtual void UpdateValue()
{
IValue.UpdateValue();
IValue.OnValueUpdated();
}
public virtual void SetValue() => throw new NotImplementedException();

View File

@ -10,7 +10,7 @@ namespace UnityExplorer.Inspectors.Reflection
{
public class CacheProperty : CacheMember
{
public override bool IsStatic => (MemInfo as PropertyInfo).GetAccessors()[0].IsStatic;
public override bool IsStatic => (MemInfo as PropertyInfo).GetAccessors(true)[0].IsStatic;
public CacheProperty(PropertyInfo propertyInfo, object declaringInstance) : base(propertyInfo, declaringInstance)
{
@ -41,12 +41,9 @@ namespace UnityExplorer.Inspectors.Reflection
m_evaluated = true;
ReflectionException = null;
}
else // create a dummy value for Write-Only properties.
else
{
if (IValue.ValueType == typeof(string))
IValue.Value = "";
else
IValue.Value = Activator.CreateInstance(IValue.ValueType);
// todo write-only properties
}
}

View File

@ -1,26 +1,123 @@
using System;
using System.Reflection;
using UnityEngine;
using UnityExplorer.Helpers;
using UnityExplorer.UI;
using UnityEngine.UI;
namespace UnityExplorer.Inspectors.Reflection
{
public enum MemberScopes
{
All,
Instance,
Static
}
public class InstanceInspector : ReflectionInspector
{
public override string TabLabel => $" <color=cyan>[R]</color> {base.TabLabel}";
public InstanceInspector(object target) : base(target)
internal MemberScopes m_scopeFilter;
internal Button m_lastActiveScopeButton;
public InstanceInspector(object target) : base(target) { }
private void OnScopeFilterClicked(MemberScopes type, Button button)
{
// needed?
if (m_lastActiveScopeButton)
{
var lastColors = m_lastActiveScopeButton.colors;
lastColors.normalColor = new Color(0.2f, 0.2f, 0.2f);
m_lastActiveScopeButton.colors = lastColors;
}
m_scopeFilter = type;
m_lastActiveScopeButton = button;
var colors = m_lastActiveScopeButton.colors;
colors.normalColor = new Color(0.2f, 0.6f, 0.2f);
m_lastActiveScopeButton.colors = colors;
FilterMembers(null, true);
m_sliderScroller.m_slider.value = 1f;
}
public void ConstructInstanceHelpers(GameObject parent)
public void ConstructInstanceHelpers()
{
// todo
// On second thought, I'm not sure about this, seems unnecessary (and bloaty)
// I might do the Texture2D helper (view/save image) but idk about anything else.
//if (typeof(Component).IsAssignableFrom(m_targetType))
//{
// // component helpers (ref GO)
// var tempObj = UIFactory.CreateLabel(Content, TextAnchor.MiddleLeft);
// var text = tempObj.GetComponent<Text>();
// text.text = "TODO comp helpers";
//}
//else if (typeof(UnityEngine.Object).IsAssignableFrom(m_targetType))
//{
// // unityengine.object helpers (name, instantiate, destroy?)
// var tempObj = UIFactory.CreateLabel(Content, TextAnchor.MiddleLeft);
// var text = tempObj.GetComponent<Text>();
// text.text = "TODO unity object helpers";
//}
}
public void ConstructInstanceFilters(GameObject parent)
{
// todo
var memberFilterRowObj = UIFactory.CreateHorizontalGroup(parent, new Color(1, 1, 1, 0));
var memFilterGroup = memberFilterRowObj.GetComponent<HorizontalLayoutGroup>();
memFilterGroup.childForceExpandHeight = false;
memFilterGroup.childForceExpandWidth = false;
memFilterGroup.childControlWidth = true;
memFilterGroup.childControlHeight = true;
memFilterGroup.spacing = 5;
var memFilterLayout = memberFilterRowObj.AddComponent<LayoutElement>();
memFilterLayout.minHeight = 25;
memFilterLayout.flexibleHeight = 0;
memFilterLayout.flexibleWidth = 5000;
var memLabelObj = UIFactory.CreateLabel(memberFilterRowObj, TextAnchor.MiddleLeft);
var memLabelLayout = memLabelObj.AddComponent<LayoutElement>();
memLabelLayout.minWidth = 100;
memLabelLayout.minHeight = 25;
memLabelLayout.flexibleWidth = 0;
var memLabelText = memLabelObj.GetComponent<Text>();
memLabelText.text = "Filter scope:";
memLabelText.color = Color.grey;
AddFilterButton(memberFilterRowObj, MemberScopes.All, true);
AddFilterButton(memberFilterRowObj, MemberScopes.Instance);
AddFilterButton(memberFilterRowObj, MemberScopes.Static);
}
private void AddFilterButton(GameObject parent, MemberScopes type, bool setEnabled = false)
{
var btnObj = UIFactory.CreateButton(parent, new Color(0.2f, 0.2f, 0.2f));
var btnLayout = btnObj.AddComponent<LayoutElement>();
btnLayout.minHeight = 25;
btnLayout.minWidth = 70;
var text = btnObj.GetComponentInChildren<Text>();
text.text = type.ToString();
var btn = btnObj.GetComponent<Button>();
btn.onClick.AddListener(() => { OnScopeFilterClicked(type, btn); });
var colors = btn.colors;
colors.highlightedColor = new Color(0.3f, 0.7f, 0.3f);
if (setEnabled)
{
colors.normalColor = new Color(0.2f, 0.6f, 0.2f);
m_scopeFilter = type;
m_lastActiveScopeButton = btn;
}
btn.colors = colors;
}
}
}

View File

@ -7,17 +7,20 @@ using UnityEngine.EventSystems;
using UnityEngine.UI;
using UnityExplorer.Helpers;
using UnityExplorer.UI;
using UnityExplorer.UI.Shared;
using UnityExplorer.Unstrip;
namespace UnityExplorer.Inspectors.Reflection
{
public class InteractiveValue
{
public InteractiveValue(Type valueType)
{
this.ValueType = valueType;
}
public CacheObjectBase OwnerCacheObject;
public object Value { get; set; }
public Type ValueType;
public readonly Type ValueType;
// might not need
public virtual bool HasSubContent => false;
@ -31,10 +34,10 @@ namespace UnityExplorer.Inspectors.Reflection
public virtual void Init()
{
UpdateValue();
OnValueUpdated();
}
public virtual void UpdateValue()
public virtual void OnValueUpdated()
{
if (!m_text)
return;
@ -55,10 +58,9 @@ namespace UnityExplorer.Inspectors.Reflection
public string GetLabelForValue()
{
if (Value != null)
ValueType = Value.GetType();
var valueType = Value?.GetType() ?? this.ValueType;
m_richValueType = UISyntaxHighlight.ParseFullSyntax(ValueType, true);
m_richValueType = UISyntaxHighlight.ParseFullSyntax(valueType, true);
if (OwnerCacheObject is CacheMember cm && !cm.HasEvaluated)
return $"<i><color=grey>Not yet evaluated</color> ({m_richValueType})</i>";
@ -67,7 +69,7 @@ namespace UnityExplorer.Inspectors.Reflection
string label;
if (ValueType == typeof(TextAsset) && Value is TextAsset textAsset)
if (valueType == typeof(TextAsset) && Value is TextAsset textAsset)
{
label = textAsset.text;
@ -76,7 +78,7 @@ namespace UnityExplorer.Inspectors.Reflection
label = $"\"{label}\" {textAsset.name} ({m_richValueType})";
}
else if (ValueType == typeof(EventSystem))
else if (valueType == typeof(EventSystem))
{
label = m_richValueType;
}
@ -84,7 +86,7 @@ namespace UnityExplorer.Inspectors.Reflection
{
var toString = (string)ToStringMethod.Invoke(Value, null);
var fullnametemp = ValueType.ToString();
var fullnametemp = valueType.ToString();
if (fullnametemp.StartsWith("Il2CppSystem"))
fullnametemp = fullnametemp.Substring(6, fullnametemp.Length - 6);
@ -101,7 +103,7 @@ namespace UnityExplorer.Inspectors.Reflection
label = toString;
var unityType = $"({ValueType.FullName})";
var unityType = $"({valueType.FullName})";
if (Value is UnityEngine.Object && label.Contains(unityType))
label = label.Replace(unityType, $"({m_richValueType})");
else

View File

@ -58,22 +58,22 @@ namespace UnityExplorer.Inspectors
#endregion
#region INSTANCE
#region INSTANCE
public override string TabLabel => m_targetTypeShortName;
public bool AutoUpdate { get; set; }
internal readonly Type m_targetType;
internal readonly string m_targetTypeShortName;
// all cached members of the target
internal CacheMember[] m_allMembers;
// filtered members based on current filters
internal CacheMember[] m_membersFiltered;
internal readonly List<CacheMember> m_membersFiltered = new List<CacheMember>();
// actual shortlist of displayed members
internal readonly CacheMember[] m_displayedMembers = new CacheMember[ModConfig.Instance.Default_Page_Limit];
internal bool m_autoUpdate;
// UI members
private GameObject m_content;
@ -84,6 +84,8 @@ namespace UnityExplorer.Inspectors
}
internal Text m_nameFilterText;
internal MemberTypes m_memberFilter;
internal Button m_lastActiveMemButton;
internal PageHandler m_pageHandler;
internal SliderScrollbar m_sliderScroller;
@ -138,14 +140,35 @@ namespace UnityExplorer.Inspectors
RefreshDisplay();
}
private void OnMemberFilterClicked(MemberTypes type, Button button)
{
if (m_lastActiveMemButton)
{
var lastColors = m_lastActiveMemButton.colors;
lastColors.normalColor = new Color(0.2f, 0.2f, 0.2f);
m_lastActiveMemButton.colors = lastColors;
}
m_memberFilter = type;
m_lastActiveMemButton = button;
var colors = m_lastActiveMemButton.colors;
colors.normalColor = new Color(0.2f, 0.6f, 0.2f);
m_lastActiveMemButton.colors = colors;
FilterMembers(null, true);
m_sliderScroller.m_slider.value = 1f;
}
public override void Update()
{
base.Update();
if (AutoUpdate)
if (m_autoUpdate)
{
foreach (var member in m_displayedMembers)
{
if (member == null) break;
member.UpdateValue();
}
}
@ -163,32 +186,42 @@ namespace UnityExplorer.Inspectors
}
}
public void FilterMembers(string nameFilter = null)
public void FilterMembers(string nameFilter = null, bool force = false)
{
var list = new List<CacheMember>();
int lastCount = m_membersFiltered.Count;
m_membersFiltered.Clear();
nameFilter = nameFilter?.ToLower() ?? m_nameFilterText.text.ToLower();
foreach (var mem in m_allMembers)
{
// name filter
if (!string.IsNullOrEmpty(nameFilter) && !mem.NameForFiltering.Contains(nameFilter))
// membertype filter
if (m_memberFilter != MemberTypes.All && mem.MemInfo.MemberType != m_memberFilter)
continue;
list.Add(mem);
if (this is InstanceInspector ii && ii.m_scopeFilter != MemberScopes.All)
{
if (mem.IsStatic && ii.m_scopeFilter != MemberScopes.Static)
continue;
else if (!mem.IsStatic && ii.m_scopeFilter != MemberScopes.Instance)
continue;
}
// name filter
if (!string.IsNullOrEmpty(nameFilter) && !mem.NameForFiltering.Contains(nameFilter))
continue;
m_membersFiltered.Add(mem);
}
if (m_membersFiltered == null || m_membersFiltered.Length != list.Count)
{
m_membersFiltered = list.ToArray();
if (force || lastCount != m_membersFiltered.Count)
RefreshDisplay();
}
}
public void RefreshDisplay()
{
var members = m_membersFiltered;
m_pageHandler.ListCount = members.Length;
m_pageHandler.ListCount = members.Count;
// disable current members
for (int i = 0; i < m_displayedMembers.Length; i++)
@ -200,12 +233,12 @@ namespace UnityExplorer.Inspectors
break;
}
if (members.Length < 1)
if (members.Count < 1)
return;
foreach (var itemIndex in m_pageHandler)
{
if (itemIndex >= members.Length)
if (itemIndex >= members.Count)
break;
CacheMember member = members[itemIndex];
@ -362,7 +395,7 @@ namespace UnityExplorer.Inspectors
// ExplorerCore.Log("Cached " + m_allMembers.Length + " members");
}
#region UI CONSTRUCTION
#region UI CONSTRUCTION
internal void ConstructUI()
{
@ -386,17 +419,7 @@ namespace UnityExplorer.Inspectors
internal void ConstructTopArea()
{
var topGroupObj = UIFactory.CreateVerticalGroup(Content, new Color(0.1f, 0.1f, 0.1f));
var topGroup = topGroupObj.GetComponent<VerticalLayoutGroup>();
topGroup.childForceExpandWidth = true;
topGroup.childForceExpandHeight = true;
topGroup.childControlWidth = true;
topGroup.childControlHeight = true;
topGroup.spacing = 8;
topGroup.padding.left = 4;
topGroup.padding.right = 4;
var nameRowObj = UIFactory.CreateHorizontalGroup(topGroupObj, new Color(1, 1, 1, 0));
var nameRowObj = UIFactory.CreateHorizontalGroup(Content, new Color(1, 1, 1, 0));
var nameRow = nameRowObj.GetComponent<HorizontalLayoutGroup>();
nameRow.childForceExpandWidth = true;
nameRow.childForceExpandHeight = true;
@ -429,20 +452,31 @@ namespace UnityExplorer.Inspectors
if (this is InstanceInspector)
{
(this as InstanceInspector).ConstructInstanceHelpers(topGroupObj);
(this as InstanceInspector).ConstructInstanceHelpers();
}
ConstructFilterArea();
ConstructOptionsArea();
}
internal void ConstructFilterArea()
{
// Filters
var filterAreaObj = UIFactory.CreateVerticalGroup(topGroupObj, new Color(1,1,1,0));
var filterAreaObj = UIFactory.CreateVerticalGroup(Content, new Color(0.1f, 0.1f, 0.1f));
var filterLayout = filterAreaObj.AddComponent<LayoutElement>();
filterLayout.minHeight = 60;
var filterGroup = filterAreaObj.GetComponent<VerticalLayoutGroup>();
filterGroup.childForceExpandWidth = true;
filterGroup.childForceExpandHeight = false;
filterGroup.childForceExpandHeight = true;
filterGroup.childControlWidth = true;
filterGroup.childControlHeight = true;
filterGroup.spacing = 4;
filterGroup.padding.left = 4;
filterGroup.padding.right = 4;
filterGroup.padding.top = 4;
filterGroup.padding.bottom = 4;
// name filter
@ -460,11 +494,12 @@ namespace UnityExplorer.Inspectors
var nameLabelObj = UIFactory.CreateLabel(nameFilterRowObj, TextAnchor.MiddleLeft);
var nameLabelLayout = nameLabelObj.AddComponent<LayoutElement>();
nameLabelLayout.minWidth = 130;
nameLabelLayout.minWidth = 100;
nameLabelLayout.minHeight = 25;
nameLabelLayout.flexibleWidth = 0;
var nameLabelText = nameLabelObj.GetComponent<Text>();
nameLabelText.text = "Name contains:";
nameLabelText.text = "Filter names:";
nameLabelText.color = Color.grey;
var nameInputObj = UIFactory.CreateInputField(nameFilterRowObj, 14, (int)TextAnchor.MiddleLeft, (int)HorizontalWrapMode.Overflow);
var nameInputLayout = nameInputObj.AddComponent<LayoutElement>();
@ -477,7 +512,31 @@ namespace UnityExplorer.Inspectors
// membertype filter
var memberFilterRowObj = UIFactory.CreateHorizontalGroup(filterAreaObj, new Color(1, 1, 1, 0));
var memFilterGroup = memberFilterRowObj.GetComponent<HorizontalLayoutGroup>();
memFilterGroup.childForceExpandHeight = false;
memFilterGroup.childForceExpandWidth = false;
memFilterGroup.childControlWidth = true;
memFilterGroup.childControlHeight = true;
memFilterGroup.spacing = 5;
var memFilterLayout = memberFilterRowObj.AddComponent<LayoutElement>();
memFilterLayout.minHeight = 25;
memFilterLayout.flexibleHeight = 0;
memFilterLayout.flexibleWidth = 5000;
var memLabelObj = UIFactory.CreateLabel(memberFilterRowObj, TextAnchor.MiddleLeft);
var memLabelLayout = memLabelObj.AddComponent<LayoutElement>();
memLabelLayout.minWidth = 100;
memLabelLayout.minHeight = 25;
memLabelLayout.flexibleWidth = 0;
var memLabelText = memLabelObj.GetComponent<Text>();
memLabelText.text = "Filter members:";
memLabelText.color = Color.grey;
AddFilterButton(memberFilterRowObj, MemberTypes.All);
AddFilterButton(memberFilterRowObj, MemberTypes.Method);
AddFilterButton(memberFilterRowObj, MemberTypes.Property, true);
AddFilterButton(memberFilterRowObj, MemberTypes.Field);
// Instance filters
@ -487,6 +546,73 @@ namespace UnityExplorer.Inspectors
}
}
private void AddFilterButton(GameObject parent, MemberTypes type, bool setEnabled = false)
{
var btnObj = UIFactory.CreateButton(parent, new Color(0.2f, 0.2f, 0.2f));
var btnLayout = btnObj.AddComponent<LayoutElement>();
btnLayout.minHeight = 25;
btnLayout.minWidth = 70;
var text = btnObj.GetComponentInChildren<Text>();
text.text = type.ToString();
var btn = btnObj.GetComponent<Button>();
btn.onClick.AddListener(() => { OnMemberFilterClicked(type, btn); });
var colors = btn.colors;
colors.highlightedColor = new Color(0.3f, 0.7f, 0.3f);
if (setEnabled)
{
colors.normalColor = new Color(0.2f, 0.4f, 0.2f);
m_memberFilter = type;
m_lastActiveMemButton = btn;
}
btn.colors = colors;
}
internal void ConstructOptionsArea()
{
var optionsRowObj = UIFactory.CreateHorizontalGroup(Content, new Color(1,1,1,0));
var optionsLayout = optionsRowObj.AddComponent<LayoutElement>();
optionsLayout.minHeight = 25;
var optionsGroup = optionsRowObj.GetComponent<HorizontalLayoutGroup>();
optionsGroup.childForceExpandHeight = true;
optionsGroup.childForceExpandWidth = false;
optionsGroup.childAlignment = TextAnchor.MiddleLeft;
optionsGroup.spacing = 10;
// update button
var updateButtonObj = UIFactory.CreateButton(optionsRowObj, new Color(0.2f, 0.2f, 0.2f));
var updateBtnLayout = updateButtonObj.AddComponent<LayoutElement>();
updateBtnLayout.minWidth = 110;
updateBtnLayout.flexibleWidth = 0;
var updateText = updateButtonObj.GetComponentInChildren<Text>();
updateText.text = "Update Values";
var updateBtn = updateButtonObj.GetComponent<Button>();
updateBtn.onClick.AddListener(() =>
{
bool orig = m_autoUpdate;
m_autoUpdate = true;
Update();
if (!orig) m_autoUpdate = orig;
});
// auto update
var autoUpdateObj = UIFactory.CreateToggle(optionsRowObj, out Toggle autoUpdateToggle, out Text autoUpdateText);
var autoUpdateLayout = autoUpdateObj.AddComponent<LayoutElement>();
autoUpdateLayout.minWidth = 150;
autoUpdateLayout.minHeight = 25;
autoUpdateText.text = "Auto-update?";
autoUpdateToggle.isOn = false;
autoUpdateToggle.onValueChanged.AddListener((bool val) => { m_autoUpdate = val; });
}
internal void ConstructMemberList()
{
var scrollobj = UIFactory.CreateScrollView(Content, out m_scrollContent, out m_sliderScroller, new Color(0.12f, 0.12f, 0.12f));
@ -503,8 +629,8 @@ namespace UnityExplorer.Inspectors
m_pageHandler.OnPageChanged += OnPageTurned;
}
#endregion
#endregion // end UI
#endregion
#endregion // end instance
}
}

View File

@ -6,9 +6,6 @@ namespace UnityExplorer.Inspectors.Reflection
{
public override string TabLabel => $" <color=cyan>[S]</color> {base.TabLabel}";
public StaticInspector(Type type) : base(type)
{
// needed?
}
public StaticInspector(Type type) : base(type) { }
}
}