ScenePresetWindow.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. using System;
  2. using UnityEngine;
  3. using wf;
  4. public class ScenePresetWindow : BaseMaidPhotoWindow
  5. {
  6. public override void Awake()
  7. {
  8. base.Awake();
  9. PhotoScenePreset.Create();
  10. }
  11. public override void Start()
  12. {
  13. base.Start();
  14. this.Init();
  15. }
  16. public void Init()
  17. {
  18. for (int i = 0; i < PhotoScenePreset.datas.Count; i++)
  19. {
  20. this.CreateScenePresetButton(this.contentGrid.gameObject, PhotoScenePreset.datas[i]);
  21. }
  22. Utility.ResetNGUI(this.contentGrid);
  23. Utility.ResetNGUI(NGUITools.FindInParents<UIScrollView>(this.contentGrid.transform));
  24. this.UpdateChildren();
  25. }
  26. public override void OnDeserializeEvent()
  27. {
  28. ScenePresetWindow.SelectData = null;
  29. }
  30. public GameObject CreateScenePresetButton(GameObject parentObject, PhotoScenePreset.Data data)
  31. {
  32. GameObject gameObject = Utility.CreatePrefab(parentObject, "ScenePhotoMode/ScenePresetButton", true);
  33. gameObject.name = data.id.ToString();
  34. UI2DSprite component = UTY.GetChildObject(gameObject, "Plate/Plate/BG/ThumImage", false).GetComponent<UI2DSprite>();
  35. if (!string.IsNullOrEmpty(data.thumbnailName))
  36. {
  37. Texture2D texture2D = ImportCM.CreateTexture(data.thumbnailName + ".tex");
  38. Sprite sprite2D = Sprite.Create(texture2D, new Rect(0f, 0f, (float)texture2D.width, (float)texture2D.height), default(Vector2));
  39. if (component.sprite2D != null && component.sprite2D.texture != null)
  40. {
  41. UnityEngine.Object.DestroyImmediate(component.sprite2D.texture);
  42. }
  43. component.sprite2D = sprite2D;
  44. component.SetDimensions(texture2D.width, texture2D.height);
  45. }
  46. UIButton componentInChildren = gameObject.GetComponentInChildren<UIButton>();
  47. componentInChildren.name = data.id.ToString();
  48. EventDelegate.Add(componentInChildren.onClick, new EventDelegate.Callback(this.OnClickLoadBtn));
  49. return gameObject;
  50. }
  51. private void OnClickLoadBtn()
  52. {
  53. int id = int.Parse(UIButton.current.name);
  54. GameMain.Instance.SysDlg.Show("現在の配置情報はリセットされます。\n宜しいですか?", SystemDialog.TYPE.OK_CANCEL, delegate
  55. {
  56. GameMain.Instance.SysDlg.Close();
  57. this.Load(id);
  58. }, null);
  59. }
  60. private void Load(int id)
  61. {
  62. foreach (PhotoScenePreset.Data data in PhotoScenePreset.datas)
  63. {
  64. if (data.id == id)
  65. {
  66. byte[] array = null;
  67. using (AFileBase afileBase = GameUty.FileSystem.FileOpen(data.loadFileName))
  68. {
  69. array = afileBase.ReadAll();
  70. }
  71. if (array != null)
  72. {
  73. ScenePresetWindow.SelectData = data;
  74. base.mgr.SaveAndLoadManager.ReadSave(array);
  75. }
  76. break;
  77. }
  78. }
  79. }
  80. [HideInInspector]
  81. public static PhotoScenePreset.Data SelectData;
  82. [SerializeField]
  83. private UIGrid contentGrid;
  84. }