CustomViewWindow.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 override string windowName
  11. {
  12. get
  13. {
  14. return "CustomViewWindow";
  15. }
  16. }
  17. public override void Awake()
  18. {
  19. base.Awake();
  20. CustomViewItemData.Create();
  21. UIWFTabButton[] componentsInChildren = this.tabPanel.GetComponentsInChildren<UIWFTabButton>();
  22. foreach (UIWFTabButton uiwftabButton in componentsInChildren)
  23. {
  24. EventDelegate.Add(uiwftabButton.onSelect, new EventDelegate.Callback(this.OnClickSelectCategory));
  25. }
  26. this.tabPanel.UpdateChildren();
  27. }
  28. private void OnDestroy()
  29. {
  30. foreach (KeyValuePair<string, Texture2D> keyValuePair in this.texDic)
  31. {
  32. UnityEngine.Object.DestroyImmediate(keyValuePair.Value);
  33. }
  34. this.texDic.Clear();
  35. }
  36. public void Create()
  37. {
  38. if (this.itemList.Count != 0)
  39. {
  40. return;
  41. }
  42. foreach (CustomViewItemData.ItemData itemData in CustomViewItemData.itemList)
  43. {
  44. if (!this.texDic.ContainsKey(itemData.iconTexName))
  45. {
  46. this.texDic.Add(itemData.iconTexName, ImportCM.CreateTexture(itemData.iconTexName));
  47. }
  48. CustomViewItem componentInChildren = Utility.CreatePrefab(this.pageItemGrits[itemData.page].gameObject, "SceneEdit/WindowParts/CustomItem", true).GetComponentInChildren<CustomViewItem>();
  49. componentInChildren.sceneEdit = this.sceneEdit;
  50. componentInChildren.mpn = itemData.mpn;
  51. componentInChildren.defaultIconTexture = this.texDic[itemData.iconTexName];
  52. componentInChildren.GetComponentInChildren<UIWidget>().depth = 15;
  53. this.itemList.Add(componentInChildren);
  54. }
  55. foreach (UIGrid grid in this.pageItemGrits)
  56. {
  57. Utility.ResetNGUI(grid);
  58. }
  59. this.UpdateAllItem();
  60. this.tabPanel.Select(this.tabPanel.GetComponentInChildren<UIWFTabButton>());
  61. this.UpdateChildren();
  62. }
  63. public bool UpdateAllItem()
  64. {
  65. bool flag = false;
  66. foreach (CustomViewItem customViewItem in this.itemList)
  67. {
  68. flag |= customViewItem.UpdateIcon(null);
  69. }
  70. return flag;
  71. }
  72. private void OnClickSelectCategory()
  73. {
  74. if (!UIWFSelectButton.selected)
  75. {
  76. return;
  77. }
  78. UIWFTabButton[] componentsInChildren = this.tabPanel.GetComponentsInChildren<UIWFTabButton>();
  79. for (int i = 0; i < componentsInChildren.Length; i++)
  80. {
  81. if (componentsInChildren[i] == UIWFSelectButton.current)
  82. {
  83. for (int j = 0; j < this.pageItemGrits.Length; j++)
  84. {
  85. this.pageItemGrits[j].transform.localScale = ((j != i) ? Vector3.zero : Vector3.one);
  86. }
  87. break;
  88. }
  89. }
  90. }
  91. [SerializeField]
  92. public SceneEdit sceneEdit;
  93. [SerializeField]
  94. private UIWFTabPanel tabPanel;
  95. [SerializeField]
  96. private UIGrid[] pageItemGrits;
  97. private List<CustomViewItem> itemList = new List<CustomViewItem>();
  98. private Dictionary<string, Texture2D> texDic = new Dictionary<string, Texture2D>();
  99. }
  100. }