CustomViewWindow.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using wf;
  5. namespace SceneEditWindow
  6. {
  7. [AddComponentMenu("SceneEditWindow/CustomViewWindow")]
  8. public class CustomViewWindow : BasePhotoWindow
  9. {
  10. public List<CustomViewItem> itemList { get; private set; }
  11. public override string windowName
  12. {
  13. get
  14. {
  15. return "CustomViewWindow";
  16. }
  17. }
  18. public override void Awake()
  19. {
  20. base.Awake();
  21. CustomViewItemData.Create();
  22. UIWFTabButton[] componentsInChildren = this.tabPanel.GetComponentsInChildren<UIWFTabButton>();
  23. foreach (UIWFTabButton uiwftabButton in componentsInChildren)
  24. {
  25. EventDelegate.Add(uiwftabButton.onSelect, new EventDelegate.Callback(this.OnClickSelectCategory));
  26. }
  27. this.tabPanel.UpdateChildren();
  28. }
  29. private void OnDestroy()
  30. {
  31. foreach (KeyValuePair<string, Texture2D> keyValuePair in this.texDic)
  32. {
  33. UnityEngine.Object.DestroyImmediate(keyValuePair.Value);
  34. }
  35. this.texDic.Clear();
  36. }
  37. public void Create()
  38. {
  39. if (this.itemList != null)
  40. {
  41. return;
  42. }
  43. this.itemList = new List<CustomViewItem>();
  44. HashSet<MPN> hashSet = new HashSet<MPN>();
  45. foreach (SceneEdit.SCategory scategory in this.sceneEdit.CategoryList)
  46. {
  47. foreach (SceneEdit.SPartsType spartsType in scategory.m_listPartsType)
  48. {
  49. hashSet.Add(spartsType.m_mpn);
  50. foreach (SceneEdit.SMenuItem smenuItem in spartsType.m_listMenu)
  51. {
  52. hashSet.Add(smenuItem.m_mpn);
  53. if (smenuItem.m_eColorSetMPN != MPN.null_mpn)
  54. {
  55. hashSet.Add(smenuItem.m_eColorSetMPN);
  56. }
  57. }
  58. }
  59. }
  60. foreach (CustomViewItemData.ItemData itemData in CustomViewItemData.itemList)
  61. {
  62. if (hashSet.Contains(itemData.mpn) && (!itemData.requestNewFace || PluginData.IsEnabled("GP001")))
  63. {
  64. if (!this.texDic.ContainsKey(itemData.iconTexName))
  65. {
  66. this.texDic.Add(itemData.iconTexName, ImportCM.CreateTexture(itemData.iconTexName));
  67. }
  68. CustomViewItem componentInChildren = Utility.CreatePrefab(this.pageItemGrits[itemData.page].gameObject, "SceneEdit/WindowParts/CustomItem", true).GetComponentInChildren<CustomViewItem>();
  69. componentInChildren.sceneEdit = this.sceneEdit;
  70. componentInChildren.mpn = itemData.mpn;
  71. componentInChildren.requestNewFace = itemData.requestNewFace;
  72. componentInChildren.defaultIconTexture = this.texDic[itemData.iconTexName];
  73. componentInChildren.GetComponentInChildren<UIWidget>().depth = 15;
  74. this.itemList.Add(componentInChildren);
  75. }
  76. }
  77. foreach (UIGrid grid in this.pageItemGrits)
  78. {
  79. Utility.ResetNGUI(grid);
  80. }
  81. this.UpdateAllItem();
  82. this.tabPanel.Select(this.tabPanel.GetComponentInChildren<UIWFTabButton>());
  83. this.UpdateChildren();
  84. }
  85. public bool UpdateAllItem()
  86. {
  87. bool flag = false;
  88. foreach (CustomViewItem customViewItem in this.itemList)
  89. {
  90. flag |= customViewItem.UpdateIcon(null);
  91. }
  92. return flag;
  93. }
  94. private void OnClickSelectCategory()
  95. {
  96. if (!UIWFSelectButton.selected)
  97. {
  98. return;
  99. }
  100. UIWFTabButton[] componentsInChildren = this.tabPanel.GetComponentsInChildren<UIWFTabButton>();
  101. for (int i = 0; i < componentsInChildren.Length; i++)
  102. {
  103. if (componentsInChildren[i] == UIWFSelectButton.current)
  104. {
  105. for (int j = 0; j < this.pageItemGrits.Length; j++)
  106. {
  107. this.pageItemGrits[j].transform.localScale = ((j != i) ? Vector3.zero : Vector3.one);
  108. }
  109. break;
  110. }
  111. }
  112. }
  113. [SerializeField]
  114. public SceneEdit sceneEdit;
  115. [SerializeField]
  116. private UIWFTabPanel tabPanel;
  117. [SerializeField]
  118. private UIGrid[] pageItemGrits;
  119. private Dictionary<string, Texture2D> texDic = new Dictionary<string, Texture2D>();
  120. }
  121. }