Skip to content

Commit 80f46e2

Browse files
committed
[F] 在游戏开始后再按键打开DisplayInTouch,由于组件未被创建而无效的问题
1 parent b83a128 commit 80f46e2

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

AquaMai.Mods/Utils/DisplayTouchInGame.cs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public static void OnMusicSelectProcessUpdate()
7272

7373
[HarmonyPostfix]
7474
[HarmonyPatch(typeof(GameProcess), nameof(GameProcess.OnUpdate))]
75-
public static void OnGameProcessUpdate()
75+
public static void OnGameProcessUpdate(GameMonitor[] ____monitors)
7676
{
7777
for (int i = 0; i < 2; i++)
7878
{
@@ -86,6 +86,10 @@ public static void OnGameProcessUpdate()
8686
for (int i = 0; i < 2; i++)
8787
{
8888
if (canvasGameObjects[i] == null) continue;
89+
if (displayType[i] > 0 && canvasGameObjects[i].Count == 0)
90+
{ // 能走到这里,说明肯定是触发了切换键的;现在displayType[i] > 0,说明功能肯定是刚刚才被打开的。因此如果canvasGameObject此前未被创建的话,则现在应该创建之。
91+
CreateDisplay(displayType[i], ____monitors[i]);
92+
}
8993
foreach (var go in canvasGameObjects[i])
9094
{
9195
if (go == null) continue;
@@ -118,19 +122,18 @@ public static void OnGameStart(GameMonitor[] ____monitors)
118122
canvasGameObjects[i].Clear();
119123
var type = displayType[i];
120124
if (type is < 1 or > 5) continue;
121-
if (type is 4 or 5)
122-
{
123-
CreateDisplay(3, ____monitors[i]);
124-
type -= 3;
125-
}
126-
if (type > 3) continue;
127125
CreateDisplay(type, ____monitors[i]);
128126
}
129127
}
130128

131129
// type 只能传入 1 2 3,如果是 4 或 5 的话,拆分成两个 call
132130
private static void CreateDisplay(int type, GameMonitor monitor)
133131
{
132+
if (type is 4 or 5)
133+
{
134+
CreateDisplay(3, monitor);
135+
type -= 3;
136+
}
134137
if (type is < 1 or > 3) throw new ArgumentException("这不对吧");
135138
var sub = monitor.gameObject.transform.Find("Canvas/Sub");
136139
if (type == 3)

0 commit comments

Comments
 (0)