2021-05-01 20:55:27 +10:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
using UnityExplorer.UI.Inspectors.CacheObject;
|
|
|
|
|
using UnityExplorer.UI.Inspectors.CacheObject.Views;
|
|
|
|
|
using UnityExplorer.UI.Utility;
|
|
|
|
|
using UnityExplorer.UI.Widgets;
|
|
|
|
|
|
|
|
|
|
namespace UnityExplorer.UI.Inspectors.IValues
|
|
|
|
|
{
|
2021-05-03 01:29:02 +10:00
|
|
|
|
public class InteractiveList : InteractiveValue, IPoolDataSource<CacheListEntryCell>, ICacheObjectController
|
2021-05-01 20:55:27 +10:00
|
|
|
|
{
|
2021-05-03 01:29:02 +10:00
|
|
|
|
CacheObjectBase ICacheObjectController.ParentCacheObject => this.CurrentOwner;
|
|
|
|
|
object ICacheObjectController.Target => this.CurrentOwner.Value;
|
|
|
|
|
public Type TargetType { get; private set; }
|
|
|
|
|
|
|
|
|
|
public override bool CanWrite => RefIList != null && !RefIList.IsReadOnly;
|
2021-05-01 20:55:27 +10:00
|
|
|
|
|
2021-05-03 01:29:02 +10:00
|
|
|
|
public Type EntryType;
|
2021-05-01 20:55:27 +10:00
|
|
|
|
public IEnumerable RefIEnumerable;
|
|
|
|
|
public IList RefIList;
|
|
|
|
|
|
|
|
|
|
public int ItemCount => values.Count;
|
|
|
|
|
private readonly List<object> values = new List<object>();
|
|
|
|
|
private readonly List<CacheListEntry> cachedEntries = new List<CacheListEntry>();
|
|
|
|
|
|
|
|
|
|
public ScrollPool<CacheListEntryCell> ListScrollPool { get; private set; }
|
|
|
|
|
|
|
|
|
|
public Text TopLabel;
|
|
|
|
|
|
2021-05-03 01:29:02 +10:00
|
|
|
|
public override void OnBorrowed(CacheObjectBase owner)
|
|
|
|
|
{
|
|
|
|
|
base.OnBorrowed(owner);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void SetLayout()
|
2021-05-01 20:55:27 +10:00
|
|
|
|
{
|
2021-05-03 01:29:02 +10:00
|
|
|
|
var minHeight = 5f;
|
|
|
|
|
|
|
|
|
|
foreach (var cell in ListScrollPool.CellPool)
|
|
|
|
|
{
|
|
|
|
|
if (cell.Enabled)
|
|
|
|
|
minHeight += cell.Rect.rect.height;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.scrollLayout.minHeight = Math.Min(400f, minHeight);
|
2021-05-01 20:55:27 +10:00
|
|
|
|
}
|
|
|
|
|
|
2021-05-03 01:29:02 +10:00
|
|
|
|
|
2021-05-01 20:55:27 +10:00
|
|
|
|
public override void ReleaseFromOwner()
|
|
|
|
|
{
|
|
|
|
|
base.ReleaseFromOwner();
|
|
|
|
|
|
|
|
|
|
ClearAndRelease();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ClearAndRelease()
|
|
|
|
|
{
|
|
|
|
|
values.Clear();
|
|
|
|
|
|
|
|
|
|
foreach (var entry in cachedEntries)
|
|
|
|
|
entry.ReleasePooledObjects();
|
|
|
|
|
|
|
|
|
|
cachedEntries.Clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void SetValue(object value)
|
|
|
|
|
{
|
|
|
|
|
if (value == null)
|
|
|
|
|
{
|
2021-05-03 01:29:02 +10:00
|
|
|
|
// should never be null
|
2021-05-01 20:55:27 +10:00
|
|
|
|
if (values.Any())
|
|
|
|
|
ClearAndRelease();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var type = value.GetActualType();
|
|
|
|
|
if (type.IsGenericType)
|
2021-05-03 01:29:02 +10:00
|
|
|
|
EntryType = type.GetGenericArguments()[0];
|
2021-05-01 20:55:27 +10:00
|
|
|
|
else
|
2021-05-03 01:29:02 +10:00
|
|
|
|
EntryType = typeof(object);
|
2021-05-01 20:55:27 +10:00
|
|
|
|
|
|
|
|
|
CacheEntries(value);
|
|
|
|
|
|
2021-05-03 01:29:02 +10:00
|
|
|
|
TopLabel.text = $"[{cachedEntries.Count}] {SignatureHighlighter.ParseFullType(type, true)}";
|
|
|
|
|
}
|
2021-05-01 20:55:27 +10:00
|
|
|
|
|
2021-05-03 01:29:02 +10:00
|
|
|
|
//this.ScrollPoolLayout.minHeight = Math.Min(400f, 35f * values.Count);
|
2021-05-01 20:55:27 +10:00
|
|
|
|
this.ListScrollPool.Refresh(true, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CacheEntries(object value)
|
|
|
|
|
{
|
|
|
|
|
RefIEnumerable = value as IEnumerable;
|
|
|
|
|
RefIList = value as IList;
|
|
|
|
|
|
|
|
|
|
if (RefIEnumerable == null)
|
|
|
|
|
{
|
2021-05-03 01:29:02 +10:00
|
|
|
|
// todo il2cpp
|
|
|
|
|
return;
|
2021-05-01 20:55:27 +10:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
values.Clear();
|
|
|
|
|
int idx = 0;
|
|
|
|
|
foreach (var entry in RefIEnumerable)
|
|
|
|
|
{
|
|
|
|
|
values.Add(entry);
|
|
|
|
|
|
|
|
|
|
// If list count increased, create new cache entries
|
|
|
|
|
CacheListEntry cache;
|
|
|
|
|
if (idx >= cachedEntries.Count)
|
|
|
|
|
{
|
|
|
|
|
cache = new CacheListEntry();
|
|
|
|
|
cache.SetListOwner(this, idx);
|
|
|
|
|
cachedEntries.Add(cache);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
cache = cachedEntries[idx];
|
|
|
|
|
|
2021-05-03 01:29:02 +10:00
|
|
|
|
cache.SetFallbackType(this.EntryType);
|
2021-05-01 20:55:27 +10:00
|
|
|
|
cache.SetValueFromSource(entry);
|
|
|
|
|
idx++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Remove excess cached entries if list count decreased
|
|
|
|
|
if (cachedEntries.Count > values.Count)
|
|
|
|
|
{
|
|
|
|
|
for (int i = cachedEntries.Count - 1; i >= values.Count; i--)
|
|
|
|
|
{
|
|
|
|
|
var cache = cachedEntries[i];
|
|
|
|
|
if (cache.CellView != null)
|
|
|
|
|
{
|
|
|
|
|
cache.CellView.Occupant = null;
|
|
|
|
|
cache.CellView = null;
|
|
|
|
|
}
|
|
|
|
|
cache.ReleasePooledObjects();
|
|
|
|
|
cachedEntries.RemoveAt(i);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// List entry scroll pool
|
|
|
|
|
|
|
|
|
|
public void OnCellBorrowed(CacheListEntryCell cell)
|
|
|
|
|
{
|
2021-05-03 01:29:02 +10:00
|
|
|
|
|
2021-05-01 20:55:27 +10:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetCell(CacheListEntryCell cell, int index)
|
|
|
|
|
{
|
|
|
|
|
if (index < 0 || index >= cachedEntries.Count)
|
|
|
|
|
{
|
|
|
|
|
if (cell.Occupant != null)
|
|
|
|
|
{
|
|
|
|
|
cell.Occupant.CellView = null;
|
|
|
|
|
cell.Occupant = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cell.Disable();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var entry = cachedEntries[index];
|
|
|
|
|
|
|
|
|
|
if (entry != cell.Occupant)
|
|
|
|
|
{
|
|
|
|
|
if (cell.Occupant != null)
|
|
|
|
|
{
|
|
|
|
|
cell.Occupant.HideIValue();
|
|
|
|
|
cell.Occupant.CellView = null;
|
|
|
|
|
cell.Occupant = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cell.Occupant = entry;
|
|
|
|
|
entry.CellView = cell;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
entry.SetCell(cell);
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-03 01:29:02 +10:00
|
|
|
|
private LayoutElement scrollLayout;
|
|
|
|
|
|
2021-05-01 20:55:27 +10:00
|
|
|
|
public override GameObject CreateContent(GameObject parent)
|
|
|
|
|
{
|
2021-05-03 01:29:02 +10:00
|
|
|
|
UIRoot = UIFactory.CreateVerticalGroup(parent, "InteractiveList", true, true, true, true, 6, new Vector4(10, 3, 15, 4),
|
2021-05-01 20:55:27 +10:00
|
|
|
|
new Color(0.05f, 0.05f, 0.05f));
|
|
|
|
|
UIFactory.SetLayoutElement(UIRoot, flexibleWidth: 9999, minHeight: 25, flexibleHeight: 600);
|
2021-05-03 01:29:02 +10:00
|
|
|
|
UIRoot.AddComponent<ContentSizeFitter>().verticalFit = ContentSizeFitter.FitMode.PreferredSize;
|
2021-05-01 20:55:27 +10:00
|
|
|
|
|
|
|
|
|
// Entries label
|
|
|
|
|
|
2021-05-03 01:29:02 +10:00
|
|
|
|
TopLabel = UIFactory.CreateLabel(UIRoot, "EntryLabel", "not set", TextAnchor.MiddleLeft, fontSize: 16);
|
|
|
|
|
TopLabel.horizontalOverflow = HorizontalWrapMode.Overflow;
|
2021-05-01 20:55:27 +10:00
|
|
|
|
|
|
|
|
|
// entry scroll pool
|
|
|
|
|
|
|
|
|
|
ListScrollPool = UIFactory.CreateScrollPool<CacheListEntryCell>(UIRoot, "EntryList", out GameObject scrollObj,
|
|
|
|
|
out GameObject _, new Color(0.09f, 0.09f, 0.09f));
|
2021-05-03 01:29:02 +10:00
|
|
|
|
UIFactory.SetLayoutElement(scrollObj, minHeight: 400, flexibleHeight: 0);
|
|
|
|
|
ListScrollPool.Initialize(this, SetLayout);
|
|
|
|
|
scrollLayout = scrollObj.GetComponent<LayoutElement>();
|
2021-05-01 20:55:27 +10:00
|
|
|
|
|
|
|
|
|
return UIRoot;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-05-03 01:29:02 +10:00
|
|
|
|
}
|