ReferenceAudit.cs 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using System;
  2. using System.IO;
  3. using System.Linq;
  4. using System.Reflection;
  5. using UnityEditor;
  6. using UnityEngine;
  7. using UnityEngine.UI;
  8. namespace Olympus.Editor
  9. {
  10. public static class ReferenceAudit
  11. {
  12. static BindingFlags flags=BindingFlags.Instance|BindingFlags.NonPublic;
  13. static T Field<T>(OlympusGame app,string key)=>(T)typeof(OlympusGame).GetField(key,flags).GetValue(app);
  14. static void Call(OlympusGame app,string method)=>typeof(OlympusGame).GetMethod(method,flags).Invoke(app,null);
  15. public static string Comparison(string page)
  16. {
  17. if(!Application.isPlaying||!SessionState.GetBool("OlympusCapture",false))throw new Exception("Use isolated editor capture save.");
  18. var app=UnityEngine.Object.FindFirstObjectByType<OlympusGame>();var store=Field<PlayerStore>(app,"store");var game=Field<MatchEngine>(app,"game");var config=Field<GameConfig>(app,"config");
  19. app.ShowPreview("Lobby");store.Reset();store.Data.avatar=1;store.Data.name="Rustic Lyra";store.Data.profileSet=true;store.Save();app.ShowPreview("Lobby");
  20. if(page=="Trial")
  21. {
  22. game.Start("olympus");var question=config.questions.First(q=>q.Normalized=="POSEIDON");typeof(MatchEngine).GetField("rounds",flags).SetValue(game,new[]{question,question,question,question,question});
  23. game.Tick(4);game.Tick(2);game.Tick(Math.Max(0,game.TimeTotal-24));
  24. typeof(MatchEngine).GetProperty("Reveal").SetValue(game,60d,null);Call(app,"RefreshTrial");Field<TMPro.TextMeshProUGUI>(app,"toast").gameObject.SetActive(false);var v=Field<ReferenceAView>(app,"referenceView");v.reveal.Configure(question.id,0);v.reveal.SetAmount(60);
  25. // Freeze the engine but let Game View render the new page before capturing it.
  26. app.ArtReviewMode=true;EditorApplication.isPaused=false;Canvas.ForceUpdateCanvases();
  27. }
  28. return "Native "+page+" comparison fixture ready (isolated save).";
  29. }
  30. public static string ExerciseRealms()
  31. {
  32. if(!Application.isPlaying||!SessionState.GetBool("OlympusCapture",false))throw new Exception("Use isolated editor capture save.");
  33. var app=UnityEngine.Object.FindFirstObjectByType<OlympusGame>();var store=Field<PlayerStore>(app,"store");var game=Field<MatchEngine>(app,"game");
  34. int submits=0;
  35. for(int realm=0;realm<4;realm++)
  36. {
  37. app.ShowPreview("Lobby");store.Reset();app.ShowPreview("Lobby");Field<ReferenceAView>(app,"referenceView").realmButtons[realm].onClick.Invoke();game.Tick(4);game.Tick(2);
  38. for(int round=0;round<5;round++)
  39. {
  40. var v=Field<ReferenceAView>(app,"referenceView");if(!v||!v.question.sprite)throw new Exception("Missing question binding");
  41. v.letterButtons[0].onClick.Invoke();string selected=v.answerText.text;if(round==0){v.itemButtons[0].onClick.Invoke();if(v.answerText.text!=selected)throw new Exception("Hint cleared selected tiles");}
  42. TileAnswerAudit.SelectAnswer(app,game.Current.answer);v.FindButton("OK").onClick.Invoke();if(game.Phase!=MatchPhase.Answer)throw new Exception("Answer submission failed");submits++;
  43. game.Tick(1.6);if(round<4){game.Continue();game.Tick(1.3);}
  44. }
  45. if(game.Phase!=MatchPhase.Result)throw new Exception("Missing results");
  46. }
  47. string report="PASS 4 realms / 20 answers selected exclusively through candidate tile buttons / 4 results\nPASS hint retains selected tiles in every realm\nPASS all question sprites bound\n";Directory.CreateDirectory("docs/验证");File.WriteAllText("docs/验证/A界面流程.txt",report);return report;
  48. }
  49. }
  50. }