TextureSelectSubWindow.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using UnityEngine;
  5. using wf;
  6. public class TextureSelectSubWindow : BasePhotoSubWindow
  7. {
  8. public static string folder_path
  9. {
  10. get
  11. {
  12. string text = PhotoWindowManager.path_photo_folder + "Texture";
  13. if (!Directory.Exists(text))
  14. {
  15. Directory.CreateDirectory(text);
  16. }
  17. return text;
  18. }
  19. }
  20. public void Awake()
  21. {
  22. }
  23. public override void Initizalize(BasePhotoWindow parentWindow)
  24. {
  25. this.Awake();
  26. base.Initizalize(parentWindow);
  27. this.ReLoad();
  28. }
  29. public void ReLoad()
  30. {
  31. List<Transform> childList = this.gridObject.GetChildList();
  32. for (int i = 0; i < childList.Count; i++)
  33. {
  34. UnityEngine.Object.DestroyImmediate(childList[i].gameObject);
  35. }
  36. this.imageFilePaths.Clear();
  37. if (Directory.Exists(TextureSelectSubWindow.folder_path))
  38. {
  39. List<string> list = new List<string>();
  40. foreach (string searchPattern in new string[]
  41. {
  42. "*.png",
  43. "*jpg"
  44. })
  45. {
  46. list.AddRange(Directory.GetFiles(TextureSelectSubWindow.folder_path, searchPattern));
  47. }
  48. foreach (string text in list)
  49. {
  50. Sprite sprite = Utility.CreateTextureSpriteFromImageFile(text);
  51. if (!(sprite == null))
  52. {
  53. GameObject gameObject = Utility.CreatePrefab(this.gridObject.gameObject, "ScenePhotoMode/TexSelectBtn", true);
  54. UI2DSprite componentInChildren = gameObject.GetComponentInChildren<UI2DSprite>();
  55. componentInChildren.sprite2D = sprite;
  56. UIButton componentInChildren2 = gameObject.GetComponentInChildren<UIButton>();
  57. EventDelegate.Add(componentInChildren2.onClick, new EventDelegate.Callback(this.OnClickItem));
  58. UIEventTrigger componentInChildren3 = gameObject.GetComponentInChildren<UIEventTrigger>();
  59. componentInChildren3.onPress = this.copyEventTrigger.onPress;
  60. this.imageFilePaths.Add(componentInChildren2, text);
  61. }
  62. }
  63. }
  64. this.warningTextObject.SetActive(this.imageFilePaths.Count == 0);
  65. Utility.ResetNGUI(this.gridObject);
  66. Utility.ResetNGUI(this.gridObject.transform.parent.gameObject.GetComponent<UIScrollView>());
  67. }
  68. public void OnDestroy()
  69. {
  70. foreach (KeyValuePair<UIButton, string> keyValuePair in this.imageFilePaths)
  71. {
  72. UI2DSprite componentInChildren = keyValuePair.Key.GetComponentInChildren<UI2DSprite>();
  73. if (componentInChildren != null && componentInChildren.sprite2D != null && componentInChildren.sprite2D.texture != null)
  74. {
  75. UnityEngine.Object.Destroy(componentInChildren.sprite2D.texture);
  76. }
  77. }
  78. }
  79. private void OnClickItem()
  80. {
  81. if (UIButton.current == null || !this.imageFilePaths.ContainsKey(UIButton.current))
  82. {
  83. return;
  84. }
  85. this.objectCreateWindow.OnChangeSelectTexture(this.imageFilePaths[UIButton.current]);
  86. }
  87. public new PhotoWindowManager mgr
  88. {
  89. get
  90. {
  91. return base.mgr as PhotoWindowManager;
  92. }
  93. }
  94. [SerializeField]
  95. private ObjectCreateWindow objectCreateWindow;
  96. [SerializeField]
  97. private UIGrid gridObject;
  98. [SerializeField]
  99. private GameObject warningTextObject;
  100. [SerializeField]
  101. private UIEventTrigger copyEventTrigger;
  102. private Dictionary<UIButton, string> imageFilePaths = new Dictionary<UIButton, string>();
  103. }