IndependentUiAudit.cs 6.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. using System;
  2. using System.IO;
  3. using System.Linq;
  4. using System.Collections;
  5. using System.Collections.Generic;
  6. using System.Text;
  7. using TMPro;
  8. using UnityEditor;
  9. using UnityEngine;
  10. using UnityEngine.EventSystems;
  11. using UnityEngine.UI;
  12. namespace Olympus.Editor
  13. {
  14. public static class IndependentUiAudit
  15. {
  16. const string Root="Assets/Olympus/Resources/Olympus/";
  17. public static string Status {get;private set;}="Not started";
  18. public static string Dependencies()
  19. {
  20. var report=new StringBuilder();
  21. foreach(string name in new[]{"Lobby","Trial","Start","Checkin","Settings","Shop","Leaderboard","Loading","Result","General"})
  22. {
  23. string path=Root+(name=="Lobby"||name=="Trial"?"ReferenceA/":"Suite/")+name+".prefab";
  24. var prefab=AssetDatabase.LoadAssetAtPath<GameObject>(path);if(!prefab)throw new Exception("Missing "+path);
  25. foreach(string dep in AssetDatabase.GetDependencies(path,true))
  26. {
  27. if(!dep.EndsWith(".png",StringComparison.OrdinalIgnoreCase))continue;
  28. if(!dep.StartsWith(Root+"Elements/")&&!dep.StartsWith(Root+"Art/")&&!dep.StartsWith(Root+"Questions/")&&dep!=DeleteIconBuilder.Path)throw new Exception("Forbidden UI image dependency: "+name+" -> "+dep);
  29. }
  30. foreach(var i in prefab.GetComponentsInChildren<Image>(true))
  31. {
  32. if(!i.sprite)continue;var r=i.sprite.rect;var t=i.sprite.texture;
  33. bool independentTrim=AssetDatabase.GetAssetPath(i.sprite).StartsWith(Root+"Elements/v3_")&&AssetDatabase.LoadAllAssetsAtPath(AssetDatabase.GetAssetPath(i.sprite)).OfType<Sprite>().Count()==1;
  34. if(!independentTrim&&(r.x!=0||r.y!=0||r.width!=t.width||r.height!=t.height))throw new Exception("Partial source image: "+name+"/"+i.name);
  35. }
  36. foreach(var glyph in prefab.GetComponentsInChildren<TempleGlyph>(true))if(!glyph.GetComponent<CanvasRenderer>())throw new Exception("Missing glyph renderer");
  37. report.AppendLine("PASS "+name+": independent images only (v3 excludes exterior transparent padding), native TMP labels, no mockup/screen-plate dependencies");
  38. }
  39. Directory.CreateDirectory("docs/验证");File.WriteAllText("docs/验证/独立UI资源依赖.txt",report.ToString());return report.ToString();
  40. }
  41. public static string StartCapture(string output="IndependentUI")
  42. {
  43. var app=UnityEngine.Object.FindFirstObjectByType<OlympusGame>();if(!Application.isPlaying||!app||!app.IsEditorPreviewSave)throw new Exception("Use isolated Art Review save");
  44. app.StartCoroutine(Capture(app,output));return Status="Capturing independent UI pages";
  45. }
  46. static IEnumerator Capture(OlympusGame app,string output)
  47. {
  48. var report=new StringBuilder();string folder="docs/运行截图/"+output;Directory.CreateDirectory(folder);
  49. foreach(string name in new[]{"Start","Lobby","Trial","Checkin","Settings","Shop","Leaderboard","Loading","Result"})
  50. {
  51. Status="Capturing "+name;app.ShowDesignPage(name);yield return null;yield return null;yield return new WaitForSecondsRealtime(.25f);Canvas.ForceUpdateCanvases();
  52. var root=app.GetComponentsInChildren<SuiteView>().LastOrDefault();Transform page=root?root.transform:app.GetComponentInChildren<ReferenceAView>().transform;
  53. foreach(var t in page.GetComponentsInChildren<TextMeshProUGUI>()){t.ForceMeshUpdate();if(t.isTextOverflowing)report.AppendLine("CHECK text overflow "+name+"/"+t.name);}
  54. foreach(var b in page.GetComponentsInChildren<Button>())
  55. {
  56. if(!b.interactable)continue;var r=(RectTransform)b.transform;var d=new PointerEventData(EventSystem.current){position=RectTransformUtility.WorldToScreenPoint(null,r.TransformPoint(r.rect.center))};var hits=new List<RaycastResult>();EventSystem.current.RaycastAll(d,hits);
  57. if(hits.Count==0||hits[0].gameObject.GetComponentInParent<Button>()!=b)report.AppendLine("CHECK hit "+name+"/"+b.name);
  58. }
  59. ScreenCapture.CaptureScreenshot(folder+"/"+name+".png");report.AppendLine("CAPTURE "+name+" at "+Screen.width+"x"+Screen.height);yield return null;yield return null;
  60. }
  61. ManualContinueAudit.FeedbackPreview("correct");yield return null;yield return null;ScreenCapture.CaptureScreenshot(folder+"/AnswerFeedback.png");yield return null;yield return null;
  62. WeeklyAndPoolAudit.IntermissionPreview();yield return null;yield return null;ScreenCapture.CaptureScreenshot(folder+"/Intermission.png");yield return null;yield return null;
  63. app.ShowDesignPage("Lobby");File.WriteAllText("docs/验证/"+output+"页面检查.txt",report.ToString());Status=report.ToString();
  64. }
  65. public static string CaptureExtras()
  66. {
  67. var app=UnityEngine.Object.FindFirstObjectByType<OlympusGame>();if(!Application.isPlaying||!app||!app.IsEditorPreviewSave)throw new Exception("Use isolated Art Review save");
  68. app.StartCoroutine(Extras(app));return Status="Capturing profile, instructions, records and menu";
  69. }
  70. static IEnumerator Extras(OlympusGame app)
  71. {
  72. var report=new StringBuilder();
  73. foreach(var name in new[]{"Profile","How to","Coin records","Menu"})
  74. {
  75. app.ShowDesignPage(name);yield return null;yield return null;yield return new WaitForSecondsRealtime(.25f);Canvas.ForceUpdateCanvases();
  76. var view=app.GetComponentsInChildren<SuiteView>().Last();
  77. foreach(var image in view.GetComponentsInChildren<Image>())
  78. {
  79. if(!image.sprite)continue;
  80. if(image.type==Image.Type.Simple&&!image.preserveAspect)throw new Exception("Stretch in "+name+"/"+image.name);
  81. }
  82. ScreenCapture.CaptureScreenshot("docs/运行截图/ReferenceScaleUI/"+name+".png");report.AppendLine("PASS "+name+": shared UI kit / proportional images / captured at "+Screen.width+"x"+Screen.height);yield return null;
  83. }
  84. app.ShowDesignPage("Lobby");File.WriteAllText("docs/验证/通用页面比例检查.txt",report.ToString());Status=report.ToString();
  85. }
  86. }
  87. }