* Added page view to GameObject Children/Component lists
* Made a generic Page Handler helper class, replaced all page view implementations with the helper (no real change for users but should make things easier to maintain in the future, and they were basically all copy+pastes).
This commit is contained in:
sinaioutlander 2020-09-03 19:48:50 +10:00
parent e7208d0c9d
commit 42156e1160
8 changed files with 284 additions and 184 deletions

View File

@ -11,8 +11,7 @@ namespace Explorer
public class CacheList : CacheObjectBase public class CacheList : CacheObjectBase
{ {
public bool IsExpanded { get; set; } public bool IsExpanded { get; set; }
public int ArrayOffset { get; set; } public PageHelper Pages = new PageHelper();
public int ArrayLimit { get; set; } = 20;
public float WhiteSpace = 215f; public float WhiteSpace = 215f;
public float ButtonWidthOffset = 290f; public float ButtonWidthOffset = 290f;
@ -230,18 +229,6 @@ namespace Explorer
{ {
list.Add(null); list.Add(null);
} }
//var type = ReflectionHelpers.GetActualType(obj);
//if (obj is Il2CppSystem.Object iObj)
//{
// obj = iObj.Il2CppCast(type);
//}
//var cached = GetCacheObject(obj, null, null, type);
//cached.UpdateValue();
//list.Add(cached);
} }
m_cachedEntries = list.ToArray(); m_cachedEntries = list.ToArray();
@ -287,50 +274,50 @@ namespace Explorer
if (IsExpanded) if (IsExpanded)
{ {
float whitespace = WhiteSpace; float whitespace = WhiteSpace;
if (whitespace > 0) if (whitespace > 0)
{ {
ClampLabelWidth(window, ref whitespace); ClampLabelWidth(window, ref whitespace);
} }
if (count > ArrayLimit) Pages.Count = count;
if (count > Pages.PageLimit)
{ {
GUILayout.EndHorizontal(); GUILayout.EndHorizontal();
GUILayout.BeginHorizontal(null); GUILayout.BeginHorizontal(null);
GUILayout.Space(whitespace); GUILayout.Space(whitespace);
int maxOffset = (int)Mathf.Ceil((float)(count / (decimal)ArrayLimit)) - 1; //int maxOffset = (int)Mathf.Ceil((float)(count / (decimal)ArrayLimit)) - 1;
GUILayout.Label($"Page {ArrayOffset + 1}/{maxOffset + 1}", new GUILayoutOption[] { GUILayout.Width(80) }); Pages.CalculateMaxOffset();
//GUILayout.Label($"Page {PH.ArrayOffset + 1}/{maxOffset + 1}", new GUILayoutOption[] { GUILayout.Width(80) });
Pages.CurrentPageLabel();
// prev/next page buttons // prev/next page buttons
if (GUILayout.Button("< Prev", new GUILayoutOption[] { GUILayout.Width(60) })) if (GUILayout.Button("< Prev", new GUILayoutOption[] { GUILayout.Width(60) }))
{ {
if (ArrayOffset > 0) ArrayOffset--; Pages.TurnPage(Turn.Left);
} }
if (GUILayout.Button("Next >", new GUILayoutOption[] { GUILayout.Width(60) })) if (GUILayout.Button("Next >", new GUILayoutOption[] { GUILayout.Width(60) }))
{ {
if (ArrayOffset < maxOffset) ArrayOffset++; Pages.TurnPage(Turn.Right);
}
GUILayout.Label("Limit: ", new GUILayoutOption[] { GUILayout.Width(50) });
var limit = this.ArrayLimit.ToString();
limit = GUILayout.TextField(limit, new GUILayoutOption[] { GUILayout.Width(50) });
if (limit != ArrayLimit.ToString() && int.TryParse(limit, out int i))
{
ArrayLimit = i;
} }
Pages.DrawLimitInputArea();
GUILayout.Space(5); GUILayout.Space(5);
} }
int offset = ArrayOffset * ArrayLimit; //int offset = ArrayOffset * ArrayLimit;
//if (offset >= count)
//{
// offset = 0;
// ArrayOffset = 0;
//}
int offset = Pages.CalculateOffsetIndex();
if (offset >= count) for (int i = offset; i < offset + Pages.PageLimit && i < count; i++)
{
offset = 0;
ArrayOffset = 0;
}
for (int i = offset; i < offset + ArrayLimit && i < count; i++)
{ {
var entry = m_cachedEntries[i]; var entry = m_cachedEntries[i];

View File

@ -12,7 +12,7 @@ namespace Explorer
public class CppExplorer : MelonMod public class CppExplorer : MelonMod
{ {
public const string GUID = "com.sinai.cppexplorer"; public const string GUID = "com.sinai.cppexplorer";
public const string VERSION = "1.5.1"; public const string VERSION = "1.5.2";
public const string AUTHOR = "Sinai"; public const string AUTHOR = "Sinai";
public const string NAME = "CppExplorer" public const string NAME = "CppExplorer"

View File

@ -60,9 +60,7 @@
<HintPath>..\..\..\..\..\Steam\steamapps\common\Hellpoint\MelonLoader\Managed\UnhollowerBaseLib.dll</HintPath> <HintPath>..\..\..\..\..\Steam\steamapps\common\Hellpoint\MelonLoader\Managed\UnhollowerBaseLib.dll</HintPath>
<Private>False</Private> <Private>False</Private>
</Reference> </Reference>
<!-- Unity 2019 build (InputLegacyModule.dll) --> <!-- Unity 2019 build (InputLegacyModule.dll) -->
<Reference Include="UnityEngine" Condition="'$(Configuration)'=='Debug'"> <Reference Include="UnityEngine" Condition="'$(Configuration)'=='Debug'">
<HintPath>..\..\..\Steam\steamapps\common\Hellpoint\MelonLoader\Managed\UnityEngine.dll</HintPath> <HintPath>..\..\..\Steam\steamapps\common\Hellpoint\MelonLoader\Managed\UnityEngine.dll</HintPath>
<Private>False</Private> <Private>False</Private>
@ -91,9 +89,7 @@
<HintPath>..\..\..\Steam\steamapps\common\Hellpoint\MelonLoader\Managed\UnityEngine.UI.dll</HintPath> <HintPath>..\..\..\Steam\steamapps\common\Hellpoint\MelonLoader\Managed\UnityEngine.UI.dll</HintPath>
<Private>False</Private> <Private>False</Private>
</Reference> </Reference>
<!-- Unity 2018 build (InputModule.dll) --> <!-- Unity 2018 build (InputModule.dll) -->
<Reference Include="UnityEngine" Condition="'$(Configuration)'=='Release_Unity2018'"> <Reference Include="UnityEngine" Condition="'$(Configuration)'=='Release_Unity2018'">
<HintPath>..\..\..\Steam\steamapps\common\VRChat\MelonLoader\Managed\UnityEngine.dll</HintPath> <HintPath>..\..\..\Steam\steamapps\common\VRChat\MelonLoader\Managed\UnityEngine.dll</HintPath>
<Private>False</Private> <Private>False</Private>
@ -122,7 +118,6 @@
<HintPath>..\..\..\Steam\steamapps\common\VRChat\MelonLoader\Managed\UnityEngine.UI.dll</HintPath> <HintPath>..\..\..\Steam\steamapps\common\VRChat\MelonLoader\Managed\UnityEngine.UI.dll</HintPath>
<Private>False</Private> <Private>False</Private>
</Reference> </Reference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="CachedObjects\CacheDictionary.cs" /> <Compile Include="CachedObjects\CacheDictionary.cs" />
@ -135,6 +130,7 @@
<Compile Include="CppExplorer.cs" /> <Compile Include="CppExplorer.cs" />
<Compile Include="Extensions\ReflectionExtensions.cs" /> <Compile Include="Extensions\ReflectionExtensions.cs" />
<Compile Include="Extensions\UnityExtensions.cs" /> <Compile Include="Extensions\UnityExtensions.cs" />
<Compile Include="Helpers\PageHelper.cs" />
<Compile Include="Helpers\ReflectionHelpers.cs" /> <Compile Include="Helpers\ReflectionHelpers.cs" />
<Compile Include="Helpers\UIHelpers.cs" /> <Compile Include="Helpers\UIHelpers.cs" />
<Compile Include="Helpers\UnityHelpers.cs" /> <Compile Include="Helpers\UnityHelpers.cs" />

88
src/Helpers/PageHelper.cs Normal file
View File

@ -0,0 +1,88 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
namespace Explorer
{
public enum Turn
{
Left,
Right
}
public class PageHelper
{
public int PageOffset { get; set; }
public int PageLimit { get; set; } = 20;
public int Count { get; set; }
public int MaxOffset { get; set; } = -1;
public int CalculateMaxOffset()
{
return MaxOffset = (int)Mathf.Ceil((float)(Count / (decimal)PageLimit)) - 1;
}
public void CurrentPageLabel()
{
var orig = GUI.skin.label.alignment;
GUI.skin.label.alignment = TextAnchor.MiddleCenter;
GUILayout.Label($"Page {PageOffset + 1}/{MaxOffset + 1}", new GUILayoutOption[] { GUILayout.Width(80) });
GUI.skin.label.alignment = orig;
}
public void TurnPage(Turn direction)
{
var _ = Vector2.zero;
TurnPage(direction, ref _);
}
public void TurnPage(Turn direction, ref Vector2 scroll)
{
if (direction == Turn.Left)
{
if (PageOffset > 0)
{
PageOffset--;
scroll = Vector2.zero;
}
}
else
{
if (PageOffset < MaxOffset)
{
PageOffset++;
scroll = Vector2.zero;
}
}
}
public int CalculateOffsetIndex()
{
int offset = PageOffset * PageLimit;
if (offset >= Count)
{
offset = 0;
PageOffset = 0;
}
return offset;
}
public void DrawLimitInputArea()
{
GUILayout.Label("Limit: ", new GUILayoutOption[] { GUILayout.Width(50) });
var limit = this.PageLimit.ToString();
limit = GUILayout.TextField(limit, new GUILayoutOption[] { GUILayout.Width(50) });
if (limit != PageLimit.ToString() && int.TryParse(limit, out int i))
{
PageLimit = i;
}
}
}
}

View File

@ -14,9 +14,7 @@ namespace Explorer
public override string Name { get => "Scene Explorer"; set => base.Name = value; } public override string Name { get => "Scene Explorer"; set => base.Name = value; }
private int m_pageOffset = 0; public PageHelper Pages = new PageHelper();
private int m_limit = 20;
private int m_currentTotalCount = 0;
private float m_timeOfLastUpdate = -1f; private float m_timeOfLastUpdate = -1f;
@ -46,14 +44,14 @@ namespace Explorer
SetTransformTarget(null); SetTransformTarget(null);
} }
public void CheckOffset(ref int offset, int childCount) //public void CheckOffset(ref int offset, int childCount)
{ //{
if (offset >= childCount) // if (offset >= childCount)
{ // {
offset = 0; // offset = 0;
m_pageOffset = 0; // m_pageOffset = 0;
} // }
} //}
public override void Update() public override void Update()
{ {
@ -63,7 +61,6 @@ namespace Explorer
m_timeOfLastUpdate = Time.time; m_timeOfLastUpdate = Time.time;
m_objectList = new List<GameObjectCache>(); m_objectList = new List<GameObjectCache>();
int offset = m_pageOffset * m_limit;
var allTransforms = new List<Transform>(); var allTransforms = new List<Transform>();
@ -86,15 +83,14 @@ namespace Explorer
} }
} }
m_currentTotalCount = allTransforms.Count; Pages.Count = allTransforms.Count;
// make sure offset doesn't exceed count int offset = Pages.CalculateOffsetIndex();
CheckOffset(ref offset, m_currentTotalCount);
// sort by childcount // sort by childcount
allTransforms.Sort((a, b) => b.childCount.CompareTo(a.childCount)); allTransforms.Sort((a, b) => b.childCount.CompareTo(a.childCount));
for (int i = offset; i < offset + m_limit && i < m_currentTotalCount; i++) for (int i = offset; i < offset + Pages.PageLimit && i < Pages.Count; i++)
{ {
var child = allTransforms[i]; var child = allTransforms[i];
m_objectList.Add(new GameObjectCache(child.gameObject)); m_objectList.Add(new GameObjectCache(child.gameObject));
@ -128,7 +124,7 @@ namespace Explorer
{ {
m_searchResults = SearchSceneObjects(m_searchInput); m_searchResults = SearchSceneObjects(m_searchInput);
m_searching = true; m_searching = true;
m_currentTotalCount = m_searchResults.Count; Pages.Count = m_searchResults.Count;
} }
public void CancelSearch() public void CancelSearch()
@ -242,33 +238,21 @@ namespace Explorer
{ {
GUILayout.BeginHorizontal(null); GUILayout.BeginHorizontal(null);
GUILayout.Label("Limit per page: ", new GUILayoutOption[] { GUILayout.Width(100) }); Pages.DrawLimitInputArea();
var limit = m_limit.ToString();
limit = GUILayout.TextField(limit, new GUILayoutOption[] { GUILayout.Width(30) });
if (int.TryParse(limit, out int lim))
{
m_limit = lim;
}
// prev/next page buttons if (Pages.Count > Pages.PageLimit)
if (m_currentTotalCount > m_limit)
{ {
int count = m_currentTotalCount; if (GUILayout.Button("< Prev", new GUILayoutOption[] { GUILayout.Width(80) }))
int maxOffset = (int)Mathf.Ceil((float)(count / (decimal)m_limit)) - 1;
if (GUILayout.Button("< Prev", null))
{ {
if (m_pageOffset > 0) m_pageOffset--; Pages.TurnPage(Turn.Left, ref this.scroll);
m_timeOfLastUpdate = -1f;
Update(); Update();
} }
GUI.skin.label.alignment = TextAnchor.MiddleCenter; Pages.CurrentPageLabel();
GUILayout.Label($"Page {m_pageOffset + 1}/{maxOffset + 1}", new GUILayoutOption[] { GUILayout.Width(80) });
if (GUILayout.Button("Next >", null)) if (GUILayout.Button("Next >", new GUILayoutOption[] { GUILayout.Width(80) }))
{ {
if (m_pageOffset < maxOffset) m_pageOffset++; Pages.TurnPage(Turn.Right, ref this.scroll);
m_timeOfLastUpdate = -1f;
Update(); Update();
} }
} }
@ -342,15 +326,9 @@ namespace Explorer
if (m_searchResults.Count > 0) if (m_searchResults.Count > 0)
{ {
int offset = m_pageOffset * m_limit; int offset = Pages.CalculateOffsetIndex();
if (offset >= m_searchResults.Count) for (int i = offset; i < offset + Pages.PageLimit && i < m_searchResults.Count; i++)
{
offset = 0;
m_pageOffset = 0;
}
for (int i = offset; i < offset + m_limit && i < m_searchResults.Count; i++)
{ {
var obj = m_searchResults[i]; var obj = m_searchResults[i];

View File

@ -5,11 +5,7 @@ using System.Linq;
using System.Text; using System.Text;
using UnityEngine; using UnityEngine;
using System.Reflection; using System.Reflection;
using UnityEngine.SceneManagement;
using Object = UnityEngine.Object;
using UnhollowerRuntimeLib;
using MelonLoader; using MelonLoader;
using UnhollowerBaseLib;
namespace Explorer namespace Explorer
{ {
@ -21,11 +17,11 @@ namespace Explorer
private string m_searchInput = ""; private string m_searchInput = "";
private string m_typeInput = ""; private string m_typeInput = "";
private int m_limit = 20;
private int m_pageOffset = 0;
//private List<object> m_searchResults = new List<object>();
private Vector2 resultsScroll = Vector2.zero; private Vector2 resultsScroll = Vector2.zero;
public PageHelper Pages = new PageHelper();
private List<CacheObjectBase> m_searchResults = new List<CacheObjectBase>(); private List<CacheObjectBase> m_searchResults = new List<CacheObjectBase>();
public SceneFilter SceneMode = SceneFilter.Any; public SceneFilter SceneMode = SceneFilter.Any;
@ -55,7 +51,7 @@ namespace Explorer
public void OnSceneChange() public void OnSceneChange()
{ {
m_searchResults.Clear(); m_searchResults.Clear();
m_pageOffset = 0; Pages.PageOffset = 0;
} }
public override void Update() public override void Update()
@ -78,6 +74,9 @@ namespace Explorer
var cache = CacheObjectBase.GetCacheObject(toCache); var cache = CacheObjectBase.GetCacheObject(toCache);
m_searchResults.Add(cache); m_searchResults.Add(cache);
} }
Pages.Count = m_searchResults.Count;
Pages.PageOffset = 0;
} }
public override void DrawWindow() public override void DrawWindow()
@ -91,7 +90,6 @@ namespace Explorer
{ {
//m_searchResults = GetInstanceClassScanner().ToList(); //m_searchResults = GetInstanceClassScanner().ToList();
CacheResults(GetInstanceClassScanner()); CacheResults(GetInstanceClassScanner());
m_pageOffset = 0;
} }
GUILayout.EndHorizontal(); GUILayout.EndHorizontal();
@ -106,25 +104,33 @@ namespace Explorer
GUI.skin.label.alignment = TextAnchor.UpperLeft; GUI.skin.label.alignment = TextAnchor.UpperLeft;
int count = m_searchResults.Count; int count = m_searchResults.Count;
Pages.CalculateMaxOffset();
if (count > this.m_limit) GUILayout.BeginHorizontal(null);
Pages.DrawLimitInputArea();
if (count > Pages.PageLimit)
{ {
// prev/next page buttons // prev/next page buttons
GUILayout.BeginHorizontal(null);
int maxOffset = (int)Mathf.Ceil((float)(count / (decimal)m_limit)) - 1; if (Pages.Count > Pages.PageLimit)
if (GUILayout.Button("< Prev", null))
{ {
if (m_pageOffset > 0) m_pageOffset--; if (GUILayout.Button("< Prev", new GUILayoutOption[] { GUILayout.Width(80) }))
{
Pages.TurnPage(Turn.Left, ref this.resultsScroll);
} }
GUILayout.Label($"Page {m_pageOffset + 1}/{maxOffset + 1}", new GUILayoutOption[] { GUILayout.Width(80) }); Pages.CurrentPageLabel();
if (GUILayout.Button("Next >", null)) if (GUILayout.Button("Next >", new GUILayoutOption[] { GUILayout.Width(80) }))
{ {
if (m_pageOffset < maxOffset) m_pageOffset++; Pages.TurnPage(Turn.Right, ref this.resultsScroll);
} }
}
}
GUILayout.EndHorizontal(); GUILayout.EndHorizontal();
}
resultsScroll = GUILayout.BeginScrollView(resultsScroll, GUI.skin.scrollView); resultsScroll = GUILayout.BeginScrollView(resultsScroll, GUI.skin.scrollView);
@ -132,10 +138,11 @@ namespace Explorer
if (m_searchResults.Count > 0) if (m_searchResults.Count > 0)
{ {
int offset = m_pageOffset * this.m_limit; //int offset = m_pageOffset * this.m_limit;
if (offset >= count) m_pageOffset = 0; //if (offset >= count) m_pageOffset = 0;
int offset = Pages.CalculateOffsetIndex();
for (int i = offset; i < offset + m_limit && i < count; i++) for (int i = offset; i < offset + Pages.PageLimit && i < count; i++)
{ {
m_searchResults[i].Draw(MainMenu.MainRect, 0f); m_searchResults[i].Draw(MainMenu.MainRect, 0f);
//m_searchResults[i].DrawValue(MainMenu.MainRect); //m_searchResults[i].DrawValue(MainMenu.MainRect);
@ -169,15 +176,15 @@ namespace Explorer
GUILayout.Label("Name Contains:", new GUILayoutOption[] { GUILayout.Width(100) }); GUILayout.Label("Name Contains:", new GUILayoutOption[] { GUILayout.Width(100) });
m_searchInput = GUILayout.TextField(m_searchInput, new GUILayoutOption[] { GUILayout.Width(200) }); m_searchInput = GUILayout.TextField(m_searchInput, new GUILayoutOption[] { GUILayout.Width(200) });
GUI.skin.label.alignment = TextAnchor.MiddleRight; //GUI.skin.label.alignment = TextAnchor.MiddleRight;
GUILayout.Label("Results per page:", new GUILayoutOption[] { GUILayout.Width(120) }); //GUILayout.Label("Results per page:", new GUILayoutOption[] { GUILayout.Width(120) });
var resultinput = m_limit.ToString(); //var resultinput = m_limit.ToString();
resultinput = GUILayout.TextField(resultinput, new GUILayoutOption[] { GUILayout.Width(55) }); //resultinput = GUILayout.TextField(resultinput, new GUILayoutOption[] { GUILayout.Width(55) });
if (int.TryParse(resultinput, out int _i) && _i > 0) //if (int.TryParse(resultinput, out int _i) && _i > 0)
{ //{
m_limit = _i; // m_limit = _i;
} //}
GUI.skin.label.alignment = TextAnchor.UpperLeft; //GUI.skin.label.alignment = TextAnchor.UpperLeft;
GUILayout.EndHorizontal(); GUILayout.EndHorizontal();
@ -256,7 +263,7 @@ namespace Explorer
private void Search() private void Search()
{ {
m_pageOffset = 0; Pages.PageOffset = 0;
CacheResults(FindAllObjectsOfType(m_searchInput, m_typeInput)); CacheResults(FindAllObjectsOfType(m_searchInput, m_typeInput));
} }

View File

@ -21,11 +21,13 @@ namespace Explorer
private string m_name; private string m_name;
private string m_scene; private string m_scene;
private Vector2 m_transformScroll = Vector2.zero;
private Transform[] m_children; private Transform[] m_children;
private Component[] m_components; private Vector2 m_transformScroll = Vector2.zero;
private PageHelper ChildPages = new PageHelper();
private Component[] m_components;
private Vector2 m_compScroll = Vector2.zero; private Vector2 m_compScroll = Vector2.zero;
private PageHelper CompPages = new PageHelper();
private float m_translateAmount = 0.3f; private float m_translateAmount = 0.3f;
private float m_rotateAmount = 50f; private float m_rotateAmount = 50f;
@ -74,12 +76,7 @@ namespace Explorer
? "None" ? "None"
: m_object.scene.name; : m_object.scene.name;
var list = new List<Transform>(); Update();
for (int i = 0; i < m_object.transform.childCount; i++)
{
list.Add(m_object.transform.GetChild(i));
}
m_children = list.ToArray();
} }
public override void Update() public override void Update()
@ -91,12 +88,30 @@ namespace Explorer
throw new Exception("Object is null!"); throw new Exception("Object is null!");
} }
var list = new List<Component>(); var list = new List<Transform>();
for (int i = 0; i < m_object.transform.childCount; i++)
{
list.Add(m_object.transform.GetChild(i));
}
list.Sort((a, b) => b.childCount.CompareTo(a.childCount));
m_children = list.ToArray();
ChildPages.Count = m_children.Length;
var list2 = new List<Component>();
foreach (var comp in m_object.GetComponents(ReflectionHelpers.ComponentType)) foreach (var comp in m_object.GetComponents(ReflectionHelpers.ComponentType))
{ {
list.Add(comp); var ilType = comp.GetIl2CppType();
if (ilType == ReflectionHelpers.TransformType)
{
continue;
} }
m_components = list.ToArray();
list2.Add(comp);
}
m_components = list2.ToArray();
CompPages.Count = m_components.Length;
} }
catch (Exception e) catch (Exception e)
{ {
@ -221,26 +236,46 @@ namespace Explorer
GUILayout.BeginVertical(GUI.skin.box, null); // new GUILayoutOption[] { GUILayout.Height(250) }); GUILayout.BeginVertical(GUI.skin.box, null); // new GUILayoutOption[] { GUILayout.Height(250) });
m_transformScroll = GUILayout.BeginScrollView(m_transformScroll, GUI.skin.scrollView); m_transformScroll = GUILayout.BeginScrollView(m_transformScroll, GUI.skin.scrollView);
GUILayout.Label("<b>Children:</b>", null); GUILayout.Label("<b><size=15>Children</size></b>", null);
GUILayout.BeginHorizontal(null);
ChildPages.DrawLimitInputArea();
if (ChildPages.Count > ChildPages.PageLimit)
{
ChildPages.CalculateMaxOffset();
ChildPages.CurrentPageLabel();
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal(null);
if (GUILayout.Button("< Prev", new GUILayoutOption[] { GUILayout.Width(80) }))
{
ChildPages.TurnPage(Turn.Left, ref this.m_transformScroll);
}
if (GUILayout.Button("Next >", new GUILayoutOption[] { GUILayout.Width(80) }))
{
ChildPages.TurnPage(Turn.Right, ref this.m_transformScroll);
}
}
GUILayout.EndHorizontal();
if (m_children != null && m_children.Length > 0) if (m_children != null && m_children.Length > 0)
{ {
foreach (var obj in m_children.Where(x => x.childCount > 0)) int start = ChildPages.CalculateOffsetIndex();
for (int j = start; (j < start + ChildPages.PageLimit && j < ChildPages.Count); j++)
{ {
var obj = m_children[j];
if (!obj) if (!obj)
{ {
GUILayout.Label("null", null); GUILayout.Label("null", null);
continue; continue;
} }
UIHelpers.GameobjButton(obj.gameObject, InspectGameObject, false, m_rect.width / 2 - 60);
} UIHelpers.GameobjButton(obj.gameObject, InspectGameObject, false, m_rect.width / 2 - 80);
foreach (var obj in m_children.Where(x => x.childCount == 0))
{
if (!obj)
{
GUILayout.Label("null", null);
continue;
}
UIHelpers.GameobjButton(obj.gameObject, InspectGameObject, false, m_rect.width / 2 - 60);
} }
} }
else else
@ -252,13 +287,35 @@ namespace Explorer
GUILayout.EndVertical(); GUILayout.EndVertical();
} }
private void ComponentList(Rect m_rect) private void ComponentList(Rect m_rect)
{ {
GUILayout.BeginVertical(GUI.skin.box, null); // new GUILayoutOption[] { GUILayout.Height(250) }); GUILayout.BeginVertical(GUI.skin.box, null); // new GUILayoutOption[] { GUILayout.Height(250) });
m_compScroll = GUILayout.BeginScrollView(m_compScroll, GUI.skin.scrollView); m_compScroll = GUILayout.BeginScrollView(m_compScroll, GUI.skin.scrollView);
GUILayout.Label("<b><size=15>Components</size></b>", null); GUILayout.Label("<b><size=15>Components</size></b>", null);
GUILayout.BeginHorizontal(null);
CompPages.DrawLimitInputArea();
if (CompPages.Count > CompPages.PageLimit)
{
CompPages.CalculateMaxOffset();
CompPages.CurrentPageLabel();
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal(null);
if (GUILayout.Button("< Prev", new GUILayoutOption[] { GUILayout.Width(80) }))
{
CompPages.TurnPage(Turn.Left, ref this.m_compScroll);
}
if (GUILayout.Button("Next >", new GUILayoutOption[] { GUILayout.Width(80) }))
{
CompPages.TurnPage(Turn.Right, ref this.m_compScroll);
}
}
GUILayout.EndHorizontal();
GUI.skin.button.alignment = TextAnchor.MiddleLeft; GUI.skin.button.alignment = TextAnchor.MiddleLeft;
if (m_cachedDestroyList.Count > 0) if (m_cachedDestroyList.Count > 0)
{ {
@ -267,15 +324,15 @@ namespace Explorer
if (m_components != null) if (m_components != null)
{ {
foreach (var component in m_components) int start = CompPages.CalculateOffsetIndex();
for (int j = start; (j < start + CompPages.PageLimit && j < CompPages.Count); j++)
{ {
var component = m_components[j];
if (!component) continue; if (!component) continue;
var ilType = component.GetIl2CppType(); var ilType = component.GetIl2CppType();
if (ilType == ReflectionHelpers.TransformType)
{
continue;
}
GUILayout.BeginHorizontal(null); GUILayout.BeginHorizontal(null);
if (ReflectionHelpers.BehaviourType.IsAssignableFrom(ilType)) if (ReflectionHelpers.BehaviourType.IsAssignableFrom(ilType))
@ -286,7 +343,7 @@ namespace Explorer
{ {
GUILayout.Space(26); GUILayout.Space(26);
} }
if (GUILayout.Button("<color=cyan>" + ilType.Name + "</color>", new GUILayoutOption[] { GUILayout.Width(m_rect.width / 2 - 90) })) if (GUILayout.Button("<color=cyan>" + ilType.Name + "</color>", new GUILayoutOption[] { GUILayout.Width(m_rect.width / 2 - 100) }))
{ {
ReflectObject(component); ReflectObject(component);
} }

View File

@ -20,8 +20,10 @@ namespace Explorer
private CacheObjectBase[] m_allCachedMembers; private CacheObjectBase[] m_allCachedMembers;
private CacheObjectBase[] m_cachedMembersFiltered; private CacheObjectBase[] m_cachedMembersFiltered;
private int m_pageOffset;
private int m_limitPerPage = 20; public PageHelper Pages = new PageHelper();
//private int m_pageOffset;
//private int m_limitPerPage = 20;
private bool m_autoUpdate = false; private bool m_autoUpdate = false;
private string m_search = ""; private string m_search = "";
@ -138,7 +140,7 @@ namespace Explorer
var name = $"{member.DeclaringType.Name}.{member.Name}"; var name = $"{member.DeclaringType.Name}.{member.Name}";
// blacklist (should probably make a proper implementation) // blacklist (should probably make a proper implementation)
if (name == "Type.DeclaringMethod" || member.Name.Contains("Il2CppType") || member.Name.StartsWith("get_") || member.Name.StartsWith("set_")) if (name == "Type.DeclaringMethod" || member.Name.StartsWith("get_") || member.Name.StartsWith("set_")) //|| member.Name.Contains("Il2CppType")
{ {
continue; continue;
} }
@ -254,34 +256,27 @@ namespace Explorer
GUILayout.Space(10); GUILayout.Space(10);
Pages.Count = m_cachedMembersFiltered.Length;
// prev/next page buttons // prev/next page buttons
GUILayout.BeginHorizontal(null); GUILayout.BeginHorizontal(null);
GUILayout.Label("<b>Limit per page:</b>", new GUILayoutOption[] { GUILayout.Width(125) });
var limitString = m_limitPerPage.ToString();
limitString = GUILayout.TextField(limitString, new GUILayoutOption[] { GUILayout.Width(60) });
if (int.TryParse(limitString, out int lim))
{
m_limitPerPage = lim;
}
int count = m_cachedMembersFiltered.Length; Pages.DrawLimitInputArea();
if (count > m_limitPerPage)
if (Pages.Count > Pages.PageLimit)
{ {
int maxOffset = (int)Mathf.Ceil((float)(count / (decimal)m_limitPerPage)) - 1; Pages.CalculateMaxOffset();
if (GUILayout.Button("< Prev", new GUILayoutOption[] { GUILayout.Width(80) })) if (GUILayout.Button("< Prev", new GUILayoutOption[] { GUILayout.Width(80) }))
{ {
if (m_pageOffset > 0) m_pageOffset--; Pages.TurnPage(Turn.Left, ref this.scroll);
scroll = Vector2.zero;
} }
GUI.skin.label.alignment = TextAnchor.MiddleCenter; Pages.CurrentPageLabel();
GUILayout.Label($"Page {m_pageOffset + 1}/{maxOffset + 1}", new GUILayoutOption[] { GUILayout.Width(80) });
GUI.skin.label.alignment = TextAnchor.UpperLeft;
if (GUILayout.Button("Next >", new GUILayoutOption[] { GUILayout.Width(80) })) if (GUILayout.Button("Next >", new GUILayoutOption[] { GUILayout.Width(80) }))
{ {
if (m_pageOffset < maxOffset) m_pageOffset++; Pages.TurnPage(Turn.Right, ref this.scroll);
scroll = Vector2.zero;
} }
} }
GUILayout.EndHorizontal(); GUILayout.EndHorizontal();
@ -297,18 +292,9 @@ namespace Explorer
GUILayout.BeginVertical(GUI.skin.box, null); GUILayout.BeginVertical(GUI.skin.box, null);
var members = this.m_cachedMembersFiltered; var members = this.m_cachedMembersFiltered;
int start = m_pageOffset * m_limitPerPage; int start = Pages.CalculateOffsetIndex();
if (start >= count) for (int j = start; (j < start + Pages.PageLimit && j < members.Length); j++)
{
int maxOffset = (int)Mathf.Ceil((float)(m_cachedMembersFiltered.Length / (decimal)m_limitPerPage)) - 1;
if (m_pageOffset > maxOffset)
{
m_pageOffset = 0;
}
}
for (int j = start; (j < start + m_limitPerPage && j < members.Length); j++)
{ {
var holder = members[j]; var holder = members[j];
@ -325,7 +311,7 @@ namespace Explorer
GUILayout.EndHorizontal(); GUILayout.EndHorizontal();
// if not last element // if not last element
if (!(j == (start + m_limitPerPage - 1) || j == (members.Length - 1))) if (!(j == (start + Pages.PageLimit - 1) || j == (members.Length - 1)))
UIStyles.HorizontalLine(new Color(0.07f, 0.07f, 0.07f), true); UIStyles.HorizontalLine(new Color(0.07f, 0.07f, 0.07f), true);
} }
@ -367,7 +353,8 @@ namespace Explorer
if (GUILayout.Button(label, new GUILayoutOption[] { GUILayout.Width(100) })) if (GUILayout.Button(label, new GUILayoutOption[] { GUILayout.Width(100) }))
{ {
m_filter = mode; m_filter = mode;
m_pageOffset = 0; Pages.PageOffset = 0;
scroll = Vector2.zero;
} }
GUI.color = Color.white; GUI.color = Color.white;
} }