using System; using System.Collections.Generic; using AlicizaX.Editor; using AlicizaX.Resource.Runtime; using UnityEditor; using UnityEngine; using YooAsset; using YooAsset.Editor; namespace AlicizaX.Resource.Editor { [CustomEditor(typeof(ResourceComponent))] internal sealed class ResourceComponentInspector : ComponentTypeComponentInspector { private SerializedProperty m_Milliseconds; private SerializedProperty m_defaultPackageName; private SerializedProperty m_AssetAutoReleaseInterval; private SerializedProperty m_AssetCapacity; private SerializedProperty m_AssetExpireTime; private SerializedProperty m_AssetPriority; private SerializedProperty m_DecryptionServices; private int m_PackageNameIndex = 0; private string[] m_PackageNames; private List m_DecryptionServicesTypeName = new(); private int m_DecryptionSelectIndex; public override void OnInspectorGUI() { base.OnInspectorGUI(); serializedObject.Update(); ResourceComponent t = (ResourceComponent)target; EditorGUI.BeginDisabledGroup(EditorApplication.isPlayingOrWillChangePlaymode); { long milliseconds = (long)EditorGUILayout.Slider("每帧执行消耗的最大时间切片(ms)", m_Milliseconds.longValue, 30, 100000); if (milliseconds != m_Milliseconds.longValue) { m_Milliseconds.longValue = milliseconds; } m_PackageNames = GetBuildPackageNames().ToArray(); m_PackageNameIndex = Array.IndexOf(m_PackageNames, m_defaultPackageName.stringValue); if (m_PackageNameIndex < 0) { m_PackageNameIndex = 0; } m_PackageNameIndex = EditorGUILayout.Popup("Package Name", m_PackageNameIndex, m_PackageNames); if (m_defaultPackageName.stringValue != m_PackageNames[m_PackageNameIndex]) { m_defaultPackageName.stringValue = m_PackageNames[m_PackageNameIndex]; } float assetAutoReleaseInterval = EditorGUILayout.Slider("对象池自动释放间隔(s)", m_AssetAutoReleaseInterval.floatValue, 60, 3600); if (assetAutoReleaseInterval != m_AssetAutoReleaseInterval.floatValue) { m_AssetAutoReleaseInterval.floatValue = assetAutoReleaseInterval; } int assetCapacity = EditorGUILayout.IntSlider("对象池容量", m_AssetCapacity.intValue, 32, 1024); if (assetCapacity != m_AssetCapacity.intValue) { m_AssetCapacity.intValue = assetCapacity; } float assetExpireTime = EditorGUILayout.Slider("对象池过期秒数", m_AssetExpireTime.floatValue, 60, 1024); if (assetExpireTime != m_AssetExpireTime.floatValue) { m_AssetExpireTime.floatValue = assetExpireTime; } int assetPriority = EditorGUILayout.IntSlider("对象池优先级", m_AssetPriority.intValue, 0, 10); if (assetPriority != m_AssetPriority.intValue) { m_AssetPriority.intValue = assetPriority; } m_DecryptionSelectIndex = EditorGUILayout.Popup("解密服务", m_DecryptionSelectIndex, m_DecryptionServicesTypeName.ToArray()); string selectService = m_DecryptionServicesTypeName[m_DecryptionSelectIndex]; if (selectService != NoneOptionName && m_DecryptionServices.stringValue != selectService) { m_DecryptionServices.stringValue = selectService; } } if (EditorApplication.isPlaying && IsPrefabInHierarchy(t.gameObject)) { // EditorGUILayout.LabelField("Unload Unused Assets", // Utility.Text.Format("{0:F2} / {1:F2}", t.LastUnloadUnusedAssetsOperationElapseSeconds, t.MaxUnloadUnusedAssetsInterval)); // EditorGUILayout.LabelField("Read-Only Path", t?.ReadOnlyPath?.ToString()); // EditorGUILayout.LabelField("Read-Write Path", t?.ReadWritePath?.ToString()); EditorGUILayout.LabelField("Package Version", t.PackageVersion ?? ""); } EditorGUI.EndDisabledGroup(); serializedObject.ApplyModifiedProperties(); Repaint(); } protected override void RefreshTypeNames() { RefreshComponentTypeNames(typeof(IResourceManager)); RefreshDecryptionServices(); } protected override void Enable() { m_Milliseconds = serializedObject.FindProperty("m_Milliseconds"); m_defaultPackageName = serializedObject.FindProperty("m_defaultPackageName"); m_AssetAutoReleaseInterval = serializedObject.FindProperty("m_AssetAutoReleaseInterval"); m_AssetCapacity = serializedObject.FindProperty("m_AssetCapacity"); m_AssetExpireTime = serializedObject.FindProperty("m_AssetExpireTime"); m_AssetPriority = serializedObject.FindProperty("m_AssetPriority"); m_DecryptionServices = serializedObject.FindProperty("m_DecryptionServices"); } /// /// 获取构建包名称列表,用于下拉可选择 /// /// private List GetBuildPackageNames() { List result = new List(); foreach (var package in AssetBundleCollectorSettingData.Setting.Packages) { result.Add(package.PackageName); } return result; } private void RefreshDecryptionServices() { m_DecryptionServicesTypeName = new List { NoneOptionName }; m_DecryptionServicesTypeName.AddRange(AlicizaX.Runtime.Utility.Assembly.GetRuntimeTypeNames(typeof(IDecryptionServices))); m_DecryptionSelectIndex = m_DecryptionServicesTypeName.IndexOf(m_DecryptionServices.stringValue); if (m_DecryptionSelectIndex < 0) { m_DecryptionSelectIndex = 0; } } } }