SubSlotEditManager.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. using System;
  2. using UnityEngine;
  3. using wf;
  4. public class SubSlotEditManager : MonoBehaviour
  5. {
  6. public MPN targetMpn { get; private set; }
  7. public SubSlotEditItem[] sloatItems { get; private set; }
  8. public bool visible
  9. {
  10. get
  11. {
  12. return this.sloatItems != null && this.sloatItems.Length != 0 && this.sloatItems[0].gameObject == this.grid;
  13. }
  14. set
  15. {
  16. if (this.sloatItems == null || this.sloatItems.Length == 0)
  17. {
  18. return;
  19. }
  20. if (value && this.sloatItems[0].transform.parent != this.grid.transform)
  21. {
  22. foreach (SubSlotEditItem subSlotEditItem in this.sloatItems)
  23. {
  24. subSlotEditItem.transform.SetParent(this.grid.transform, false);
  25. }
  26. Utility.ResetNGUI(this.grid);
  27. }
  28. else if (!value && this.sloatItems[0].transform.parent == this.grid.transform)
  29. {
  30. foreach (SubSlotEditItem subSlotEditItem2 in this.sloatItems)
  31. {
  32. subSlotEditItem2.transform.SetParent(this.standbyObject.transform, false);
  33. }
  34. Utility.ResetNGUI(this.grid);
  35. }
  36. }
  37. }
  38. private void Awake()
  39. {
  40. this.targetMpn = MPN.null_mpn;
  41. try
  42. {
  43. this.targetMpn = (MPN)Enum.Parse(typeof(MPN), this.targetMpnName);
  44. }
  45. catch (Exception e)
  46. {
  47. NDebug.AssertParseError("MPN", e);
  48. }
  49. this.standbyObject = new GameObject();
  50. this.standbyObject.transform.SetParent(GameObject.Find("UI Root").transform, false);
  51. this.standbyObject.transform.localScale = Vector3.zero;
  52. this.standbyObject.name = "_subSlot_standbyObject_" + this.targetMpnName.ToString();
  53. }
  54. private void Start()
  55. {
  56. if (this.sloatItems == null)
  57. {
  58. this.sloatItems = new SubSlotEditItem[this.maxSlot];
  59. for (int i = 0; i < this.maxSlot; i++)
  60. {
  61. this.sloatItems[i] = this.CreateSubSloatEditItem(this.standbyObject, i);
  62. }
  63. }
  64. }
  65. private void OnDestroy()
  66. {
  67. if (this.sloatItems != null)
  68. {
  69. for (int i = 0; i < this.sloatItems.Length; i++)
  70. {
  71. if (this.sloatItems[i] != null && this.sloatItems[i].gameObject != null)
  72. {
  73. UnityEngine.Object.DestroyImmediate(this.sloatItems[i].gameObject);
  74. }
  75. }
  76. }
  77. UnityEngine.Object.DestroyImmediate(this.standbyObject);
  78. }
  79. public void SetItem(SceneEdit.SMenuItem menu)
  80. {
  81. if (menu.m_boDelOnly)
  82. {
  83. this.sceneEdit.maid.SetProp(menu.m_strCateName, menu.m_strMenuFileName, menu.m_nMenuFileRID, false, false);
  84. return;
  85. }
  86. bool flag = false;
  87. bool flag2 = false;
  88. SceneEdit.SMenuItem[] array = new SceneEdit.SMenuItem[this.maxSlot];
  89. for (int i = 0; i < this.maxSlot; i++)
  90. {
  91. if (this.sloatItems[i].menuItem == null)
  92. {
  93. flag2 = true;
  94. }
  95. else if (this.sloatItems[i].menuItem != menu)
  96. {
  97. array[i] = this.sloatItems[i].menuItem;
  98. }
  99. else
  100. {
  101. flag = true;
  102. }
  103. }
  104. if (!flag2 && !flag)
  105. {
  106. flag = true;
  107. array[array.Length - 1] = menu;
  108. }
  109. if (flag)
  110. {
  111. MaidProp prop = this.sceneEdit.maid.GetProp(menu.m_strCateName);
  112. this.sceneEdit.maid.SetProp(menu.m_strCateName, prop.strFileName, prop.nFileNameRID, false, false);
  113. int num = 0;
  114. for (int j = 0; j < array.Length; j++)
  115. {
  116. if (array[j] != null)
  117. {
  118. this.sloatItems[num++].SetItem(array[j]);
  119. }
  120. }
  121. return;
  122. }
  123. for (int k = 0; k < this.maxSlot; k++)
  124. {
  125. if (this.sloatItems[k].menuItem == null)
  126. {
  127. this.sloatItems[k].SetItem(menu);
  128. break;
  129. }
  130. }
  131. if (!flag2)
  132. {
  133. this.sloatItems[this.sloatItems.Length - 1].SetItem(menu);
  134. }
  135. }
  136. public void UpdateAllItem()
  137. {
  138. foreach (SubSlotEditItem subSlotEditItem in this.sloatItems)
  139. {
  140. subSlotEditItem.UpdateSloatInformation();
  141. }
  142. }
  143. private void OnClickItemEvent(SubSlotEditItem editItem)
  144. {
  145. MPN mpn = editItem.menuItem.m_mpn;
  146. this.SetItem(editItem.menuItem);
  147. this.sceneEdit.maid.AllProcProp();
  148. this.sceneEdit.UpdateCurrentItemPanel(false);
  149. this.sceneEdit.customViewWindow.UpdateAllItem();
  150. }
  151. private SubSlotEditItem CreateSubSloatEditItem(GameObject parentObject, int sloatNo)
  152. {
  153. GameObject gameObject = Utility.CreatePrefab(parentObject, "SceneEdit/MainMenu/Prefab/ButtonItem", true);
  154. SubSlotEditItem subSlotEditItem = gameObject.AddComponent<SubSlotEditItem>();
  155. subSlotEditItem.sceneEdit = this.sceneEdit;
  156. subSlotEditItem.targetMpn = this.targetMpn;
  157. subSlotEditItem.sloatNo = sloatNo;
  158. SubSlotEditItem subSlotEditItem2 = subSlotEditItem;
  159. subSlotEditItem2.onClickEvent = (Action<SubSlotEditItem>)Delegate.Combine(subSlotEditItem2.onClickEvent, new Action<SubSlotEditItem>(this.OnClickItemEvent));
  160. return subSlotEditItem;
  161. }
  162. [SerializeField]
  163. private SceneEdit sceneEdit;
  164. [SerializeField]
  165. private UIGrid grid;
  166. [SerializeField]
  167. public int maxSlot;
  168. [SerializeField]
  169. public string targetMpnName;
  170. private GameObject standbyObject;
  171. }