65 lines
2.4 KiB
C#
65 lines
2.4 KiB
C#
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace TKS
|
|
{
|
|
/// <summary>
|
|
/// 물리 뒤로 가기(Android 백키 · 뒤로 제스처 = KeyCode.Escape) 처리 순서표 — PD 2026-11-26 「구글 플레이 피처드 정책(물리 백키로 돌아가기 · 취소)」.
|
|
/// 화면 위에 뜨는 덮개(설정 팝업 · 뽑기 연출 · 대사 · 보스 등장 · 인트로 · 타이틀 등)가 열릴 때 Push → 백키 = 가장 나중에 열린 「켜져 있는」 덮개부터 처리.
|
|
/// 덮개가 사라지면(오브젝트 파괴) 스스로 빠진다. 공용 팝업(OutGameRoot.Modal) · 화면 이동은 OutGameRoot.HandleBackKey 가 이어서 처리.
|
|
/// </summary>
|
|
public static class UiBack
|
|
{
|
|
struct Entry
|
|
{
|
|
public GameObject owner;
|
|
public System.Func<bool> handle;
|
|
}
|
|
|
|
static readonly List<Entry> stack = new List<Entry>();
|
|
|
|
/// <summary>덮개 등록 — handle 이 true 를 돌려주면 그 백키는 여기서 끝(false = 아래 덮개 · 화면으로 넘김).</summary>
|
|
public static void Push(GameObject owner, System.Func<bool> handle)
|
|
{
|
|
if (owner == null || handle == null) return;
|
|
Remove(owner);
|
|
stack.Add(new Entry { owner = owner, handle = handle });
|
|
}
|
|
|
|
public static void Remove(GameObject owner)
|
|
{
|
|
for (int i = stack.Count - 1; i >= 0; i--)
|
|
if (stack[i].owner == null || stack[i].owner == owner)
|
|
stack.RemoveAt(i);
|
|
}
|
|
|
|
/// <summary>맨 위의 살아 있는(켜진) 덮개부터 처리 — 처리했으면 true.</summary>
|
|
public static bool Handle()
|
|
{
|
|
for (int i = stack.Count - 1; i >= 0; i--)
|
|
{
|
|
if (i >= stack.Count) continue;
|
|
var e = stack[i];
|
|
if (e.owner == null)
|
|
{
|
|
stack.RemoveAt(i);
|
|
continue;
|
|
}
|
|
if (!e.owner.activeInHierarchy) continue;
|
|
if (e.handle()) return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/// <summary>등록된 살아 있는 덮개 수(시험용).</summary>
|
|
public static int Count
|
|
{
|
|
get
|
|
{
|
|
stack.RemoveAll(e => e.owner == null);
|
|
return stack.Count;
|
|
}
|
|
}
|
|
}
|
|
}
|