mly2023cheat/CheatUtil.cs

109 lines
2.5 KiB
C#
Raw Normal View History

2023-08-24 14:33:32 +08:00
using System;
using System.Collections.Generic;
using UnityEngine;
namespace Mly.Hotfix
{
public static class CheatUtil
{
public static float StartX = 100;
public static float StartY = 100;
public static float SpaceX = 10;
public static float SpaceY = 10;
public static float W = 110;
public static float H = 30;
public static int Columns = 5;
public static int X;
public static int Y;
private static float startX;
private static float startY;
private static float spaceX;
private static float spaceY;
public static void AutoScaling()
{
var wa = Screen.width / 1280f;
var ha = Screen.height / 720f;
startX = StartX * wa;
startY = StartY * ha;
spaceX = SpaceX * wa;
spaceY = SpaceY * ha;
}
public static void PointToStart()
{
X = Y = 0;
}
public static void PointToNext()
{
if (++X >= Columns)
{
X = 0;
++Y;
}
}
public static void PointToNewLine()
{
if (X > 0)
{
++Y;
}
X = 0;
}
public static Rect GetNextRect()
{
return new Rect(startX + X * (W + spaceX), startY + Y * (H + spaceY), W, H);
}
public static void DrawCheatList<T>(IList<T> list, Action<T, Rect> action)
{
for (int i = 0; i < list.Count; i++)
{
var item = list[i];
action?.Invoke(item, GetNextRect());
PointToNext();
}
PointToNewLine();
}
public static GUIStyle GetGUIButtonStyle()
{
return GetGUIStyle(GUI.skin.button);
}
public static GUIStyle GetGUIStyle(GUIStyle style)
{
return new GUIStyle(style);
}
public static CheatAdvView AddCheatView(ICheatOpenStage view, GameObject go)
{
var cheat = go.AddComponent<CheatAdvView>();
cheat.View = view;
return cheat;
}
public static void Init()
{
CheatInteractor.ActionMap.Add(typeof(EventQuestView), vc =>
{
var cheatV = vc.GameObject.AddComponent<CheatAdvView>();
//cheatV.View = vc;
});
}
}
}