87 lines
4.4 KiB
C#
87 lines
4.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Threading.Tasks;
|
|
using HotUpdate.Gameplay;
|
|
using HotUpdate.UI;
|
|
using TMPro;
|
|
using UnityEditor;
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
using UnityEngine.UI;
|
|
|
|
public static class VerifySettings
|
|
{
|
|
static PrototypeFlow Flow => UnityEngine.Object.FindObjectOfType<PrototypeFlow>();
|
|
static void Check(bool value, string message) { if (!value) throw new Exception(message); }
|
|
static async Task Until(Func<bool> condition, int seconds = 20)
|
|
{
|
|
var end = DateTime.UtcNow.AddSeconds(seconds);
|
|
while (!condition())
|
|
{
|
|
Check(DateTime.UtcNow < end, "Settings timed out: " + Flow?.Page);
|
|
await Task.Delay(100);
|
|
}
|
|
}
|
|
static Button Button(string name) => UnityEngine.Object.FindObjectsOfType<Button>().Single(b => b.name == "Btn_" + name && b.gameObject.activeInHierarchy);
|
|
static void Click(string name)
|
|
{
|
|
var b = Button(name);
|
|
Check(b.interactable, "Disabled " + name);
|
|
Canvas.ForceUpdateCanvases();
|
|
var rect = b.GetComponent<RectTransform>();
|
|
var pointer = new PointerEventData(EventSystem.current) { position = RectTransformUtility.WorldToScreenPoint(null, rect.TransformPoint(rect.rect.center)), button = PointerEventData.InputButton.Left };
|
|
var hits = new List<RaycastResult>();
|
|
EventSystem.current.RaycastAll(pointer, hits);
|
|
Check(hits.Count > 0 && ExecuteEvents.GetEventHandler<IPointerClickHandler>(hits[0].gameObject) == b.gameObject, "Blocked " + name);
|
|
ExecuteEvents.Execute(b.gameObject, pointer, ExecuteEvents.pointerClickHandler);
|
|
}
|
|
static async Task Capture(string name)
|
|
{
|
|
await Task.Delay(180);
|
|
var type = AppDomain.CurrentDomain.GetAssemblies().Select(a => a.GetType("Unity.Pipeline.Editor.Commands.Capture.CaptureCommands")).First(t => t != null);
|
|
type.GetMethod("CaptureGameView", BindingFlags.Public | BindingFlags.Static).Invoke(null, new object[] { 1080, 1920, null, "Screenshots/settings_" + name + ".png", false, 0, "screen" });
|
|
}
|
|
|
|
public static string Assets()
|
|
{
|
|
var prefab = AssetDatabase.LoadAssetAtPath<GameObject>("Assets/Bundles/UI/Prefab/UI_PrototypeSettings.prefab");
|
|
Check(prefab != null, "Missing settings prefab");
|
|
Check(prefab.GetComponentsInChildren<TextMeshProUGUI>(true).All(t => t.font != null), "Missing settings font");
|
|
foreach (var image in prefab.GetComponentsInChildren<Image>(true).Where(i => i.type == Image.Type.Sliced))
|
|
Check(image.sprite != null && image.sprite.border.x > 0 && image.sprite.border.y > 0, "Invalid settings nine slice " + image.name);
|
|
var names = prefab.GetComponentsInChildren<Transform>(true).Select(t => t.name).ToHashSet();
|
|
foreach (var name in new[] { "Btn_ToggleMusic", "Btn_ToggleSfx", "Btn_CycleQuality", "Btn_ToggleVibrate", "Btn_Relogin", "Btn_DeleteAccount", "Txt_AccountInfo", "Btn_Close" })
|
|
Check(names.Contains(name), "Missing settings node " + name);
|
|
Check(!names.Contains("Btn_Back"), "Settings should not keep the camp back button");
|
|
bool music = PrototypeClientPrefs.Music;
|
|
PrototypeClientPrefs.Music = !music;
|
|
Check(PrototypeClientPrefs.Music == !music, "Music pref not persisted");
|
|
PrototypeClientPrefs.Music = music;
|
|
PrototypeClientPrefs.Apply();
|
|
return "PASS settings prefab, fonts, nine-slices, toggle nodes and local music preference.";
|
|
}
|
|
|
|
public static async Task<string> Play()
|
|
{
|
|
Check(EditorApplication.isPlaying, "Enter Play Mode first");
|
|
await Until(() => Flow?.Game != null && !Flow.IsBusy);
|
|
Check(Flow.Handle("Settings"), "Settings entry not handled");
|
|
await Until(() => Flow.Page == "UI_PrototypeSettings");
|
|
bool music = PrototypeClientPrefs.Music;
|
|
Click("ToggleMusic");
|
|
await Task.Delay(120);
|
|
Check(PrototypeClientPrefs.Music == !music, "Music toggle did not flip");
|
|
Click("ToggleMusic");
|
|
await Task.Delay(80);
|
|
Check(PrototypeClientPrefs.Music == music, "Music toggle did not restore");
|
|
Click("CycleQuality");
|
|
await Task.Delay(80);
|
|
await Capture("page");
|
|
Click("Close");
|
|
await Until(() => Flow.Page == "Home");
|
|
return "PASS settings opens from home, toggles music/quality, closes with X, screenshot settings_page.png";
|
|
}
|
|
}
|