mirror of
https://github.com/originalnicodr/CinematicUnityExplorer.git
synced 2026-10-11 09:58:02 +08:00
* Fixed a bug where the Page Helper would not update the total page count after changing the limit per page * Cleaned up the "Find Instances" helper, it will now filter out all types in the `System`, `Mono`, `Il2CppSystem` and `Iced` namespaces. * Improved the Find Instances helper so that it will avoid exceptions and get more results. * Enums now display their value type name * Changed the Scroll View unstrip so that it is less hard-coded for different unity versions and more dynamic.
110 lines
2.6 KiB
C#
110 lines
2.6 KiB
C#
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 ItemsPerPage
|
|
{
|
|
get => m_itemsPerPage;
|
|
set
|
|
{
|
|
m_itemsPerPage = value;
|
|
CalculateMaxOffset();
|
|
}
|
|
}
|
|
private int m_itemsPerPage = 20;
|
|
|
|
public int ItemCount
|
|
{
|
|
get => m_count;
|
|
set
|
|
{
|
|
m_count = value;
|
|
CalculateMaxOffset();
|
|
}
|
|
}
|
|
private int m_count;
|
|
|
|
public int MaxPageOffset { get; private set; } = -1;
|
|
|
|
private int CalculateMaxOffset()
|
|
{
|
|
return MaxPageOffset = (int)Mathf.Ceil((float)(ItemCount / (decimal)ItemsPerPage)) - 1;
|
|
}
|
|
|
|
public void CurrentPageLabel()
|
|
{
|
|
var orig = GUI.skin.label.alignment;
|
|
GUI.skin.label.alignment = TextAnchor.MiddleCenter;
|
|
|
|
GUILayout.Label($"Page {PageOffset + 1}/{MaxPageOffset + 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 < MaxPageOffset)
|
|
{
|
|
PageOffset++;
|
|
scroll = Vector2.zero;
|
|
}
|
|
}
|
|
}
|
|
|
|
public int CalculateOffsetIndex()
|
|
{
|
|
int offset = PageOffset * ItemsPerPage;
|
|
|
|
if (offset >= ItemCount)
|
|
{
|
|
offset = 0;
|
|
PageOffset = 0;
|
|
}
|
|
|
|
return offset;
|
|
}
|
|
|
|
public void DrawLimitInputArea()
|
|
{
|
|
GUILayout.Label("Limit: ", new GUILayoutOption[] { GUILayout.Width(50) });
|
|
var limit = this.ItemsPerPage.ToString();
|
|
limit = GUILayout.TextField(limit, new GUILayoutOption[] { GUILayout.Width(50) });
|
|
if (limit != ItemsPerPage.ToString() && int.TryParse(limit, out int i))
|
|
{
|
|
ItemsPerPage = i;
|
|
}
|
|
}
|
|
}
|
|
}
|