2020-11-15 21:11:43 +11:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2020-11-16 21:21:04 +11:00
|
|
|
|
using System.Reflection;
|
2020-11-15 21:11:43 +11:00
|
|
|
|
using System.Text;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
using UnityExplorer.Config;
|
|
|
|
|
using UnityExplorer.Helpers;
|
|
|
|
|
using UnityExplorer.UI;
|
|
|
|
|
using UnityExplorer.UI.Shared;
|
|
|
|
|
|
|
|
|
|
namespace UnityExplorer.Inspectors.Reflection
|
|
|
|
|
{
|
|
|
|
|
public class InteractiveEnumerable : InteractiveValue
|
|
|
|
|
{
|
|
|
|
|
public InteractiveEnumerable(object value, Type valueType) : base(value, valueType)
|
|
|
|
|
{
|
|
|
|
|
if (valueType.IsGenericType)
|
|
|
|
|
m_baseEntryType = valueType.GetGenericArguments()[0];
|
|
|
|
|
else
|
|
|
|
|
m_baseEntryType = typeof(object);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override bool WantInspectBtn => false;
|
2020-11-16 00:56:20 +11:00
|
|
|
|
public override bool HasSubContent => true;
|
|
|
|
|
public override bool SubContentWanted
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (m_recacheWanted)
|
|
|
|
|
return true;
|
|
|
|
|
else return m_entries.Count > 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-11-15 21:11:43 +11:00
|
|
|
|
|
|
|
|
|
internal IEnumerable RefIEnumerable;
|
|
|
|
|
internal IList RefIList;
|
2020-12-07 22:22:03 +11:00
|
|
|
|
#if CPP
|
|
|
|
|
internal Il2CppSystem.Collections.ICollection CppICollection;
|
|
|
|
|
#else
|
|
|
|
|
internal ICollection CppICollection = null;
|
|
|
|
|
#endif
|
2020-11-15 21:11:43 +11:00
|
|
|
|
|
|
|
|
|
internal readonly Type m_baseEntryType;
|
|
|
|
|
|
|
|
|
|
internal readonly List<CacheEnumerated> m_entries = new List<CacheEnumerated>();
|
2021-03-11 17:57:58 +11:00
|
|
|
|
internal readonly CacheEnumerated[] m_displayedEntries = new CacheEnumerated[ExplorerConfig.Instance.Default_Page_Limit];
|
2020-11-15 21:11:43 +11:00
|
|
|
|
internal bool m_recacheWanted = true;
|
|
|
|
|
|
|
|
|
|
public override void OnValueUpdated()
|
|
|
|
|
{
|
2020-11-16 21:21:04 +11:00
|
|
|
|
RefIEnumerable = Value as IEnumerable;
|
|
|
|
|
RefIList = Value as IList;
|
2020-11-15 21:11:43 +11:00
|
|
|
|
|
2020-12-07 22:22:03 +11:00
|
|
|
|
#if CPP
|
|
|
|
|
if (Value != null && RefIList == null)
|
|
|
|
|
{
|
|
|
|
|
try { CppICollection = (Value as Il2CppSystem.Object).TryCast<Il2CppSystem.Collections.ICollection>(); }
|
|
|
|
|
catch { }
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2020-11-16 22:44:47 +11:00
|
|
|
|
if (m_subContentParent.activeSelf)
|
2020-11-15 21:11:43 +11:00
|
|
|
|
{
|
2020-11-16 22:44:47 +11:00
|
|
|
|
GetCacheEntries();
|
|
|
|
|
RefreshDisplay();
|
2020-11-15 21:11:43 +11:00
|
|
|
|
}
|
|
|
|
|
else
|
2020-11-16 22:44:47 +11:00
|
|
|
|
m_recacheWanted = true;
|
2020-11-15 21:11:43 +11:00
|
|
|
|
|
2020-11-16 21:21:04 +11:00
|
|
|
|
base.OnValueUpdated();
|
|
|
|
|
}
|
2020-11-15 21:11:43 +11:00
|
|
|
|
|
2020-11-16 21:21:04 +11:00
|
|
|
|
public override void OnException(CacheMember member)
|
|
|
|
|
{
|
|
|
|
|
base.OnException(member);
|
2020-11-15 21:11:43 +11:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnPageTurned()
|
|
|
|
|
{
|
|
|
|
|
RefreshDisplay();
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-16 21:21:04 +11:00
|
|
|
|
public override void RefreshUIForValue()
|
2020-11-15 21:11:43 +11:00
|
|
|
|
{
|
2020-11-16 21:21:04 +11:00
|
|
|
|
GetDefaultLabel();
|
|
|
|
|
|
|
|
|
|
if (Value != null)
|
|
|
|
|
{
|
|
|
|
|
string count = "?";
|
2020-12-07 22:22:03 +11:00
|
|
|
|
if (m_recacheWanted && (RefIList != null || CppICollection != null))
|
|
|
|
|
count = RefIList?.Count.ToString() ?? CppICollection.Count.ToString();
|
2020-11-16 21:21:04 +11:00
|
|
|
|
else if (!m_recacheWanted)
|
|
|
|
|
count = m_entries.Count.ToString();
|
2020-11-15 21:11:43 +11:00
|
|
|
|
|
2020-11-16 21:21:04 +11:00
|
|
|
|
m_baseLabel.text = $"[{count}] {m_richValueType}";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
m_baseLabel.text = DefaultLabel;
|
|
|
|
|
}
|
2020-11-15 21:11:43 +11:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void GetCacheEntries()
|
|
|
|
|
{
|
|
|
|
|
if (m_entries.Any())
|
|
|
|
|
{
|
|
|
|
|
// maybe improve this, probably could be more efficient i guess
|
|
|
|
|
|
|
|
|
|
foreach (var entry in m_entries)
|
|
|
|
|
entry.Destroy();
|
|
|
|
|
|
|
|
|
|
m_entries.Clear();
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-16 21:21:04 +11:00
|
|
|
|
#if CPP
|
2020-11-16 22:44:47 +11:00
|
|
|
|
if (RefIEnumerable == null && Value != null)
|
2020-11-16 21:21:04 +11:00
|
|
|
|
RefIEnumerable = EnumerateWithReflection();
|
|
|
|
|
#endif
|
|
|
|
|
|
2020-11-15 21:11:43 +11:00
|
|
|
|
if (RefIEnumerable != null)
|
|
|
|
|
{
|
|
|
|
|
int index = 0;
|
|
|
|
|
foreach (var entry in RefIEnumerable)
|
|
|
|
|
{
|
|
|
|
|
var cache = new CacheEnumerated(index, this, RefIList, this.m_listContent);
|
|
|
|
|
cache.CreateIValue(entry, m_baseEntryType);
|
|
|
|
|
m_entries.Add(cache);
|
|
|
|
|
|
|
|
|
|
cache.Disable();
|
|
|
|
|
|
|
|
|
|
index++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RefreshDisplay();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void RefreshDisplay()
|
|
|
|
|
{
|
|
|
|
|
var entries = m_entries;
|
|
|
|
|
m_pageHandler.ListCount = entries.Count;
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < m_displayedEntries.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
var entry = m_displayedEntries[i];
|
|
|
|
|
if (entry != null)
|
|
|
|
|
entry.Disable();
|
|
|
|
|
else
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (entries.Count < 1)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
foreach (var itemIndex in m_pageHandler)
|
|
|
|
|
{
|
|
|
|
|
if (itemIndex >= entries.Count)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
CacheEnumerated entry = entries[itemIndex];
|
|
|
|
|
m_displayedEntries[itemIndex - m_pageHandler.StartIndex] = entry;
|
|
|
|
|
entry.Enable();
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-16 00:50:06 +11:00
|
|
|
|
//UpdateSubcontentHeight();
|
2020-11-15 21:11:43 +11:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal override void OnToggleSubcontent(bool active)
|
|
|
|
|
{
|
|
|
|
|
base.OnToggleSubcontent(active);
|
|
|
|
|
|
|
|
|
|
if (active && m_recacheWanted)
|
|
|
|
|
{
|
|
|
|
|
m_recacheWanted = false;
|
|
|
|
|
GetCacheEntries();
|
2020-11-16 21:21:04 +11:00
|
|
|
|
RefreshUIForValue();
|
2020-11-15 21:11:43 +11:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RefreshDisplay();
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-07 22:22:03 +11:00
|
|
|
|
#region CPP Helpers
|
2020-11-16 21:21:04 +11:00
|
|
|
|
|
|
|
|
|
#if CPP
|
|
|
|
|
// some temp fixes for Il2Cpp IEnumerables until interfaces are fixed
|
|
|
|
|
|
2020-12-07 22:22:03 +11:00
|
|
|
|
internal static readonly Dictionary<Type, MethodInfo> s_getEnumeratorMethods = new Dictionary<Type, MethodInfo>();
|
2020-11-16 21:21:04 +11:00
|
|
|
|
|
2020-12-07 22:22:03 +11:00
|
|
|
|
internal static readonly Dictionary<Type, EnumeratorInfo> s_enumeratorInfos = new Dictionary<Type, EnumeratorInfo>();
|
|
|
|
|
|
|
|
|
|
internal class EnumeratorInfo
|
2020-11-16 21:21:04 +11:00
|
|
|
|
{
|
2020-12-07 22:22:03 +11:00
|
|
|
|
internal MethodInfo moveNext;
|
|
|
|
|
internal PropertyInfo current;
|
2020-11-16 21:21:04 +11:00
|
|
|
|
}
|
|
|
|
|
|
2020-12-07 22:22:03 +11:00
|
|
|
|
private IEnumerable EnumerateWithReflection()
|
2020-11-16 21:21:04 +11:00
|
|
|
|
{
|
2020-12-07 22:22:03 +11:00
|
|
|
|
if (Value == null)
|
|
|
|
|
return null;
|
2020-11-16 21:21:04 +11:00
|
|
|
|
|
2020-12-07 22:22:03 +11:00
|
|
|
|
// new test
|
|
|
|
|
var CppEnumerable = (Value as Il2CppSystem.Object)?.TryCast<Il2CppSystem.Collections.IEnumerable>();
|
|
|
|
|
if (CppEnumerable != null)
|
2020-11-16 21:21:04 +11:00
|
|
|
|
{
|
2020-12-07 22:22:03 +11:00
|
|
|
|
var type = Value.GetType();
|
|
|
|
|
if (!s_getEnumeratorMethods.ContainsKey(type))
|
|
|
|
|
s_getEnumeratorMethods.Add(type, type.GetMethod("GetEnumerator"));
|
|
|
|
|
|
|
|
|
|
var enumerator = s_getEnumeratorMethods[type].Invoke(Value, null);
|
|
|
|
|
var enumeratorType = enumerator.GetType();
|
|
|
|
|
|
|
|
|
|
if (!s_enumeratorInfos.ContainsKey(enumeratorType))
|
2020-11-16 21:21:04 +11:00
|
|
|
|
{
|
2020-12-07 22:22:03 +11:00
|
|
|
|
s_enumeratorInfos.Add(enumeratorType, new EnumeratorInfo
|
2020-11-16 21:21:04 +11:00
|
|
|
|
{
|
2020-12-07 22:22:03 +11:00
|
|
|
|
current = enumeratorType.GetProperty("Current"),
|
|
|
|
|
moveNext = enumeratorType.GetMethod("MoveNext"),
|
|
|
|
|
});
|
2020-11-16 21:21:04 +11:00
|
|
|
|
}
|
2020-12-07 22:22:03 +11:00
|
|
|
|
var info = s_enumeratorInfos[enumeratorType];
|
|
|
|
|
|
|
|
|
|
// iterate
|
|
|
|
|
var list = new List<object>();
|
|
|
|
|
while ((bool)info.moveNext.Invoke(enumerator, null))
|
|
|
|
|
list.Add(info.current.GetValue(enumerator));
|
2020-11-16 21:21:04 +11:00
|
|
|
|
|
|
|
|
|
return list;
|
|
|
|
|
}
|
2020-12-07 22:22:03 +11:00
|
|
|
|
|
|
|
|
|
return null;
|
2020-11-16 21:21:04 +11:00
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2020-12-07 22:22:03 +11:00
|
|
|
|
#endregion
|
2020-11-16 21:21:04 +11:00
|
|
|
|
|
2020-12-07 22:22:03 +11:00
|
|
|
|
#region UI CONSTRUCTION
|
2020-11-15 21:11:43 +11:00
|
|
|
|
|
|
|
|
|
internal GameObject m_listContent;
|
|
|
|
|
internal LayoutElement m_listLayout;
|
|
|
|
|
|
|
|
|
|
internal PageHandler m_pageHandler;
|
|
|
|
|
|
|
|
|
|
public override void ConstructUI(GameObject parent, GameObject subGroup)
|
|
|
|
|
{
|
|
|
|
|
base.ConstructUI(parent, subGroup);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void ConstructSubcontent()
|
|
|
|
|
{
|
|
|
|
|
base.ConstructSubcontent();
|
|
|
|
|
|
|
|
|
|
m_pageHandler = new PageHandler(null);
|
|
|
|
|
m_pageHandler.ConstructUI(m_subContentParent);
|
|
|
|
|
m_pageHandler.OnPageChanged += OnPageTurned;
|
|
|
|
|
|
|
|
|
|
var scrollObj = UIFactory.CreateVerticalGroup(this.m_subContentParent, new Color(0.08f, 0.08f, 0.08f));
|
|
|
|
|
m_listContent = scrollObj;
|
|
|
|
|
|
|
|
|
|
var scrollRect = scrollObj.GetComponent<RectTransform>();
|
|
|
|
|
scrollRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 0);
|
|
|
|
|
|
2020-11-16 21:21:04 +11:00
|
|
|
|
m_listLayout = Owner.m_mainContent.GetComponent<LayoutElement>();
|
2020-11-15 21:11:43 +11:00
|
|
|
|
m_listLayout.minHeight = 25;
|
|
|
|
|
m_listLayout.flexibleHeight = 0;
|
2020-11-16 21:21:04 +11:00
|
|
|
|
Owner.m_mainRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 25);
|
2020-11-15 21:11:43 +11:00
|
|
|
|
|
|
|
|
|
var scrollGroup = m_listContent.GetComponent<VerticalLayoutGroup>();
|
|
|
|
|
scrollGroup.childForceExpandHeight = true;
|
|
|
|
|
scrollGroup.childControlHeight = true;
|
|
|
|
|
scrollGroup.spacing = 2;
|
|
|
|
|
scrollGroup.padding.top = 5;
|
|
|
|
|
scrollGroup.padding.left = 5;
|
|
|
|
|
scrollGroup.padding.right = 5;
|
|
|
|
|
scrollGroup.padding.bottom = 5;
|
|
|
|
|
|
|
|
|
|
var contentFitter = scrollObj.AddComponent<ContentSizeFitter>();
|
|
|
|
|
contentFitter.horizontalFit = ContentSizeFitter.FitMode.Unconstrained;
|
|
|
|
|
contentFitter.verticalFit = ContentSizeFitter.FitMode.PreferredSize;
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-07 22:22:03 +11:00
|
|
|
|
#endregion
|
2020-11-15 21:11:43 +11:00
|
|
|
|
}
|
|
|
|
|
}
|