AlicizaX/Client/Packages/com.alicizax.unity.resource/Editor/Inspector/ResourceComponentInspector.cs

265 lines
10 KiB
C#
Raw Normal View History

2025-01-26 20:55:39 +08:00
using System;
using System.Collections.Generic;
using AlicizaX.Editor;
2025-01-23 19:06:48 +08:00
using AlicizaX.Resource.Runtime;
using UnityEditor;
2025-02-06 17:59:35 +08:00
using YooAsset;
2025-01-26 20:55:39 +08:00
using YooAsset.Editor;
2025-01-23 19:06:48 +08:00
namespace AlicizaX.Resource.Editor
{
[CustomEditor(typeof(ResourceComponent))]
2025-04-28 19:45:45 +08:00
internal sealed class ResourceComponentInspector : GameFrameworkInspector
2025-01-23 19:06:48 +08:00
{
2025-04-28 19:45:45 +08:00
private SerializedProperty _milliseconds = null;
private SerializedProperty _minUnloadUnusedAssetsInterval = null;
private SerializedProperty _maxUnloadUnusedAssetsInterval = null;
private SerializedProperty _useSystemUnloadUnusedAssets = null;
private SerializedProperty _assetAutoReleaseInterval = null;
private SerializedProperty _assetCapacity = null;
private SerializedProperty _assetExpireTime = null;
private SerializedProperty _assetPriority = null;
private SerializedProperty _downloadingMaxNum = null;
private SerializedProperty _failedTryAgain = null;
private SerializedProperty _packageName = null;
private SerializedProperty _decryptionServices = null;
2025-02-06 17:59:35 +08:00
2025-04-28 19:45:45 +08:00
private int _packageNameIndex = 0;
private string[] _packageNames;
2025-01-24 16:21:00 +08:00
2025-02-06 17:59:35 +08:00
private List<string> m_DecryptionServicesTypeName = new();
private int m_DecryptionSelectIndex;
2025-01-23 19:06:48 +08:00
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
2025-04-28 19:45:45 +08:00
2025-01-23 19:06:48 +08:00
serializedObject.Update();
2025-01-26 20:55:39 +08:00
ResourceComponent t = (ResourceComponent)target;
2025-04-28 19:45:45 +08:00
m_DecryptionSelectIndex = EditorGUILayout.Popup("解密服务", m_DecryptionSelectIndex, m_DecryptionServicesTypeName.ToArray());
string selectService = m_DecryptionServicesTypeName[m_DecryptionSelectIndex];
if (_decryptionServices.stringValue != selectService)
{
string serviceName = selectService.Equals(NoneOptionName) ? string.Empty : selectService;
_decryptionServices.stringValue = serviceName;
}
_packageNames = GetBuildPackageNames().ToArray();
_packageNameIndex = Array.IndexOf(_packageNames, _packageName.stringValue);
if (_packageNameIndex < 0)
{
_packageNameIndex = 0;
}
_packageNameIndex = EditorGUILayout.Popup("Package Name", _packageNameIndex, _packageNames);
if (_packageName.stringValue != _packageNames[_packageNameIndex])
{
_packageName.stringValue = _packageNames[_packageNameIndex];
}
int milliseconds = EditorGUILayout.DelayedIntField("Milliseconds", _milliseconds.intValue);
if (milliseconds != _milliseconds.intValue)
2025-01-23 19:06:48 +08:00
{
2025-04-28 19:45:45 +08:00
if (EditorApplication.isPlaying)
2025-01-24 16:21:00 +08:00
{
2025-04-28 19:45:45 +08:00
t.milliseconds = milliseconds;
2025-01-24 16:21:00 +08:00
}
2025-04-28 19:45:45 +08:00
else
2025-01-26 20:55:39 +08:00
{
2025-04-28 19:45:45 +08:00
_milliseconds.longValue = milliseconds;
2025-01-26 20:55:39 +08:00
}
2025-04-28 19:45:45 +08:00
}
EditorGUILayout.PropertyField(_useSystemUnloadUnusedAssets);
2025-01-26 20:55:39 +08:00
2025-04-28 19:45:45 +08:00
float minUnloadUnusedAssetsInterval =
EditorGUILayout.Slider("Min Unload Unused Assets Interval", _minUnloadUnusedAssetsInterval.floatValue, 0f, 3600f);
if (Math.Abs(minUnloadUnusedAssetsInterval - _minUnloadUnusedAssetsInterval.floatValue) > 0.01f)
{
if (EditorApplication.isPlaying)
2025-01-24 16:21:00 +08:00
{
2025-04-28 19:45:45 +08:00
t.MinUnloadUnusedAssetsInterval = minUnloadUnusedAssetsInterval;
2025-01-24 16:21:00 +08:00
}
2025-04-28 19:45:45 +08:00
else
{
_minUnloadUnusedAssetsInterval.floatValue = minUnloadUnusedAssetsInterval;
}
}
2025-01-24 16:21:00 +08:00
2025-04-28 19:45:45 +08:00
float maxUnloadUnusedAssetsInterval =
EditorGUILayout.Slider("Max Unload Unused Assets Interval", _maxUnloadUnusedAssetsInterval.floatValue, 0f, 3600f);
if (Math.Abs(maxUnloadUnusedAssetsInterval - _maxUnloadUnusedAssetsInterval.floatValue) > 0.01f)
{
if (EditorApplication.isPlaying)
{
t.MaxUnloadUnusedAssetsInterval = maxUnloadUnusedAssetsInterval;
}
else
2025-01-24 16:21:00 +08:00
{
2025-04-28 19:45:45 +08:00
_maxUnloadUnusedAssetsInterval.floatValue = maxUnloadUnusedAssetsInterval;
2025-01-24 16:21:00 +08:00
}
2025-04-28 19:45:45 +08:00
}
2025-01-24 16:21:00 +08:00
2025-04-28 19:45:45 +08:00
float downloadingMaxNum = EditorGUILayout.Slider("Max Downloading Num", _downloadingMaxNum.intValue, 1f, 48f);
if (Math.Abs(downloadingMaxNum - _downloadingMaxNum.intValue) > 0.001f)
{
if (EditorApplication.isPlaying)
2025-01-24 16:21:00 +08:00
{
2025-04-28 19:45:45 +08:00
t.DownloadingMaxNum = (int)downloadingMaxNum;
2025-01-24 16:21:00 +08:00
}
2025-04-28 19:45:45 +08:00
else
{
_downloadingMaxNum.intValue = (int)downloadingMaxNum;
}
}
2025-01-24 16:21:00 +08:00
2025-04-28 19:45:45 +08:00
float failedTryAgain = EditorGUILayout.Slider("Max FailedTryAgain Count", _failedTryAgain.intValue, 1f, 48f);
if (Math.Abs(failedTryAgain - _failedTryAgain.intValue) > 0.001f)
{
if (EditorApplication.isPlaying)
{
t.FailedTryAgain = (int)failedTryAgain;
}
else
{
_failedTryAgain.intValue = (int)failedTryAgain;
}
}
2025-01-24 16:21:00 +08:00
2025-04-28 19:45:45 +08:00
EditorGUI.BeginDisabledGroup(EditorApplication.isPlaying);
{
float assetAutoReleaseInterval = EditorGUILayout.DelayedFloatField("Asset Auto Release Interval", _assetAutoReleaseInterval.floatValue);
if (Math.Abs(assetAutoReleaseInterval - _assetAutoReleaseInterval.floatValue) > 0.01f)
2025-01-24 16:21:00 +08:00
{
2025-04-28 19:45:45 +08:00
if (EditorApplication.isPlaying)
{
t.AssetAutoReleaseInterval = assetAutoReleaseInterval;
}
else
{
_assetAutoReleaseInterval.floatValue = assetAutoReleaseInterval;
}
2025-01-24 16:21:00 +08:00
}
2025-04-28 19:45:45 +08:00
int assetCapacity = EditorGUILayout.DelayedIntField("Asset Capacity", _assetCapacity.intValue);
if (assetCapacity != _assetCapacity.intValue)
{
if (EditorApplication.isPlaying)
{
t.AssetCapacity = assetCapacity;
}
else
{
_assetCapacity.intValue = assetCapacity;
}
}
2025-01-24 16:21:00 +08:00
2025-04-28 19:45:45 +08:00
float assetExpireTime = EditorGUILayout.DelayedFloatField("Asset Expire Time", _assetExpireTime.floatValue);
if (Math.Abs(assetExpireTime - _assetExpireTime.floatValue) > 0.01f)
2025-01-24 16:21:00 +08:00
{
2025-04-28 19:45:45 +08:00
if (EditorApplication.isPlaying)
{
t.AssetExpireTime = assetExpireTime;
}
else
{
_assetExpireTime.floatValue = assetExpireTime;
}
2025-01-24 16:21:00 +08:00
}
2025-02-06 17:59:35 +08:00
2025-04-28 19:45:45 +08:00
int assetPriority = EditorGUILayout.DelayedIntField("Asset Priority", _assetPriority.intValue);
if (assetPriority != _assetPriority.intValue)
2025-02-06 17:59:35 +08:00
{
2025-04-28 19:45:45 +08:00
if (EditorApplication.isPlaying)
{
t.AssetPriority = assetPriority;
}
else
{
_assetPriority.intValue = assetPriority;
}
2025-02-06 17:59:35 +08:00
}
2025-01-23 19:06:48 +08:00
}
2025-04-28 19:45:45 +08:00
EditorGUI.EndDisabledGroup();
2025-01-26 20:55:39 +08:00
if (EditorApplication.isPlaying && IsPrefabInHierarchy(t.gameObject))
{
2025-04-28 19:45:45 +08:00
EditorGUILayout.LabelField("Unload Unused Assets",
AlicizaX.Utility.Text.Format("{0:F2} / {1:F2}", t.LastUnloadUnusedAssetsOperationElapseSeconds, t.MaxUnloadUnusedAssetsInterval));
EditorGUILayout.LabelField("Applicable Game Version", t.ApplicableGameVersion ?? "<Unknwon>");
2025-01-26 20:55:39 +08:00
}
2025-01-23 19:06:48 +08:00
serializedObject.ApplyModifiedProperties();
Repaint();
}
2025-01-24 16:21:00 +08:00
2025-04-28 19:45:45 +08:00
protected override void OnCompileComplete()
{
base.OnCompileComplete();
RefreshTypeNames();
}
2025-01-23 19:06:48 +08:00
2025-04-28 19:45:45 +08:00
private void OnEnable()
2025-01-23 19:06:48 +08:00
{
2025-04-28 19:45:45 +08:00
_milliseconds = serializedObject.FindProperty("milliseconds");
_minUnloadUnusedAssetsInterval = serializedObject.FindProperty("minUnloadUnusedAssetsInterval");
_maxUnloadUnusedAssetsInterval = serializedObject.FindProperty("maxUnloadUnusedAssetsInterval");
_useSystemUnloadUnusedAssets = serializedObject.FindProperty("useSystemUnloadUnusedAssets");
_assetAutoReleaseInterval = serializedObject.FindProperty("assetAutoReleaseInterval");
_assetCapacity = serializedObject.FindProperty("assetCapacity");
_assetExpireTime = serializedObject.FindProperty("assetExpireTime");
_assetPriority = serializedObject.FindProperty("assetPriority");
_downloadingMaxNum = serializedObject.FindProperty("downloadingMaxNum");
_failedTryAgain = serializedObject.FindProperty("failedTryAgain");
_packageName = serializedObject.FindProperty("packageName");
_decryptionServices = serializedObject.FindProperty("_decryptionServices");
2025-02-06 17:59:35 +08:00
RefreshDecryptionServices();
2025-04-28 19:45:45 +08:00
RefreshTypeNames();
}
private void RefreshDecryptionServices()
{
m_DecryptionServicesTypeName = new List<string>
{
NoneOptionName
};
m_DecryptionServicesTypeName.AddRange(AlicizaX.Utility.Assembly.GetRuntimeTypeNames(typeof(IDecryptionServices)));
m_DecryptionSelectIndex = m_DecryptionServicesTypeName.IndexOf(_decryptionServices.stringValue);
if (m_DecryptionSelectIndex < 0)
{
m_DecryptionSelectIndex = 0;
}
2025-01-23 19:06:48 +08:00
}
2025-01-24 16:21:00 +08:00
2025-04-28 19:45:45 +08:00
private void RefreshTypeNames()
2025-01-23 19:06:48 +08:00
{
2025-04-28 19:45:45 +08:00
serializedObject.ApplyModifiedProperties();
2025-01-23 19:06:48 +08:00
}
2025-01-26 20:55:39 +08:00
/// <summary>
/// 获取构建包名称列表,用于下拉可选择
/// </summary>
/// <returns></returns>
private List<string> GetBuildPackageNames()
{
List<string> result = new List<string>();
foreach (var package in AssetBundleCollectorSettingData.Setting.Packages)
{
result.Add(package.PackageName);
}
return result;
}
2025-01-23 19:06:48 +08:00
}
2025-01-24 16:21:00 +08:00
}