WebRequestComponentInspector.cs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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(WebRequestComponent))]
  17. internal sealed class WebRequestComponentInspector : GameFrameworkInspector
  18. {
  19. private SerializedProperty m_InstanceRoot = null;
  20. private SerializedProperty m_WebRequestAgentHelperCount = null;
  21. private SerializedProperty m_Timeout = null;
  22. private HelperInfo<WebRequestAgentHelperBase> m_WebRequestAgentHelperInfo = new HelperInfo<WebRequestAgentHelperBase>("WebRequestAgent");
  23. public override void OnInspectorGUI()
  24. {
  25. base.OnInspectorGUI();
  26. serializedObject.Update();
  27. WebRequestComponent t = (WebRequestComponent)target;
  28. EditorGUI.BeginDisabledGroup(EditorApplication.isPlayingOrWillChangePlaymode);
  29. {
  30. EditorGUILayout.PropertyField(m_InstanceRoot);
  31. m_WebRequestAgentHelperInfo.Draw();
  32. m_WebRequestAgentHelperCount.intValue = EditorGUILayout.IntSlider("Web Request Agent Helper Count", m_WebRequestAgentHelperCount.intValue, 1, 16);
  33. }
  34. EditorGUI.EndDisabledGroup();
  35. float timeout = EditorGUILayout.Slider("Timeout", m_Timeout.floatValue, 0f, 120f);
  36. if (timeout != m_Timeout.floatValue)
  37. {
  38. if (EditorApplication.isPlaying)
  39. {
  40. t.Timeout = timeout;
  41. }
  42. else
  43. {
  44. m_Timeout.floatValue = timeout;
  45. }
  46. }
  47. if (EditorApplication.isPlaying && IsPrefabInHierarchy(t.gameObject))
  48. {
  49. EditorGUILayout.LabelField("Total Agent Count", t.TotalAgentCount.ToString());
  50. EditorGUILayout.LabelField("Free Agent Count", t.FreeAgentCount.ToString());
  51. EditorGUILayout.LabelField("Working Agent Count", t.WorkingAgentCount.ToString());
  52. EditorGUILayout.LabelField("Waiting Agent Count", t.WaitingTaskCount.ToString());
  53. EditorGUILayout.BeginVertical("box");
  54. {
  55. GameFramework.TaskInfo[] webRequestInfos = t.GetAllWebRequestInfos();
  56. if (webRequestInfos.Length > 0)
  57. {
  58. foreach (GameFramework.TaskInfo webRequestInfo in webRequestInfos)
  59. {
  60. DrawWebRequestInfo(webRequestInfo);
  61. }
  62. if (GUILayout.Button("Export CSV Data"))
  63. {
  64. string exportFileName = EditorUtility.SaveFilePanel("Export CSV Data", string.Empty, "WebRequest Task Data.csv", string.Empty);
  65. if (!string.IsNullOrEmpty(exportFileName))
  66. {
  67. try
  68. {
  69. int index = 0;
  70. string[] data = new string[webRequestInfos.Length + 1];
  71. data[index++] = "WebRequest Uri,Serial Id,Tag,Priority,Status";
  72. foreach (GameFramework.TaskInfo webRequestInfo in webRequestInfos)
  73. {
  74. data[index++] = Utility.Text.Format("{0},{1},{2},{3},{4}", webRequestInfo.Description, webRequestInfo.SerialId.ToString(), webRequestInfo.Tag ?? string.Empty, webRequestInfo.Priority.ToString(), webRequestInfo.Status.ToString());
  75. }
  76. File.WriteAllLines(exportFileName, data, Encoding.UTF8);
  77. Debug.Log(Utility.Text.Format("Export web request task CSV data to '{0}' success.", exportFileName));
  78. }
  79. catch (Exception exception)
  80. {
  81. Debug.LogError(Utility.Text.Format("Export web request task CSV data to '{0}' failure, exception is '{1}'.", exportFileName, exception.ToString()));
  82. }
  83. }
  84. }
  85. }
  86. else
  87. {
  88. GUILayout.Label("WebRequset Task is Empty ...");
  89. }
  90. }
  91. EditorGUILayout.EndVertical();
  92. }
  93. serializedObject.ApplyModifiedProperties();
  94. Repaint();
  95. }
  96. protected override void OnCompileComplete()
  97. {
  98. base.OnCompileComplete();
  99. RefreshTypeNames();
  100. }
  101. private void OnEnable()
  102. {
  103. m_InstanceRoot = serializedObject.FindProperty("m_InstanceRoot");
  104. m_WebRequestAgentHelperCount = serializedObject.FindProperty("m_WebRequestAgentHelperCount");
  105. m_Timeout = serializedObject.FindProperty("m_Timeout");
  106. m_WebRequestAgentHelperInfo.Init(serializedObject);
  107. RefreshTypeNames();
  108. }
  109. private void DrawWebRequestInfo(GameFramework.TaskInfo webRequestInfo)
  110. {
  111. EditorGUILayout.LabelField(webRequestInfo.Description, Utility.Text.Format("[SerialId]{0} [Tag]{1} [Priority]{2} [Status]{3}", webRequestInfo.SerialId.ToString(), webRequestInfo.Tag ?? "<None>", webRequestInfo.Priority.ToString(), webRequestInfo.Status.ToString()));
  112. }
  113. private void RefreshTypeNames()
  114. {
  115. m_WebRequestAgentHelperInfo.Refresh();
  116. serializedObject.ApplyModifiedProperties();
  117. }
  118. }
  119. }