SceneManagerScenePane.cs 3.0 KB

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