Files
UltimateFishing/Assets/Scripts/Assembly-CSharp/SRDebugger/Internal/SRDebuggerUtil.cs
2026-02-21 16:45:37 +08:00

106 lines
3.1 KiB
C#

using System.Collections.Generic;
using System.ComponentModel;
using System.Reflection;
using SRF.Helpers;
using UnityEngine;
using UnityEngine.EventSystems;
namespace SRDebugger.Internal
{
public static class SRDebuggerUtil
{
public static bool IsMobilePlatform
{
get
{
if (Application.isMobilePlatform)
{
return true;
}
switch (Application.platform)
{
case RuntimePlatform.MetroPlayerX86:
case RuntimePlatform.MetroPlayerX64:
case RuntimePlatform.MetroPlayerARM:
return true;
default:
return false;
}
}
}
public static bool EnsureEventSystemExists()
{
if (EventSystem.current != null)
{
return false;
}
EventSystem eventSystem = Object.FindObjectOfType<EventSystem>();
if (eventSystem != null && eventSystem.gameObject.activeSelf && eventSystem.enabled)
{
return false;
}
CreateDefaultEventSystem();
return true;
}
public static void CreateDefaultEventSystem()
{
GameObject gameObject = new GameObject("EventSystem");
gameObject.AddComponent<EventSystem>();
gameObject.AddComponent<StandaloneInputModule>();
}
public static ICollection<OptionDefinition> ScanForOptions(object obj)
{
List<OptionDefinition> list = new List<OptionDefinition>();
MemberInfo[] members = obj.GetType().GetMembers(BindingFlags.Instance | BindingFlags.Public | BindingFlags.InvokeMethod | BindingFlags.GetProperty | BindingFlags.SetProperty);
MemberInfo[] array = members;
foreach (MemberInfo memberInfo in array)
{
CategoryAttribute attribute = SRReflection.GetAttribute<CategoryAttribute>(memberInfo);
string category = ((attribute != null) ? attribute.Category : "Default");
SROptions.SortAttribute attribute2 = SRReflection.GetAttribute<SROptions.SortAttribute>(memberInfo);
int sortPriority = ((attribute2 != null) ? attribute2.SortPriority : 0);
SROptions.DisplayNameAttribute attribute3 = SRReflection.GetAttribute<SROptions.DisplayNameAttribute>(memberInfo);
string name = ((attribute3 != null) ? attribute3.Name : memberInfo.Name);
if (memberInfo is PropertyInfo)
{
PropertyInfo propertyInfo = memberInfo as PropertyInfo;
if (propertyInfo.GetGetMethod() != null && (propertyInfo.GetGetMethod().Attributes & MethodAttributes.Static) == 0)
{
list.Add(new OptionDefinition(name, category, sortPriority, new PropertyReference(obj, propertyInfo)));
}
}
else if (memberInfo is MethodInfo)
{
MethodInfo methodInfo = memberInfo as MethodInfo;
if (!methodInfo.IsStatic && methodInfo.ReturnType == typeof(void) && methodInfo.GetParameters().Length <= 0)
{
list.Add(new OptionDefinition(name, category, sortPriority, new MethodReference(obj, methodInfo)));
}
}
}
return list;
}
public static string GetNumberString(int value, int max, string exceedsMaxString)
{
if (value >= max)
{
return exceedsMaxString;
}
return value.ToString();
}
public static void ConfigureCanvas(Canvas canvas)
{
if (Settings.Instance.UseDebugCamera)
{
canvas.worldCamera = Service.DebugCamera.Camera;
canvas.renderMode = RenderMode.ScreenSpaceCamera;
}
}
}
}