SceneManagerScenePane.cs 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. using UnityEngine;
  2. namespace COM3D2.MeidoPhotoStudio.Plugin
  3. {
  4. public class SceneManagerScenePane : BasePane
  5. {
  6. public static readonly float thumbnailScale = 0.55f;
  7. private readonly SceneManager sceneManager;
  8. private readonly SceneModalWindow sceneModalWindow;
  9. private readonly Button addSceneButton;
  10. private Vector2 sceneScrollPos;
  11. public SceneManagerScenePane(SceneManager sceneManager, SceneModalWindow sceneModalWindow)
  12. {
  13. this.sceneManager = sceneManager;
  14. this.sceneModalWindow = sceneModalWindow;
  15. addSceneButton = new Button("+");
  16. addSceneButton.ControlEvent += (s, a) => sceneManager.SaveScene(overwrite: false);
  17. }
  18. public override void Draw()
  19. {
  20. GUIStyle sceneImageStyle = new GUIStyle(GUI.skin.label)
  21. {
  22. alignment = TextAnchor.MiddleCenter,
  23. padding = new RectOffset(0, 0, 0, 0)
  24. };
  25. GUIStyle addSceneStyle = new GUIStyle(GUI.skin.button)
  26. {
  27. alignment = TextAnchor.MiddleCenter,
  28. fontSize = 60
  29. };
  30. GUILayout.BeginVertical();
  31. float sceneWidth = SceneManager.sceneDimensions.x * thumbnailScale;
  32. float sceneHeight = SceneManager.sceneDimensions.y * thumbnailScale;
  33. float sceneGridWidth = parent.WindowRect.width - SceneManagerDirectoryPane.listWidth;
  34. GUILayoutOption[] sceneLayoutOptions = new[] { GUILayout.Height(sceneHeight), GUILayout.Width(sceneWidth) };
  35. int columns = Mathf.Max(1, (int)(sceneGridWidth / sceneWidth));
  36. int rows = (int)Mathf.Ceil(sceneManager.SceneList.Count + (1 / (float)columns));
  37. sceneScrollPos = GUILayout.BeginScrollView(sceneScrollPos);
  38. GUILayout.BeginHorizontal();
  39. GUILayout.FlexibleSpace();
  40. GUILayout.BeginVertical();
  41. int currentScene = -1;
  42. for (int i = 0; i < rows; i++)
  43. {
  44. GUILayout.BeginHorizontal();
  45. for (int j = 0; j < columns; j++, currentScene++)
  46. {
  47. if (currentScene == -1)
  48. {
  49. addSceneButton.Draw(addSceneStyle, sceneLayoutOptions);
  50. }
  51. else if (currentScene < sceneManager.SceneList.Count)
  52. {
  53. var scene = sceneManager.SceneList[currentScene];
  54. if (GUILayout.Button(scene.Thumbnail, sceneImageStyle, sceneLayoutOptions))
  55. {
  56. sceneManager.SelectScene(currentScene);
  57. sceneModalWindow.ShowSceneDialogue();
  58. }
  59. }
  60. }
  61. GUILayout.EndHorizontal();
  62. }
  63. GUILayout.EndVertical();
  64. GUILayout.FlexibleSpace();
  65. GUILayout.EndHorizontal();
  66. GUILayout.EndScrollView();
  67. GUILayout.EndVertical();
  68. }
  69. }
  70. }