DownloadComponentInspector.cs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. //------------------------------------------------------------
  2. // Game Framework
  3. // Copyright © 2013-2021 loyalsoft. All rights reserved.
  4. // Homepage: http://www.game7000.com/
  5. // Feedback: http://www.game7000.com/
  6. //------------------------------------------------------------
  7. using GameFramework;
  8. using System;
  9. using System.IO;
  10. using System.Text;
  11. using UnityEditor;
  12. using UnityEngine;
  13. using UnityGameFramework.Runtime;
  14. namespace UnityGameFramework.Editor
  15. {
  16. [CustomEditor(typeof(DownloadComponent))]
  17. internal sealed class DownloadComponentInspector : GameFrameworkInspector
  18. {
  19. private SerializedProperty m_InstanceRoot = null;
  20. private SerializedProperty m_DownloadAgentHelperCount = null;
  21. private SerializedProperty m_Timeout = null;
  22. private SerializedProperty m_FlushSize = null;
  23. private HelperInfo<DownloadAgentHelperBase> m_DownloadAgentHelperInfo = new HelperInfo<DownloadAgentHelperBase>("DownloadAgent");
  24. public override void OnInspectorGUI()
  25. {
  26. base.OnInspectorGUI();
  27. serializedObject.Update();
  28. DownloadComponent t = (DownloadComponent)target;
  29. EditorGUI.BeginDisabledGroup(EditorApplication.isPlayingOrWillChangePlaymode);
  30. {
  31. EditorGUILayout.PropertyField(m_InstanceRoot);
  32. m_DownloadAgentHelperInfo.Draw();
  33. m_DownloadAgentHelperCount.intValue = EditorGUILayout.IntSlider("Download Agent Helper Count", m_DownloadAgentHelperCount.intValue, 1, 16);
  34. }
  35. EditorGUI.EndDisabledGroup();
  36. float timeout = EditorGUILayout.Slider("Timeout", m_Timeout.floatValue, 0f, 120f);
  37. if (timeout != m_Timeout.floatValue)
  38. {
  39. if (EditorApplication.isPlaying)
  40. {
  41. t.Timeout = timeout;
  42. }
  43. else
  44. {
  45. m_Timeout.floatValue = timeout;
  46. }
  47. }
  48. int flushSize = EditorGUILayout.DelayedIntField("Flush Size", m_FlushSize.intValue);
  49. if (flushSize != m_FlushSize.intValue)
  50. {
  51. if (EditorApplication.isPlaying)
  52. {
  53. t.FlushSize = flushSize;
  54. }
  55. else
  56. {
  57. m_FlushSize.intValue = flushSize;
  58. }
  59. }
  60. if (EditorApplication.isPlaying && IsPrefabInHierarchy(t.gameObject))
  61. {
  62. EditorGUILayout.LabelField("Paused", t.Paused.ToString());
  63. EditorGUILayout.LabelField("Total Agent Count", t.TotalAgentCount.ToString());
  64. EditorGUILayout.LabelField("Free Agent Count", t.FreeAgentCount.ToString());
  65. EditorGUILayout.LabelField("Working Agent Count", t.WorkingAgentCount.ToString());
  66. EditorGUILayout.LabelField("Waiting Agent Count", t.WaitingTaskCount.ToString());
  67. EditorGUILayout.LabelField("Current Speed", t.CurrentSpeed.ToString());
  68. EditorGUILayout.BeginVertical("box");
  69. {
  70. GameFramework.TaskInfo[] downloadInfos = t.GetAllDownloadInfos();
  71. if (downloadInfos.Length > 0)
  72. {
  73. foreach (GameFramework.TaskInfo downloadInfo in downloadInfos)
  74. {
  75. DrawDownloadInfo(downloadInfo);
  76. }
  77. if (GUILayout.Button("Export CSV Data"))
  78. {
  79. string exportFileName = EditorUtility.SaveFilePanel("Export CSV Data", string.Empty, "Download Task Data.csv", string.Empty);
  80. if (!string.IsNullOrEmpty(exportFileName))
  81. {
  82. try
  83. {
  84. int index = 0;
  85. string[] data = new string[downloadInfos.Length + 1];
  86. data[index++] = "Download Path,Serial Id,Tag,Priority,Status";
  87. foreach (GameFramework.TaskInfo downloadInfo in downloadInfos)
  88. {
  89. data[index++] = Utility.Text.Format("{0},{1},{2},{3},{4}", downloadInfo.Description, downloadInfo.SerialId.ToString(), downloadInfo.Tag ?? string.Empty, downloadInfo.Priority.ToString(), downloadInfo.Status.ToString());
  90. }
  91. File.WriteAllLines(exportFileName, data, Encoding.UTF8);
  92. Debug.Log(Utility.Text.Format("Export download task CSV data to '{0}' success.", exportFileName));
  93. }
  94. catch (Exception exception)
  95. {
  96. Debug.LogError(Utility.Text.Format("Export download task CSV data to '{0}' failure, exception is '{1}'.", exportFileName, exception.ToString()));
  97. }
  98. }
  99. }
  100. }
  101. else
  102. {
  103. GUILayout.Label("Download Task is Empty ...");
  104. }
  105. }
  106. EditorGUILayout.EndVertical();
  107. }
  108. serializedObject.ApplyModifiedProperties();
  109. Repaint();
  110. }
  111. protected override void OnCompileComplete()
  112. {
  113. base.OnCompileComplete();
  114. RefreshTypeNames();
  115. }
  116. private void OnEnable()
  117. {
  118. m_InstanceRoot = serializedObject.FindProperty("m_InstanceRoot");
  119. m_DownloadAgentHelperCount = serializedObject.FindProperty("m_DownloadAgentHelperCount");
  120. m_Timeout = serializedObject.FindProperty("m_Timeout");
  121. m_FlushSize = serializedObject.FindProperty("m_FlushSize");
  122. m_DownloadAgentHelperInfo.Init(serializedObject);
  123. RefreshTypeNames();
  124. }
  125. private void DrawDownloadInfo(GameFramework.TaskInfo downloadInfo)
  126. {
  127. EditorGUILayout.LabelField(downloadInfo.Description, Utility.Text.Format("[SerialId]{0} [Tag]{1} [Priority]{2} [Status]{3}", downloadInfo.SerialId.ToString(), downloadInfo.Tag ?? "<None>", downloadInfo.Priority.ToString(), downloadInfo.Status.ToString()));
  128. }
  129. private void RefreshTypeNames()
  130. {
  131. m_DownloadAgentHelperInfo.Refresh();
  132. serializedObject.ApplyModifiedProperties();
  133. }
  134. }
  135. }