GameplayContentLayout.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. namespace DevilLink2.UI
  4. {
  5. // Fixed safe rectangles measured against UI11B artwork; owns no data, events or animation.
  6. public static class GameplayContentLayout
  7. {
  8. public static void Apply(GameHUD hud)
  9. {
  10. var panel=hud.transform.Find("HUDPanel");
  11. if(panel.Find("ContentRoot"))return;
  12. var content=UIBuilder.Rect("ContentRoot",panel,24,16,358,122);
  13. Place(hud.TimerLabel.transform,content,0,0,358,38);
  14. Place(hud.TimeFill.transform.parent,content,0,43,358,6);
  15. Place(hud.ScoreLabel.transform,content,0,59,178,26);
  16. Place(hud.ComboLabel.transform,content,194,59,164,26);
  17. Place(hud.PairsLabel.transform,content,0,91,178,22);
  18. Place(hud.ComboStateLabel.transform,content,194,87,164,18);
  19. Place(hud.ComboFill.transform.parent,content,194,114,164,4);
  20. // PNG682x658 inner rectangle approximately x90..592,y160..559.
  21. // Image is aspect preserved at 330/682 or 400/682, not the full panel rect.
  22. var pause=hud.Pause.transform.Find("Card");
  23. var title=pause.Find("Face/Heading");var note=pause.Find("Face/Note");
  24. var safe=UIBuilder.Rect("ContentRoot",pause,44,80,242,180);
  25. Place(title,safe,0,0,242,26);Place(note,safe,0,30,242,22);
  26. Button(hud.Pause.ResumeButton,safe,0,62,242,30);
  27. Button(hud.Pause.RestartButton,safe,0,102,242,30);
  28. Button(hud.Pause.LobbyButton,safe,0,142,242,30);
  29. var result=UIBuilder.Rect("ContentRoot",hud.Result.transform.Find("Card"),54,96,292,232);
  30. Place(hud.Result.Heading.transform,result,0,0,292,46);hud.Result.Heading.fontSize=19;
  31. Place(hud.Result.ScoreLabel.transform,result,0,48,292,46);hud.Result.ScoreLabel.fontSize=19;
  32. Place(hud.Result.RewardsLabel.transform,result,0,96,292,24);hud.Result.RewardsLabel.fontSize=12;
  33. Button(hud.Result.NextButton,result,0,128,292,28);
  34. Button(hud.Result.RetryButton,result,0,164,292,28);
  35. Button(hud.Result.LobbyButton,result,0,200,292,28);
  36. }
  37. private static void Place(Transform target,Transform parent,float x,float y,float w,float h)
  38. {target.SetParent(parent,false);UIBuilder.Place((RectTransform)target,x,y,w,h);}
  39. private static void Button(Button button,Transform parent,float x,float y,float w,float h)
  40. {
  41. Place(button.transform,parent,x,y,w,h);
  42. foreach(var image in button.GetComponentsInChildren<Image>(true))
  43. {
  44. if(image.transform==button.transform)continue;
  45. var r=image.rectTransform;r.anchorMin=Vector2.zero;r.anchorMax=Vector2.one;
  46. r.offsetMin=Vector2.one;r.offsetMax=-Vector2.one;
  47. }
  48. var text=button.GetComponentInChildren<Text>(true);UIBuilder.Place(text.rectTransform,4,0,w-8,h);
  49. }
  50. }
  51. }