* Implemented manual unstripping for ScrollView and Resize, should now work on any Unity 2018 or 2019 game.
* Fixed a bug with page view on the Scene Explorer
* Back-end cleanups
This commit is contained in:
sinaioutlander
2020-09-04 21:36:40 +10:00
parent 5de771389e
commit 6adaaf5500
17 changed files with 1002 additions and 103 deletions

View File

@ -16,13 +16,23 @@ namespace Explorer
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()
public int ItemsPerPage { get; set; } = 20;
public int ItemCount
{
return MaxOffset = (int)Mathf.Ceil((float)(Count / (decimal)PageLimit)) - 1;
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()
@ -30,7 +40,7 @@ namespace Explorer
var orig = GUI.skin.label.alignment;
GUI.skin.label.alignment = TextAnchor.MiddleCenter;
GUILayout.Label($"Page {PageOffset + 1}/{MaxOffset + 1}", new GUILayoutOption[] { GUILayout.Width(80) });
GUILayout.Label($"Page {PageOffset + 1}/{MaxPageOffset + 1}", new GUILayoutOption[] { GUILayout.Width(80) });
GUI.skin.label.alignment = orig;
}
@ -53,7 +63,7 @@ namespace Explorer
}
else
{
if (PageOffset < MaxOffset)
if (PageOffset < MaxPageOffset)
{
PageOffset++;
scroll = Vector2.zero;
@ -63,9 +73,9 @@ namespace Explorer
public int CalculateOffsetIndex()
{
int offset = PageOffset * PageLimit;
int offset = PageOffset * ItemsPerPage;
if (offset >= Count)
if (offset >= ItemCount)
{
offset = 0;
PageOffset = 0;
@ -77,11 +87,11 @@ namespace Explorer
public void DrawLimitInputArea()
{
GUILayout.Label("Limit: ", new GUILayoutOption[] { GUILayout.Width(50) });
var limit = this.PageLimit.ToString();
var limit = this.ItemsPerPage.ToString();
limit = GUILayout.TextField(limit, new GUILayoutOption[] { GUILayout.Width(50) });
if (limit != PageLimit.ToString() && int.TryParse(limit, out int i))
if (limit != ItemsPerPage.ToString() && int.TryParse(limit, out int i))
{
PageLimit = i;
ItemsPerPage = i;
}
}
}

View File

@ -3,6 +3,8 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Reflection;
using UnhollowerRuntimeLib;
using UnityEngine;
using Object = UnityEngine.Object;
@ -10,35 +12,6 @@ namespace Explorer
{
public class UIHelpers
{
private static bool ScrollUnstrippingFailed = false;
public static Vector2 BeginScrollView(Vector2 scroll) => BeginScrollView(scroll, null);
public static Vector2 BeginScrollView(Vector2 scroll, GUIStyle style, params GUILayoutOption[] layoutOptions)
{
if (ScrollUnstrippingFailed) return scroll;
try
{
if (style != null)
return GUILayout.BeginScrollView(scroll, style, layoutOptions);
else
return GUILayout.BeginScrollView(scroll, layoutOptions);
}
catch
{
ScrollUnstrippingFailed = true;
return scroll;
}
}
public static void EndScrollView()
{
if (ScrollUnstrippingFailed) return;
GUILayout.EndScrollView();
}
// helper for "Instantiate" button on UnityEngine.Objects
public static void InstantiateButton(Object obj, float width = 100)
{
@ -51,13 +24,13 @@ namespace Explorer
}
// helper for drawing a styled button for a GameObject or Transform
public static void GameobjButton(object _obj, Action<Transform> specialInspectMethod = null, bool showSmallInspectBtn = true, float width = 380)
public static void GOButton(object _obj, Action<Transform> specialInspectMethod = null, bool showSmallInspectBtn = true, float width = 380)
{
var obj = (_obj as GameObject) ?? (_obj as Transform).gameObject;
bool children = obj.transform.childCount > 0;
bool hasChild = obj.transform.childCount > 0;
string label = children ? "[" + obj.transform.childCount + " children] " : "";
string label = hasChild ? $"[{obj.transform.childCount} children] " : "";
label += obj.name;
bool enabled = obj.activeSelf;
@ -80,10 +53,10 @@ namespace Explorer
color = Color.red;
}
FastGameobjButton(_obj, color, label, obj.activeSelf, specialInspectMethod, showSmallInspectBtn, width);
GOButton_Impl(_obj, color, label, obj.activeSelf, specialInspectMethod, showSmallInspectBtn, width);
}
public static void FastGameobjButton(object _obj, Color activeColor, string label, bool enabled, Action<Transform> specialInspectMethod = null, bool showSmallInspectBtn = true, float width = 380)
public static void GOButton_Impl(object _obj, Color activeColor, string label, bool enabled, Action<Transform> specialInspectMethod = null, bool showSmallInspectBtn = true, float width = 380)
{
var obj = _obj as GameObject ?? (_obj as Transform).gameObject;