CustomViewWindow.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. bool flag = hashSet.Contains(MPN.eyewhite);
  61. foreach (CustomViewItemData.ItemData itemData in CustomViewItemData.itemList)
  62. {
  63. if (hashSet.Contains(itemData.mpn) && (!itemData.requestNewFace || PluginData.IsEnabled("GP001")))
  64. {
  65. if (!this.texDic.ContainsKey(itemData.iconTexName))
  66. {
  67. this.texDic.Add(itemData.iconTexName, ImportCM.CreateTexture(itemData.iconTexName));
  68. }
  69. CustomViewItem componentInChildren = Utility.CreatePrefab(this.pageItemGrits[itemData.page].gameObject, "SceneEdit/WindowParts/CustomItem", true).GetComponentInChildren<CustomViewItem>();
  70. componentInChildren.sceneEdit = this.sceneEdit;
  71. componentInChildren.mpn = itemData.mpn;
  72. componentInChildren.requestNewFace = itemData.requestNewFace;
  73. componentInChildren.defaultIconTexture = this.texDic[itemData.iconTexName];
  74. componentInChildren.GetComponentInChildren<UIWidget>().depth = 15;
  75. this.itemList.Add(componentInChildren);
  76. }
  77. }
  78. foreach (UIGrid grid in this.pageItemGrits)
  79. {
  80. Utility.ResetNGUI(grid);
  81. }
  82. this.UpdateAllItem();
  83. this.tabPanel.Select(this.tabPanel.GetComponentInChildren<UIWFTabButton>());
  84. this.UpdateChildren();
  85. }
  86. public bool UpdateAllItem()
  87. {
  88. bool flag = false;
  89. foreach (CustomViewItem customViewItem in this.itemList)
  90. {
  91. flag |= customViewItem.UpdateIcon(null);
  92. }
  93. return flag;
  94. }
  95. private void OnClickSelectCategory()
  96. {
  97. if (!UIWFSelectButton.selected)
  98. {
  99. return;
  100. }
  101. UIWFTabButton[] componentsInChildren = this.tabPanel.GetComponentsInChildren<UIWFTabButton>();
  102. for (int i = 0; i < componentsInChildren.Length; i++)
  103. {
  104. if (componentsInChildren[i] == UIWFSelectButton.current)
  105. {
  106. for (int j = 0; j < this.pageItemGrits.Length; j++)
  107. {
  108. this.pageItemGrits[j].transform.localScale = ((j != i) ? Vector3.zero : Vector3.one);
  109. }
  110. break;
  111. }
  112. }
  113. }
  114. [SerializeField]
  115. public SceneEdit sceneEdit;
  116. [SerializeField]
  117. private UIWFTabPanel tabPanel;
  118. [SerializeField]
  119. private UIGrid[] pageItemGrits;
  120. private Dictionary<string, Texture2D> texDic = new Dictionary<string, Texture2D>();
  121. }
  122. }