HexUIRevisionCapture.cs 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using System.IO;
  5. using UnityEditor;
  6. using UnityEngine;
  7. namespace HexaCrazy.Editor
  8. {
  9. public static class HexUIRevisionCapture
  10. {
  11. static string Folder=>Path.GetFullPath("output/qa/ui-v2");
  12. [MenuItem("Hexa Crazy/Capture UI Revision (Play Mode)")]
  13. public static void Capture()
  14. {
  15. if(!EditorApplication.isPlaying)throw new System.InvalidOperationException("Enter Play Mode first.");
  16. var app=Object.FindAnyObjectByType<HexGameApp>();app.StartCoroutine(Run(app));
  17. }
  18. static IEnumerator Shot(string name)
  19. {
  20. yield return new WaitForSecondsRealtime(.5f);yield return new WaitForEndOfFrame();
  21. ScreenCapture.CaptureScreenshot(Path.Combine(Folder,name+".png"));yield return new WaitForSecondsRealtime(.2f);
  22. }
  23. static IEnumerator Run(HexGameApp app)
  24. {
  25. Directory.CreateDirectory(Folder);Directory.CreateDirectory(Path.Combine(Folder,"frames"));
  26. HexProjectBuilder.SetGameView(750,1334);app.UseReviewProfile(Path.Combine(Folder,"review-profile.json"));app.Profile.Reset();
  27. app.Profile.Data.reduceMotion=true;app.Profile.Data.music=false;app.Profile.Data.sound=false;
  28. app.GetComponent<HexAudio>().Music=false;app.GetComponent<HexAudio>().Sound=false;
  29. app.SetMode(2);yield return Shot("lobby");app.PreviewApprovedGameplay();yield return Shot("game");
  30. app.OpenPanel("shop");yield return Shot("shop");app.ClosePanel();
  31. app.OpenPanel("draw");yield return Shot("draw");app.ClosePanel();
  32. app.StartLevel(2,20,true);yield return Shot("max-board");
  33. HexProjectBuilder.SetGameView(1125,2436);app.SetMode(2);yield return Shot("long-lobby");app.PreviewApprovedGameplay();yield return Shot("long-game");
  34. HexProjectBuilder.SetGameView(750,1334);app.SetMode(0);yield return new WaitForSecondsRealtime(.4f);app.Profile.Data.reduceMotion=false;
  35. var times=new List<string>();int frame=0;
  36. for(int step=0;step<3;step++)
  37. {
  38. app.SetMode((step+1)%3);float until=Time.realtimeSinceStartup+1;
  39. while(Time.realtimeSinceStartup<until)
  40. {
  41. yield return new WaitForEndOfFrame();var texture=ScreenCapture.CaptureScreenshotAsTexture();
  42. times.Add(Time.realtimeSinceStartup.ToString("F5",CultureInfo.InvariantCulture));
  43. File.WriteAllBytes(Path.Combine(Folder,"frames",frame.ToString("D4")+".jpg"),texture.EncodeToJPG(88));Object.Destroy(texture);frame++;
  44. yield return new WaitForSecondsRealtime(.025f);
  45. }
  46. }
  47. File.WriteAllLines(Path.Combine(Folder,"frame-times.txt"),times);File.WriteAllText(Path.Combine(Folder,"capture-complete.txt"),System.DateTimeOffset.UtcNow.ToString("O"));
  48. Debug.Log("HEXA_UI_REVISION_CAPTURE_COMPLETE");
  49. }
  50. }
  51. }