PackWindowVersionCode.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEditor;
  5. namespace Pack
  6. {
  7. public partial class PackWindow
  8. {
  9. private string[] m_CanSelectPlatforms = new string[]
  10. {
  11. BuildTarget.Android.ToString(),
  12. BuildTarget.iOS.ToString(),
  13. BuildTarget.StandaloneWindows64.ToString(),
  14. };
  15. private string[] m_SelectedPlatforms = new string[0];
  16. private string[] m_SelectedPlatformsChange = new string[0];
  17. private Dictionary<string, PackPlatformBase> m_PackPlatformMapChange = new Dictionary<string, PackPlatformBase>();
  18. private VersionCode? m_GameVersionCodeMax;
  19. private VersionCode? m_ResVersionCodeMax;
  20. private VersionCode? m_GameVersionCodeMaxChange;
  21. private VersionCode? m_ResVersionCodeMaxChange;
  22. private VersionCode? m_GameVersionCodeMin;
  23. private VersionCode? m_ResVersionCodeMin;
  24. private void DrawChangeVersionGUI()
  25. {
  26. EditorGUILayout.BeginVertical();
  27. EditorGUILayout.BeginHorizontal();
  28. Rect totalPosition = EditorGUILayout.GetControlRect(false, PackGUI.kSingleLineHeight, PackGUI.styles.popup);
  29. var id = GUIUtility.GetControlID(PackGUI.s_MutliSelectField, FocusType.Keyboard, totalPosition);
  30. Vector2 size = PackGUI.styles.label.CalcSize(EditorGUIUtility.TrTempContent("选择平台"));
  31. float labelWidth = size.x;
  32. Rect labelPosition = new Rect(totalPosition.x + PackGUI.indent, totalPosition.y, labelWidth - PackGUI.indent, PackGUI.kSingleLineHeight);
  33. Rect fieldPosition = new Rect(totalPosition.x + labelWidth, totalPosition.y, totalPosition.width - labelWidth, totalPosition.height);
  34. EditorGUI.HandlePrefixLabel(labelPosition, totalPosition, EditorGUIUtility.TrTempContent("选择平台"), id, PackGUI.styles.label);
  35. m_SelectedPlatformsChange = MutliSelectFieldGUI.DoMutliSelectFieldShowValue(fieldPosition, id, m_CanSelectPlatforms, m_SelectedPlatformsChange, null, -1, true, PackGUI.styles.popup);
  36. EditorGUILayout.EndHorizontal();
  37. if (!ArrayUtility.ArrayEquals(m_SelectedPlatforms, m_SelectedPlatformsChange))
  38. {
  39. ClearSavePlatformVersionCodeChange();
  40. ArrayUtility.AddRange(ref m_SelectedPlatforms, m_SelectedPlatformsChange);
  41. }
  42. if (m_PackPlatformUniqueIds == null || m_PackPlatformUniqueIds.Length <= 0
  43. || m_PackPlatformMap == null || m_PackPlatformMap.Count <= 0
  44. || m_SelectedPlatformsChange.Length <= 0)
  45. {
  46. GUILayout.FlexibleSpace();
  47. EditorGUILayout.LabelField(GUIContent.none, EditorGUIUtility.TrTextContentWithIcon("暂无目标平台信息", MessageType.Warning), PackGUI.styles.helpBox);
  48. GUILayout.FlexibleSpace();
  49. }
  50. else
  51. {
  52. EditorGUILayout.Space();
  53. m_ScrollPosition = EditorGUILayout.BeginScrollView(m_ScrollPosition);
  54. for (int i = 0, iMax = m_PackPlatformUniqueIds.Length; i < iMax; i++)
  55. {
  56. string channelUniqueId = m_PackPlatformUniqueIds[i];
  57. if (m_PackPlatformMap.ContainsKey(channelUniqueId))
  58. {
  59. PackPlatformBase srcPackPlatformBase = m_PackPlatformMap[channelUniqueId];
  60. if (ArrayUtility.Contains(m_SelectedPlatforms, srcPackPlatformBase.GetBuildTarget().ToString()))
  61. {
  62. if (!m_PackPlatformMapChange.ContainsKey(channelUniqueId))
  63. {
  64. m_PackPlatformMapChange.Add(channelUniqueId, (PackPlatformBase)srcPackPlatformBase.Clone());
  65. }
  66. PackPlatformBase packPlatformBase = m_PackPlatformMapChange[channelUniqueId];
  67. packPlatformBase.DrawVersionCodeGUI(true, srcPackPlatformBase);
  68. EditorGUILayout.Space();
  69. if (m_GameVersionCodeMin == null || m_GameVersionCodeMin == null)
  70. {
  71. m_GameVersionCodeMin = srcPackPlatformBase.gameVersionCode;
  72. m_GameVersionCodeMax = srcPackPlatformBase.gameVersionCode;
  73. }
  74. else if (srcPackPlatformBase.gameVersionCode < m_GameVersionCodeMin)
  75. {
  76. m_GameVersionCodeMin = srcPackPlatformBase.gameVersionCode;
  77. }
  78. else if (srcPackPlatformBase.gameVersionCode > m_GameVersionCodeMax)
  79. {
  80. m_GameVersionCodeMax = srcPackPlatformBase.gameVersionCode;
  81. }
  82. if (m_ResVersionCodeMin == null || m_ResVersionCodeMax == null)
  83. {
  84. m_ResVersionCodeMin = srcPackPlatformBase.resVersionCode;
  85. m_ResVersionCodeMax = srcPackPlatformBase.resVersionCode;
  86. }
  87. else if (srcPackPlatformBase.resVersionCode < m_ResVersionCodeMin)
  88. {
  89. m_ResVersionCodeMin = srcPackPlatformBase.resVersionCode;
  90. }
  91. else if (srcPackPlatformBase.resVersionCode > m_ResVersionCodeMax)
  92. {
  93. m_ResVersionCodeMax = srcPackPlatformBase.resVersionCode;
  94. }
  95. }
  96. }
  97. else
  98. {
  99. if (m_PackPlatformMapChange.ContainsKey(channelUniqueId))
  100. {
  101. m_PackPlatformMapChange.Remove(channelUniqueId);
  102. }
  103. }
  104. }
  105. EditorGUILayout.EndScrollView();
  106. EditorGUILayout.Space();
  107. GUILayout.FlexibleSpace();
  108. labelWidth = EditorGUIUtility.labelWidth;
  109. EditorGUIUtility.labelWidth = 220;
  110. EditorGUILayout.BeginVertical(PackGUI.styles.box);
  111. EditorGUILayout.BeginHorizontal();
  112. EditorGUILayout.BeginVertical();
  113. EditorGUILayout.LabelField("App版本号", PackGUI.styles.boldLabel);
  114. EditorGUILayout.Space();
  115. EditorGUI.indentLevel += 1;
  116. PackGUI.DrawLabelField("最大App版本号", m_GameVersionCodeMax.ToString());
  117. PackGUI.DrawLabelField("最小App版本号", m_GameVersionCodeMin.ToString());
  118. // PackGUI.DrawVersionCodeField("最大App版本号", false, m_GameVersionCodeMax, ref m_GameVersionCodeMax);
  119. // PackGUI.DrawVersionCodeField("最小App版本号", false, m_GameVersionCodeMin, ref m_GameVersionCodeMin);
  120. EditorGUI.indentLevel -= 1;
  121. EditorGUILayout.EndVertical();
  122. EditorGUILayout.BeginVertical();
  123. EditorGUILayout.LabelField("资源版本号", PackGUI.styles.boldLabel);
  124. EditorGUILayout.Space();
  125. EditorGUI.indentLevel += 1;
  126. PackGUI.DrawLabelField("最大资源版本号", m_ResVersionCodeMax.ToString());
  127. PackGUI.DrawLabelField("最小资源版本号", m_ResVersionCodeMin.ToString());
  128. // PackGUI.DrawVersionCodeField("最大资源版本号", false, m_GameVersionCodeMax, ref m_GameVersionCodeMax);
  129. // PackGUI.DrawVersionCodeField("最小资源版本号", false, m_GameVersionCodeMin, ref m_GameVersionCodeMin);
  130. EditorGUI.indentLevel -= 1;
  131. EditorGUILayout.EndVertical();
  132. EditorGUILayout.EndHorizontal();
  133. EditorGUILayout.Space();
  134. if (!m_GameVersionCodeMaxChange.HasValue) m_GameVersionCodeMaxChange = m_GameVersionCodeMax;
  135. VersionCode versionCode = m_GameVersionCodeMaxChange.Value;
  136. PackGUI.DrawVersionCodeField("全部修改App版本号", false, m_GameVersionCodeMax.Value, ref versionCode);
  137. m_GameVersionCodeMaxChange = versionCode;
  138. if (!m_ResVersionCodeMaxChange.HasValue) m_ResVersionCodeMaxChange = m_ResVersionCodeMax;
  139. versionCode = m_ResVersionCodeMaxChange.Value;
  140. PackGUI.DrawVersionCodeField("全部修改资源版本号", false, m_ResVersionCodeMax.Value, ref versionCode);
  141. m_ResVersionCodeMaxChange = versionCode;
  142. EditorGUILayout.Space();
  143. if (GUILayout.Button("保存修改", PackGUI.styles.miniButton))
  144. {
  145. SavePlatformVersionCodeChange(false);
  146. }
  147. EditorGUILayout.EndVertical();
  148. EditorGUIUtility.labelWidth = labelWidth;
  149. EditorGUILayout.Space();
  150. }
  151. EditorGUILayout.EndVertical();
  152. }
  153. private void ClearSavePlatformVersionCodeChange()
  154. {
  155. m_PackPlatformMapChange.Clear();
  156. ArrayUtility.Clear(ref m_SelectedPlatforms);
  157. m_GameVersionCodeMin = null;
  158. m_GameVersionCodeMax = null;
  159. m_GameVersionCodeMaxChange = null;
  160. m_ResVersionCodeMin = null;
  161. m_ResVersionCodeMax = null;
  162. m_ResVersionCodeMaxChange = null;
  163. }
  164. private bool SavePlatformVersionCodeChange(bool remind = true)
  165. {
  166. bool change1 = false;
  167. if (m_PackPlatformMapChange != null)
  168. {
  169. foreach (var item in m_PackPlatformMapChange)
  170. {
  171. if (m_PackPlatformMap == null
  172. || (m_PackPlatformMap.ContainsKey(item.Value.channelUniqueId) && !m_PackPlatformMap[item.Value.channelUniqueId].Equals(item.Value)))
  173. {
  174. change1 = true;
  175. break;
  176. }
  177. }
  178. }
  179. bool change2 = !m_GameVersionCodeMaxChange.Equals(m_GameVersionCodeMax);
  180. bool change3 = !m_ResVersionCodeMaxChange.Equals(m_ResVersionCodeMax);
  181. bool change4 = (change2 || change3);
  182. if (!change1 && !change4)
  183. {
  184. ClearSavePlatformVersionCodeChange();
  185. return false;
  186. }
  187. if (change1 || change4)
  188. {
  189. if (remind)
  190. {
  191. int overlay = (EditorUtility.DisplayDialogComplex("提示", "是否保存当前修改", "是", "再看看", "否"));
  192. if (overlay == 1)
  193. {
  194. return true;
  195. }
  196. if (overlay == 2)
  197. {
  198. ClearSavePlatformVersionCodeChange();
  199. return false;
  200. }
  201. }
  202. }
  203. if (change1 && change4)
  204. {
  205. if (EditorUtility.DisplayDialog("提示", "有版本单独做了修改, 是否继续保存?", "是", "否"))
  206. {
  207. int overlay = (EditorUtility.DisplayDialogComplex("提示", "有版本单独做了修改, 是否全局修改覆盖它?", "覆盖", "取消修改", "不覆盖"));
  208. if (overlay == 1)
  209. {
  210. return true;
  211. }
  212. foreach (var item in m_PackPlatformMapChange)
  213. {
  214. if ((m_PackPlatformMap.ContainsKey(item.Value.channelUniqueId)))
  215. {
  216. if (!m_PackPlatformMap[item.Value.channelUniqueId].Equals(item.Value))
  217. {
  218. if (overlay == 0)
  219. {
  220. if (change2)
  221. item.Value.gameVersionCode = m_GameVersionCodeMaxChange.Value;
  222. if (change3)
  223. item.Value.resVersionCode = m_ResVersionCodeMaxChange.Value;
  224. }
  225. }
  226. else
  227. {
  228. if (change2)
  229. item.Value.gameVersionCode = m_GameVersionCodeMaxChange.Value;
  230. if (change3)
  231. item.Value.resVersionCode = m_ResVersionCodeMaxChange.Value;
  232. }
  233. }
  234. }
  235. }
  236. else
  237. {
  238. return true;
  239. }
  240. }
  241. else if (change4)
  242. {
  243. foreach (var item in m_PackPlatformMapChange)
  244. {
  245. if ((m_PackPlatformMap.ContainsKey(item.Value.channelUniqueId)))
  246. {
  247. if (change2)
  248. item.Value.gameVersionCode = m_GameVersionCodeMaxChange.Value;
  249. if (change3)
  250. item.Value.resVersionCode = m_ResVersionCodeMaxChange.Value;
  251. }
  252. }
  253. }
  254. foreach (var item in m_PackPlatformMapChange)
  255. {
  256. if ((m_PackPlatformMap.ContainsKey(item.Value.channelUniqueId)))
  257. {
  258. m_PackPlatformMap[item.Value.channelUniqueId] = item.Value;
  259. }
  260. }
  261. SavePackPlatforms();
  262. ClearSavePlatformVersionCodeChange();
  263. return false;
  264. }
  265. }
  266. }