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;
|
2021-04-04 03:41:36 +10:00
|
|
|
|
using UnityExplorer.Core;
|
2021-03-18 17:17:29 +11:00
|
|
|
|
using UnityExplorer.Core.Config;
|
|
|
|
|
using UnityExplorer.Core.Unity;
|
2020-11-15 21:11:43 +11:00
|
|
|
|
using UnityExplorer.UI;
|
2021-03-30 19:50:04 +11:00
|
|
|
|
using UnityExplorer.UI.CacheObject;
|
|
|
|
|
using UnityExplorer.UI.Utility;
|
2020-11-15 21:11:43 +11:00
|
|
|
|
|
2021-03-30 19:50:04 +11:00
|
|
|
|
namespace UnityExplorer.UI.InteractiveValues
|
2020-11-15 21:11:43 +11:00
|
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
internal readonly Type m_baseEntryType;
|
|
|
|
|
|
|
|
|
|
internal readonly List<CacheEnumerated> m_entries = new List<CacheEnumerated>();
|
2021-03-30 19:50:04 +11:00
|
|
|
|
internal readonly CacheEnumerated[] m_displayedEntries = new CacheEnumerated[ConfigManager.Default_Page_Limit.Value];
|
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-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 = "?";
|
2021-04-07 17:20:09 +10:00
|
|
|
|
if (m_recacheWanted && RefIList != null)
|
|
|
|
|
count = RefIList.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 22:44:47 +11:00
|
|
|
|
if (RefIEnumerable == null && Value != null)
|
2021-04-07 17:20:09 +10:00
|
|
|
|
RefIEnumerable = RuntimeProvider.Instance.Reflection.EnumerateEnumerable(Value);
|
2020-11-16 21:21:04 +11:00
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
2021-03-30 19:50:04 +11:00
|
|
|
|
m_listContent = UIFactory.CreateVerticalGroup(this.m_subContentParent, "EnumerableContent", true, true, true, true, 2, new Vector4(5,5,5,5),
|
|
|
|
|
new Color(0.08f, 0.08f, 0.08f));
|
2020-11-15 21:11:43 +11:00
|
|
|
|
|
2021-03-30 19:50:04 +11:00
|
|
|
|
var scrollRect = m_listContent.GetComponent<RectTransform>();
|
2020-11-15 21:11:43 +11:00
|
|
|
|
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
|
|
|
|
|
2021-03-30 19:50:04 +11:00
|
|
|
|
var contentFitter = m_listContent.AddComponent<ContentSizeFitter>();
|
2020-11-15 21:11:43 +11:00
|
|
|
|
contentFitter.horizontalFit = ContentSizeFitter.FitMode.Unconstrained;
|
|
|
|
|
contentFitter.verticalFit = ContentSizeFitter.FitMode.PreferredSize;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|