//------------------------------------------------------------ // Game Framework // Copyright © 2013-2021 loyalsoft. All rights reserved. // Homepage: http://www.game7000.com/ // Feedback: http://www.game7000.com/ //------------------------------------------------------------ using GameFramework; using System; using System.IO; using System.Text; using UnityEditor; using UnityEngine; using UnityGameFramework.Runtime; namespace UnityGameFramework.Editor { [CustomEditor(typeof(DownloadComponent))] internal sealed class DownloadComponentInspector : GameFrameworkInspector { private SerializedProperty m_InstanceRoot = null; private SerializedProperty m_DownloadAgentHelperCount = null; private SerializedProperty m_Timeout = null; private SerializedProperty m_FlushSize = null; private HelperInfo m_DownloadAgentHelperInfo = new HelperInfo("DownloadAgent"); public override void OnInspectorGUI() { base.OnInspectorGUI(); serializedObject.Update(); DownloadComponent t = (DownloadComponent)target; EditorGUI.BeginDisabledGroup(EditorApplication.isPlayingOrWillChangePlaymode); { EditorGUILayout.PropertyField(m_InstanceRoot); m_DownloadAgentHelperInfo.Draw(); m_DownloadAgentHelperCount.intValue = EditorGUILayout.IntSlider("Download Agent Helper Count", m_DownloadAgentHelperCount.intValue, 1, 16); } EditorGUI.EndDisabledGroup(); float timeout = EditorGUILayout.Slider("Timeout", m_Timeout.floatValue, 0f, 120f); if (timeout != m_Timeout.floatValue) { if (EditorApplication.isPlaying) { t.Timeout = timeout; } else { m_Timeout.floatValue = timeout; } } int flushSize = EditorGUILayout.DelayedIntField("Flush Size", m_FlushSize.intValue); if (flushSize != m_FlushSize.intValue) { if (EditorApplication.isPlaying) { t.FlushSize = flushSize; } else { m_FlushSize.intValue = flushSize; } } if (EditorApplication.isPlaying && IsPrefabInHierarchy(t.gameObject)) { EditorGUILayout.LabelField("Paused", t.Paused.ToString()); EditorGUILayout.LabelField("Total Agent Count", t.TotalAgentCount.ToString()); EditorGUILayout.LabelField("Free Agent Count", t.FreeAgentCount.ToString()); EditorGUILayout.LabelField("Working Agent Count", t.WorkingAgentCount.ToString()); EditorGUILayout.LabelField("Waiting Agent Count", t.WaitingTaskCount.ToString()); EditorGUILayout.LabelField("Current Speed", t.CurrentSpeed.ToString()); EditorGUILayout.BeginVertical("box"); { GameFramework.TaskInfo[] downloadInfos = t.GetAllDownloadInfos(); if (downloadInfos.Length > 0) { foreach (GameFramework.TaskInfo downloadInfo in downloadInfos) { DrawDownloadInfo(downloadInfo); } if (GUILayout.Button("Export CSV Data")) { string exportFileName = EditorUtility.SaveFilePanel("Export CSV Data", string.Empty, "Download Task Data.csv", string.Empty); if (!string.IsNullOrEmpty(exportFileName)) { try { int index = 0; string[] data = new string[downloadInfos.Length + 1]; data[index++] = "Download Path,Serial Id,Tag,Priority,Status"; foreach (GameFramework.TaskInfo downloadInfo in downloadInfos) { 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()); } File.WriteAllLines(exportFileName, data, Encoding.UTF8); Debug.Log(Utility.Text.Format("Export download task CSV data to '{0}' success.", exportFileName)); } catch (Exception exception) { Debug.LogError(Utility.Text.Format("Export download task CSV data to '{0}' failure, exception is '{1}'.", exportFileName, exception.ToString())); } } } } else { GUILayout.Label("Download Task is Empty ..."); } } EditorGUILayout.EndVertical(); } serializedObject.ApplyModifiedProperties(); Repaint(); } protected override void OnCompileComplete() { base.OnCompileComplete(); RefreshTypeNames(); } private void OnEnable() { m_InstanceRoot = serializedObject.FindProperty("m_InstanceRoot"); m_DownloadAgentHelperCount = serializedObject.FindProperty("m_DownloadAgentHelperCount"); m_Timeout = serializedObject.FindProperty("m_Timeout"); m_FlushSize = serializedObject.FindProperty("m_FlushSize"); m_DownloadAgentHelperInfo.Init(serializedObject); RefreshTypeNames(); } private void DrawDownloadInfo(GameFramework.TaskInfo downloadInfo) { EditorGUILayout.LabelField(downloadInfo.Description, Utility.Text.Format("[SerialId]{0} [Tag]{1} [Priority]{2} [Status]{3}", downloadInfo.SerialId.ToString(), downloadInfo.Tag ?? "", downloadInfo.Priority.ToString(), downloadInfo.Status.ToString())); } private void RefreshTypeNames() { m_DownloadAgentHelperInfo.Refresh(); serializedObject.ApplyModifiedProperties(); } } }