PhotographDataManager.cs 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. using System.Collections.Generic;
  2. using FairyGUI;
  3. using UI.DressUp;
  4. using UnityEngine;
  5. namespace GFGGame
  6. {
  7. public enum EnumPhotographType
  8. {
  9. BG,
  10. NPC,
  11. SCENE,
  12. BORDER,
  13. EFFECT
  14. }
  15. public class PhotographDataManager : SingletonBase<PhotographDataManager>
  16. {
  17. public List<int> _equipRoleData = new List<int>();//当前穿戴的角色数据
  18. public Dictionary<int, List<int>> _equipSceneData = new Dictionary<int, List<int>>();//当前穿戴的场景数据
  19. public List<int> listBgData = new List<int>();
  20. public List<int> listNpcData = new List<int>();
  21. public List<int> listSceneData = new List<int>();
  22. public List<int> listBorderData = new List<int>();
  23. public List<int> listEffectData = new List<int>();
  24. public void Clear()
  25. {
  26. listBgData.Clear();
  27. listNpcData.Clear();
  28. listSceneData.Clear();
  29. listBorderData.Clear();
  30. listEffectData.Clear();
  31. }
  32. public void Add(int itemID)
  33. {
  34. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemID);
  35. if (itemCfg.itemType == ConstItemType.DRESS_UP)
  36. {
  37. if (itemCfg.subType == ConstDressUpItemType.BEI_JING)
  38. {
  39. if (listBgData.IndexOf(itemID) < 0) listBgData.Add(itemID);
  40. }
  41. else if (itemCfg.subType == ConstDressUpItemType.QIAN_JING || itemCfg.subType == ConstDressUpItemType.BEI_SHI || itemCfg.subType == ConstDressUpItemType.HUAN_JING)
  42. {
  43. if (listSceneData.IndexOf(itemID) < 0) listSceneData.Add(itemID);
  44. }
  45. }
  46. else if (itemCfg.itemType == ConstItemType.ITEM)
  47. {
  48. if (itemCfg.subType == ConstItemSubType.NPC)
  49. {
  50. if (listNpcData.IndexOf(itemID) < 0) listNpcData.Add(itemID);
  51. }
  52. else if (itemCfg.subType == ConstItemSubType.BOREDR)
  53. {
  54. if (listBorderData.IndexOf(itemID) < 0) listBorderData.Add(itemID);
  55. }
  56. else if (itemCfg.subType == ConstItemSubType.EFFECT)
  57. {
  58. if (listEffectData.IndexOf(itemID) < 0) listEffectData.Add(itemID);
  59. }
  60. }
  61. }
  62. //将穿戴数据分类
  63. public void ClassifyEquipData()
  64. {
  65. _equipRoleData.Clear();
  66. _equipSceneData.Clear();
  67. for (int i = 0; i < EquipDataCache.cacher.equipDatas.Length; i++)
  68. {
  69. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(EquipDataCache.cacher.equipDatas[i]);
  70. if (itemCfg.subType == ConstDressUpItemType.QIAN_JING || itemCfg.subType == ConstDressUpItemType.BEI_SHI || itemCfg.subType == ConstDressUpItemType.HUAN_JING || itemCfg.subType == ConstDressUpItemType.FEN_WEI)
  71. {
  72. PhotographDataManager.Instance.AddEquipItem(_equipSceneData, itemCfg.id, out _equipSceneData);
  73. }
  74. else
  75. {
  76. _equipRoleData.Add(EquipDataCache.cacher.equipDatas[i]);
  77. }
  78. }
  79. }
  80. public void AddEquipItem(Dictionary<int, List<int>> _equipSceneData, int itemID, out Dictionary<int, List<int>> equipSceneData)
  81. {
  82. if (!_equipSceneData.ContainsKey(itemID))
  83. {
  84. _equipSceneData.Add(itemID, new List<int>());
  85. }
  86. _equipSceneData[itemID].Add(itemID);
  87. equipSceneData = _equipSceneData;
  88. }
  89. public List<int> GetListData(EnumPhotographType index)
  90. {
  91. List<int> _listData = null;
  92. switch (index)
  93. {
  94. case EnumPhotographType.BG:
  95. _listData = PhotographDataManager.Instance.listBgData;
  96. break;
  97. case EnumPhotographType.NPC:
  98. _listData = PhotographDataManager.Instance.listNpcData;
  99. break;
  100. case EnumPhotographType.SCENE:
  101. _listData = PhotographDataManager.Instance.listSceneData;
  102. break;
  103. case EnumPhotographType.BORDER:
  104. _listData = PhotographDataManager.Instance.listBorderData;
  105. break;
  106. case EnumPhotographType.EFFECT:
  107. _listData = PhotographDataManager.Instance.listEffectData;
  108. break;
  109. }
  110. return _listData;
  111. }
  112. //是否点击在UI上
  113. public bool IsTouchUI(GComponent viewCom)
  114. {
  115. GObject obj = GRoot.inst.touchTarget;
  116. UI_PhotographUI _viewCom = UI_PhotographUI.Proxy(viewCom);
  117. return _viewCom.m_comSelectBox.m_btnSize.GetChild("icon").asLoader == obj || _viewCom.m_comSelectBox.m_btnDelete.GetChild("icon").asLoader == obj || _viewCom.m_comSelectBox.m_btnFlip.GetChild("icon").asLoader == obj || _viewCom.m_btnBack == obj || _viewCom.m_btnChoose.GetChild("icon").asLoader == obj || _viewCom.m_btnPhotograph.GetChild("icon").asLoader == obj || _viewCom.m_btnUp.GetChild("icon").asLoader == obj || _viewCom.m_btnDown.GetChild("icon").asLoader == obj;
  118. }
  119. public void SetLayer(GameObject parentObj, int layer, string state)
  120. {
  121. int count = 0;
  122. if (state == "up")
  123. {
  124. count = layer - GetMinLayer(parentObj);
  125. }
  126. else if (state == "down")
  127. {
  128. count = layer - GetMaxLayer(parentObj);
  129. }
  130. int maxLayer = int.MinValue;
  131. SpriteRenderer[] sps = parentObj.GetComponentsInChildren<SpriteRenderer>();
  132. for (int i = 0; i < sps.Length; i++)
  133. {
  134. sps[i].sortingOrder = sps[i].sortingOrder + layer + count;
  135. if (maxLayer < sps[i].sortingOrder)
  136. {
  137. maxLayer = sps[i].sortingOrder;
  138. }
  139. }
  140. for (int i = 0; i < parentObj.transform.childCount; i++)
  141. {
  142. Transform tf = parentObj.transform.GetChild(i);
  143. string[] strs = tf.name.Split('_');
  144. if (strs.Length > 1 && strs[1] == "eff")//子物体是特效
  145. {
  146. DressUpUtil.SetParticleSortingOrder(tf.gameObject, maxLayer);
  147. }
  148. }
  149. }
  150. private int GetMaxLayer(GameObject parentObj)
  151. {
  152. int layer = int.MinValue;
  153. for (int i = 0; i < parentObj.transform.childCount; i++)
  154. {
  155. Transform tf = parentObj.transform.GetChild(i);
  156. SpriteRenderer sp = tf.GetComponent<SpriteRenderer>();
  157. if (sp && layer < sp.sortingOrder)
  158. {
  159. layer = sp.sortingOrder;
  160. }
  161. }
  162. return layer;
  163. }
  164. public int GetMinLayer(GameObject parentObj)
  165. {
  166. int layer = int.MaxValue;
  167. for (int i = 0; i < parentObj.transform.childCount; i++)
  168. {
  169. Transform tf = parentObj.transform.GetChild(i);
  170. SpriteRenderer sp = tf.GetComponent<SpriteRenderer>();
  171. if (sp && sp.sortingOrder < layer)
  172. {
  173. layer = sp.sortingOrder;
  174. }
  175. }
  176. return layer;
  177. }
  178. public void SetBgPos(GameObject hitGameObj, Vector2 uiSize)
  179. {
  180. Vector2 size = hitGameObj.GetComponent<SpriteRenderer>().size;
  181. float deviationWidth = (size.x - uiSize.x / 100) / 2;
  182. float deviationHeigh = (size.y - uiSize.y / 100) / 2;
  183. Vector2 pos = hitGameObj.transform.position;
  184. if (pos.x <= -deviationWidth)
  185. {
  186. hitGameObj.transform.position = new Vector2(-deviationWidth, hitGameObj.transform.position.y);
  187. }
  188. if (pos.x >= deviationWidth)
  189. {
  190. hitGameObj.transform.position = new Vector2(deviationWidth, hitGameObj.transform.position.y);
  191. }
  192. if (pos.y <= -deviationHeigh)
  193. {
  194. hitGameObj.transform.position = new Vector2(hitGameObj.transform.position.x, -deviationHeigh);
  195. }
  196. if (pos.y >= deviationHeigh)
  197. {
  198. hitGameObj.transform.position = new Vector2(hitGameObj.transform.position.x, deviationHeigh);
  199. }
  200. }
  201. }
  202. }