| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- using System;
- using System.IO;
- using System.Linq;
- using System.Collections;
- using System.Collections.Generic;
- using System.Text;
- using TMPro;
- using UnityEditor;
- using UnityEngine;
- using UnityEngine.EventSystems;
- using UnityEngine.UI;
- namespace Olympus.Editor
- {
- public static class IndependentUiAudit
- {
- const string Root="Assets/Olympus/Resources/Olympus/";
- public static string Status {get;private set;}="Not started";
- public static string Dependencies()
- {
- var report=new StringBuilder();
- foreach(string name in new[]{"Lobby","Trial","Start","Checkin","Settings","Shop","Leaderboard","Loading","Result","General"})
- {
- string path=Root+(name=="Lobby"||name=="Trial"?"ReferenceA/":"Suite/")+name+".prefab";
- var prefab=AssetDatabase.LoadAssetAtPath<GameObject>(path);if(!prefab)throw new Exception("Missing "+path);
- foreach(string dep in AssetDatabase.GetDependencies(path,true))
- {
- if(!dep.EndsWith(".png",StringComparison.OrdinalIgnoreCase))continue;
- 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);
- }
- foreach(var i in prefab.GetComponentsInChildren<Image>(true))
- {
- if(!i.sprite)continue;var r=i.sprite.rect;var t=i.sprite.texture;
- bool independentTrim=AssetDatabase.GetAssetPath(i.sprite).StartsWith(Root+"Elements/v3_")&&AssetDatabase.LoadAllAssetsAtPath(AssetDatabase.GetAssetPath(i.sprite)).OfType<Sprite>().Count()==1;
- 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);
- }
- foreach(var glyph in prefab.GetComponentsInChildren<TempleGlyph>(true))if(!glyph.GetComponent<CanvasRenderer>())throw new Exception("Missing glyph renderer");
- report.AppendLine("PASS "+name+": independent images only (v3 excludes exterior transparent padding), native TMP labels, no mockup/screen-plate dependencies");
- }
- Directory.CreateDirectory("docs/验证");File.WriteAllText("docs/验证/独立UI资源依赖.txt",report.ToString());return report.ToString();
- }
- public static string StartCapture(string output="IndependentUI")
- {
- var app=UnityEngine.Object.FindFirstObjectByType<OlympusGame>();if(!Application.isPlaying||!app||!app.IsEditorPreviewSave)throw new Exception("Use isolated Art Review save");
- app.StartCoroutine(Capture(app,output));return Status="Capturing independent UI pages";
- }
- static IEnumerator Capture(OlympusGame app,string output)
- {
- var report=new StringBuilder();string folder="docs/运行截图/"+output;Directory.CreateDirectory(folder);
- foreach(string name in new[]{"Start","Lobby","Trial","Checkin","Settings","Shop","Leaderboard","Loading","Result"})
- {
- Status="Capturing "+name;app.ShowDesignPage(name);yield return null;yield return null;yield return new WaitForSecondsRealtime(.25f);Canvas.ForceUpdateCanvases();
- var root=app.GetComponentsInChildren<SuiteView>().LastOrDefault();Transform page=root?root.transform:app.GetComponentInChildren<ReferenceAView>().transform;
- foreach(var t in page.GetComponentsInChildren<TextMeshProUGUI>()){t.ForceMeshUpdate();if(t.isTextOverflowing)report.AppendLine("CHECK text overflow "+name+"/"+t.name);}
- foreach(var b in page.GetComponentsInChildren<Button>())
- {
- 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);
- if(hits.Count==0||hits[0].gameObject.GetComponentInParent<Button>()!=b)report.AppendLine("CHECK hit "+name+"/"+b.name);
- }
- ScreenCapture.CaptureScreenshot(folder+"/"+name+".png");report.AppendLine("CAPTURE "+name+" at "+Screen.width+"x"+Screen.height);yield return null;yield return null;
- }
- ManualContinueAudit.FeedbackPreview("correct");yield return null;yield return null;ScreenCapture.CaptureScreenshot(folder+"/AnswerFeedback.png");yield return null;yield return null;
- WeeklyAndPoolAudit.IntermissionPreview();yield return null;yield return null;ScreenCapture.CaptureScreenshot(folder+"/Intermission.png");yield return null;yield return null;
- app.ShowDesignPage("Lobby");File.WriteAllText("docs/验证/"+output+"页面检查.txt",report.ToString());Status=report.ToString();
- }
- public static string CaptureExtras()
- {
- var app=UnityEngine.Object.FindFirstObjectByType<OlympusGame>();if(!Application.isPlaying||!app||!app.IsEditorPreviewSave)throw new Exception("Use isolated Art Review save");
- app.StartCoroutine(Extras(app));return Status="Capturing profile, instructions, records and menu";
- }
- static IEnumerator Extras(OlympusGame app)
- {
- var report=new StringBuilder();
- foreach(var name in new[]{"Profile","How to","Coin records","Menu"})
- {
- app.ShowDesignPage(name);yield return null;yield return null;yield return new WaitForSecondsRealtime(.25f);Canvas.ForceUpdateCanvases();
- var view=app.GetComponentsInChildren<SuiteView>().Last();
- foreach(var image in view.GetComponentsInChildren<Image>())
- {
- if(!image.sprite)continue;
- if(image.type==Image.Type.Simple&&!image.preserveAspect)throw new Exception("Stretch in "+name+"/"+image.name);
- }
- 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;
- }
- app.ShowDesignPage("Lobby");File.WriteAllText("docs/验证/通用页面比例检查.txt",report.ToString());Status=report.ToString();
- }
- }
- }
|