mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-14 16:51:28 +00:00
ResourceModule
ResourceModule
This commit is contained in:
@@ -857,9 +857,18 @@ MonoBehaviour:
|
|||||||
m_GameObject: {fileID: 2049602905}
|
m_GameObject: {fileID: 2049602905}
|
||||||
m_Enabled: 1
|
m_Enabled: 1
|
||||||
m_EditorHideFlags: 0
|
m_EditorHideFlags: 0
|
||||||
m_Script: {fileID: 11500000, guid: 77d67944806247f99024bf5307adc918, type: 3}
|
m_Script: {fileID: 11500000, guid: 6e9edd9af2004f138ce8c543a2509393, type: 3}
|
||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
|
packageName: DefaultPackage
|
||||||
|
playMode: 0
|
||||||
|
verifyLevel: 1
|
||||||
|
readWritePathType: 0
|
||||||
|
minUnloadUnusedAssetsInterval: 60
|
||||||
|
maxUnloadUnusedAssetsInterval: 300
|
||||||
|
milliseconds: 30
|
||||||
|
downloadingMaxNum: 3
|
||||||
|
failedTryAgain: 3
|
||||||
--- !u!1 &2061060681
|
--- !u!1 &2061060681
|
||||||
GameObject:
|
GameObject:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
@@ -871,7 +880,7 @@ GameObject:
|
|||||||
- component: {fileID: 2061060682}
|
- component: {fileID: 2061060682}
|
||||||
- component: {fileID: 2061060683}
|
- component: {fileID: 2061060683}
|
||||||
m_Layer: 0
|
m_Layer: 0
|
||||||
m_Name: RootModule
|
m_Name: Root
|
||||||
m_TagString: Untagged
|
m_TagString: Untagged
|
||||||
m_Icon: {fileID: 0}
|
m_Icon: {fileID: 0}
|
||||||
m_NavMeshLayer: 0
|
m_NavMeshLayer: 0
|
||||||
|
247
Assets/TEngine/Editor/Inspector/ResourceModuleInspector.cs
Normal file
247
Assets/TEngine/Editor/Inspector/ResourceModuleInspector.cs
Normal file
@@ -0,0 +1,247 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEditor;
|
||||||
|
using UnityEditor.UIElements;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.UIElements;
|
||||||
|
using YooAsset.Editor;
|
||||||
|
|
||||||
|
namespace TEngine.Editor.Inspector
|
||||||
|
{
|
||||||
|
[CustomEditor(typeof(ResourceModule))]
|
||||||
|
internal sealed class ResourceModuleInspector : GameFrameworkInspector
|
||||||
|
{
|
||||||
|
private static readonly string[] ResourceModeNames = new string[] { "EditorSimulateMode (编辑器下的模拟模式)", "OfflinePlayMode (单机模式)", "HostPlayMode (联机运行模式)" };
|
||||||
|
private static readonly string[] VerifyLevelNames = new string[] { "Low (验证文件存在)", "Middle (验证文件大小)", "High (验证文件大小和CRC)" };
|
||||||
|
|
||||||
|
private SerializedProperty m_PackageName = null;
|
||||||
|
private SerializedProperty m_PlayMode = null;
|
||||||
|
private SerializedProperty m_ReadWritePathType = null;
|
||||||
|
private SerializedProperty m_VerifyLevel = null;
|
||||||
|
private SerializedProperty m_Milliseconds = null;
|
||||||
|
private SerializedProperty m_MinUnloadUnusedAssetsInterval = null;
|
||||||
|
private SerializedProperty m_MaxUnloadUnusedAssetsInterval = null;
|
||||||
|
private SerializedProperty m_DownloadingMaxNum = null;
|
||||||
|
private SerializedProperty m_FailedTryAgain = null;
|
||||||
|
|
||||||
|
private int m_ResourceModeIndex = 0;
|
||||||
|
private int m_PackageIndex = 0;
|
||||||
|
private int m_VerifyIndex = 0;
|
||||||
|
|
||||||
|
private PopupField<string> _buildPackageField;
|
||||||
|
private List<string> _buildPackageNames;
|
||||||
|
|
||||||
|
private void OnEnable()
|
||||||
|
{
|
||||||
|
m_PackageName = serializedObject.FindProperty("packageName");
|
||||||
|
m_PlayMode = serializedObject.FindProperty("playMode");
|
||||||
|
m_VerifyLevel = serializedObject.FindProperty("verifyLevel");
|
||||||
|
m_Milliseconds = serializedObject.FindProperty("milliseconds");
|
||||||
|
|
||||||
|
m_ReadWritePathType = serializedObject.FindProperty("readWritePathType");
|
||||||
|
m_MinUnloadUnusedAssetsInterval = serializedObject.FindProperty("minUnloadUnusedAssetsInterval");
|
||||||
|
m_MaxUnloadUnusedAssetsInterval = serializedObject.FindProperty("maxUnloadUnusedAssetsInterval");
|
||||||
|
m_DownloadingMaxNum = serializedObject.FindProperty("downloadingMaxNum");
|
||||||
|
m_FailedTryAgain = serializedObject.FindProperty("failedTryAgain");
|
||||||
|
|
||||||
|
RefreshModes();
|
||||||
|
RefreshTypeNames();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void RefreshModes()
|
||||||
|
{
|
||||||
|
m_ResourceModeIndex = m_PlayMode.enumValueIndex > 0 ? m_PlayMode.enumValueIndex : 0;
|
||||||
|
m_VerifyIndex = m_VerifyLevel.enumValueIndex > 0 ? m_VerifyLevel.enumValueIndex : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void OnInspectorGUI()
|
||||||
|
{
|
||||||
|
base.OnInspectorGUI();
|
||||||
|
|
||||||
|
serializedObject.Update();
|
||||||
|
|
||||||
|
ResourceModule t = (ResourceModule)target;
|
||||||
|
|
||||||
|
EditorGUI.BeginDisabledGroup(EditorApplication.isPlayingOrWillChangePlaymode);
|
||||||
|
{
|
||||||
|
if (EditorApplication.isPlaying && IsPrefabInHierarchy(t.gameObject))
|
||||||
|
{
|
||||||
|
EditorGUILayout.EnumPopup("Resource Mode", t.playMode);
|
||||||
|
|
||||||
|
EditorGUILayout.EnumPopup("VerifyLevel", t.verifyLevel);
|
||||||
|
|
||||||
|
_buildPackageNames = GetBuildPackageNames();
|
||||||
|
if (_buildPackageNames.Count > 0)
|
||||||
|
{
|
||||||
|
GUILayout.Label(_buildPackageNames[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// 资源模式
|
||||||
|
int selectedIndex = EditorGUILayout.Popup("Resource Mode", m_ResourceModeIndex, ResourceModeNames);
|
||||||
|
if (selectedIndex != m_ResourceModeIndex)
|
||||||
|
{
|
||||||
|
m_ResourceModeIndex = selectedIndex;
|
||||||
|
m_PlayMode.enumValueIndex = selectedIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
int selectedVerifyIndex = EditorGUILayout.Popup("VerifyLevel", m_VerifyIndex, VerifyLevelNames);
|
||||||
|
if (selectedVerifyIndex != m_VerifyIndex)
|
||||||
|
{
|
||||||
|
m_VerifyIndex = selectedVerifyIndex;
|
||||||
|
m_VerifyLevel.enumValueIndex = selectedVerifyIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 包裹名称列表
|
||||||
|
_buildPackageNames = GetBuildPackageNames();
|
||||||
|
if (_buildPackageNames.Count > 0)
|
||||||
|
{
|
||||||
|
int selectedPackageIndex = EditorGUILayout.Popup("Used Packages", m_PackageIndex, _buildPackageNames.ToArray());
|
||||||
|
if (selectedPackageIndex != m_PackageIndex)
|
||||||
|
{
|
||||||
|
m_PackageIndex = selectedPackageIndex;
|
||||||
|
m_PlayMode.enumValueIndex = selectedIndex + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int defaultIndex = GetDefaultPackageIndex(AssetBundleBuilderSettingData.Setting.BuildPackage);
|
||||||
|
_buildPackageField = new PopupField<string>(_buildPackageNames, defaultIndex);
|
||||||
|
_buildPackageField.label = "Build Package";
|
||||||
|
_buildPackageField.style.width = 350;
|
||||||
|
_buildPackageField.RegisterValueChangedCallback(evt =>
|
||||||
|
{
|
||||||
|
AssetBundleBuilderSettingData.IsDirty = true;
|
||||||
|
AssetBundleBuilderSettingData.Setting.BuildPackage = _buildPackageField.value;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
GUILayout.Label("Please Create Packages with YooAssets ...!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
m_ReadWritePathType.enumValueIndex = (int)(ReadWritePathType)EditorGUILayout.EnumPopup("Read-Write Path Type", t.ReadWritePathType);
|
||||||
|
}
|
||||||
|
EditorGUI.EndDisabledGroup();
|
||||||
|
|
||||||
|
int milliseconds = EditorGUILayout.DelayedIntField("Milliseconds", m_Milliseconds.intValue);
|
||||||
|
if (milliseconds != m_Milliseconds.intValue)
|
||||||
|
{
|
||||||
|
if (EditorApplication.isPlaying)
|
||||||
|
{
|
||||||
|
t.milliseconds = milliseconds;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_Milliseconds.longValue = milliseconds;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
float minUnloadUnusedAssetsInterval = EditorGUILayout.Slider("Min Unload Unused Assets Interval", m_MinUnloadUnusedAssetsInterval.floatValue, 0f, 3600f);
|
||||||
|
if (Math.Abs(minUnloadUnusedAssetsInterval - m_MinUnloadUnusedAssetsInterval.floatValue) > 0.001f)
|
||||||
|
{
|
||||||
|
if (EditorApplication.isPlaying)
|
||||||
|
{
|
||||||
|
t.MinUnloadUnusedAssetsInterval = minUnloadUnusedAssetsInterval;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_MinUnloadUnusedAssetsInterval.floatValue = minUnloadUnusedAssetsInterval;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
float maxUnloadUnusedAssetsInterval = EditorGUILayout.Slider("Max Unload Unused Assets Interval", m_MaxUnloadUnusedAssetsInterval.floatValue, 0f, 3600f);
|
||||||
|
if (Math.Abs(maxUnloadUnusedAssetsInterval - m_MaxUnloadUnusedAssetsInterval.floatValue) > 0.001f)
|
||||||
|
{
|
||||||
|
if (EditorApplication.isPlaying)
|
||||||
|
{
|
||||||
|
t.MaxUnloadUnusedAssetsInterval = maxUnloadUnusedAssetsInterval;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_MaxUnloadUnusedAssetsInterval.floatValue = maxUnloadUnusedAssetsInterval;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
float downloadingMaxNum = EditorGUILayout.Slider("Max Downloading Num", m_DownloadingMaxNum.intValue, 1f, 48f);
|
||||||
|
if (Math.Abs(downloadingMaxNum - m_DownloadingMaxNum.intValue) > 0.001f)
|
||||||
|
{
|
||||||
|
if (EditorApplication.isPlaying)
|
||||||
|
{
|
||||||
|
t.downloadingMaxNum = (int)downloadingMaxNum;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_DownloadingMaxNum.intValue = (int)downloadingMaxNum;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
float failedTryAgain = EditorGUILayout.Slider("Max FailedTryAgain Count", m_FailedTryAgain.intValue, 1f, 48f);
|
||||||
|
if (Math.Abs(failedTryAgain - m_FailedTryAgain.intValue) > 0.001f)
|
||||||
|
{
|
||||||
|
if (EditorApplication.isPlaying)
|
||||||
|
{
|
||||||
|
t.failedTryAgain = (int)failedTryAgain;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_FailedTryAgain.intValue = (int)failedTryAgain;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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("Applicable Game Version", t.ApplicableGameVersion ?? "<Unknwon>");
|
||||||
|
EditorGUILayout.LabelField("Internal Resource Version", t.InternalResourceVersion.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
|
serializedObject.ApplyModifiedProperties();
|
||||||
|
|
||||||
|
Repaint();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnCompileComplete()
|
||||||
|
{
|
||||||
|
base.OnCompileComplete();
|
||||||
|
|
||||||
|
RefreshTypeNames();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void RefreshTypeNames()
|
||||||
|
{
|
||||||
|
serializedObject.ApplyModifiedProperties();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 构建包裹相关
|
||||||
|
private int GetDefaultPackageIndex(string packageName)
|
||||||
|
{
|
||||||
|
for (int index = 0; index < _buildPackageNames.Count; index++)
|
||||||
|
{
|
||||||
|
if (_buildPackageNames[index] == packageName)
|
||||||
|
{
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
AssetBundleBuilderSettingData.IsDirty = true;
|
||||||
|
AssetBundleBuilderSettingData.Setting.BuildPackage = _buildPackageNames[0];
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<string> GetBuildPackageNames()
|
||||||
|
{
|
||||||
|
List<string> result = new List<string>();
|
||||||
|
foreach (var package in AssetBundleCollectorSettingData.Setting.Packages)
|
||||||
|
{
|
||||||
|
result.Add(package.PackageName);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 78be88e0b69747ffbbcf360389dd4d4b
|
||||||
|
timeCreated: 1680590523
|
@@ -2,7 +2,8 @@
|
|||||||
"name": "TEngine.Editor",
|
"name": "TEngine.Editor",
|
||||||
"rootNamespace": "",
|
"rootNamespace": "",
|
||||||
"references": [
|
"references": [
|
||||||
"TEngine.Runtime"
|
"TEngine.Runtime",
|
||||||
|
"YooAsset.Editor"
|
||||||
],
|
],
|
||||||
"includePlatforms": [
|
"includePlatforms": [
|
||||||
"Editor"
|
"Editor"
|
||||||
|
@@ -11,7 +11,7 @@ namespace TEngine
|
|||||||
{
|
{
|
||||||
private RootModule _mRootModule = null;
|
private RootModule _mRootModule = null;
|
||||||
|
|
||||||
private ResourceModuleBase _mResourceModuleBase = null;
|
private ResourceModule _mResourceModule = null;
|
||||||
|
|
||||||
public override void Initialize(params object[] args)
|
public override void Initialize(params object[] args)
|
||||||
{
|
{
|
||||||
@@ -22,8 +22,8 @@ namespace TEngine
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_mResourceModuleBase = GameEntry.GetModule<ResourceModuleBase>();
|
_mResourceModule = GameEntry.GetModule<ResourceModule>();
|
||||||
if (_mResourceModuleBase == null)
|
if (_mResourceModule == null)
|
||||||
{
|
{
|
||||||
Log.Fatal("Resource component is invalid.");
|
Log.Fatal("Resource component is invalid.");
|
||||||
return;
|
return;
|
||||||
@@ -44,7 +44,7 @@ namespace TEngine
|
|||||||
#endif
|
#endif
|
||||||
DrawItem("Game Framework Version", Version.GameFrameworkVersion);
|
DrawItem("Game Framework Version", Version.GameFrameworkVersion);
|
||||||
DrawItem("Game Version", Utility.Text.Format("{0} ({1})", Version.GameVersion, Version.InternalGameVersion));
|
DrawItem("Game Version", Utility.Text.Format("{0} ({1})", Version.GameVersion, Version.InternalGameVersion));
|
||||||
DrawItem("Resource Version", (string.IsNullOrEmpty(_mResourceModuleBase.ApplicableGameVersion) ? "Unknown" : Utility.Text.Format("{0} ({1})", _mResourceModuleBase.ApplicableGameVersion, _mResourceModuleBase.InternalResourceVersion)));
|
DrawItem("Resource Version", (string.IsNullOrEmpty(_mResourceModule.ApplicableGameVersion) ? "Unknown" : Utility.Text.Format("{0} ({1})", _mResourceModule.ApplicableGameVersion, _mResourceModule.InternalResourceVersion)));
|
||||||
DrawItem("Application Version", Application.version);
|
DrawItem("Application Version", Application.version);
|
||||||
DrawItem("Unity Version", Application.unityVersion);
|
DrawItem("Unity Version", Application.unityVersion);
|
||||||
DrawItem("Platform", Application.platform.ToString());
|
DrawItem("Platform", Application.platform.ToString());
|
||||||
|
@@ -25,7 +25,7 @@ namespace TEngine
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ResourceModuleBase resourceCompoent = GameEntry.GetModule<ResourceModuleBase>();
|
ResourceModule resourceCompoent = GameEntry.GetModule<ResourceModule>();
|
||||||
if (resourceCompoent != null)
|
if (resourceCompoent != null)
|
||||||
{
|
{
|
||||||
if (GUILayout.Button("Unload Unused Assets", GUILayout.Height(30f)))
|
if (GUILayout.Button("Unload Unused Assets", GUILayout.Height(30f)))
|
||||||
|
@@ -106,19 +106,21 @@ namespace TEngine
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 同步加载资源。
|
/// 同步加载资源。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <param name="handle">资源操作句柄。</param>
|
||||||
/// <param name="assetName">要加载资源的名称。</param>
|
/// <param name="assetName">要加载资源的名称。</param>
|
||||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||||
/// <returns>资源实例。</returns>
|
/// <returns>资源实例。</returns>
|
||||||
T LoadAsset<T>(string assetName) where T : UnityEngine.Object;
|
T LoadAsset<T>(string assetName,out AssetOperationHandle handle) where T : UnityEngine.Object;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 同步加载资源。
|
/// 同步加载资源。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="assetName">要加载资源的名称。</param>
|
/// <param name="assetName">要加载资源的名称。</param>
|
||||||
|
/// <param name="handle">资源操作句柄。</param>
|
||||||
/// <param name="parent">父节点位置。</param>
|
/// <param name="parent">父节点位置。</param>
|
||||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||||
/// <returns>资源实例。</returns>
|
/// <returns>资源实例。</returns>
|
||||||
T LoadAsset<T>(string assetName, Transform parent) where T : UnityEngine.Object;
|
T LoadAsset<T>(string assetName, Transform parent,out AssetOperationHandle handle) where T : UnityEngine.Object;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 异步加载资源。
|
/// 异步加载资源。
|
||||||
|
@@ -165,12 +165,12 @@ namespace TEngine
|
|||||||
throw new System.NotImplementedException();
|
throw new System.NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public T LoadAsset<T>(string assetName) where T : Object
|
public T LoadAsset<T>(string assetName,out AssetOperationHandle handle) where T : Object
|
||||||
{
|
{
|
||||||
throw new System.NotImplementedException();
|
throw new System.NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public T LoadAsset<T>(string assetName, Transform parent) where T : Object
|
public T LoadAsset<T>(string assetName, Transform parent,out AssetOperationHandle handle) where T : Object
|
||||||
{
|
{
|
||||||
throw new System.NotImplementedException();
|
throw new System.NotImplementedException();
|
||||||
}
|
}
|
||||||
|
284
Assets/TEngine/Runtime/GameFramework/Resource/ResourceModule.cs
Normal file
284
Assets/TEngine/Runtime/GameFramework/Resource/ResourceModule.cs
Normal file
@@ -0,0 +1,284 @@
|
|||||||
|
using System;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.Serialization;
|
||||||
|
using YooAsset;
|
||||||
|
|
||||||
|
namespace TEngine
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 资源模块。
|
||||||
|
/// </summary>
|
||||||
|
[DisallowMultipleComponent]
|
||||||
|
public class ResourceModule : GameFrameworkModuleBase
|
||||||
|
{
|
||||||
|
#region Propreties
|
||||||
|
/// <summary>
|
||||||
|
/// 获取当前资源适用的游戏版本号。
|
||||||
|
/// </summary>
|
||||||
|
public string ApplicableGameVersion => m_ResourceManager?.ApplicableGameVersion ?? "Unknown";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取当前内部资源版本号。
|
||||||
|
/// </summary>
|
||||||
|
public int InternalResourceVersion => m_ResourceManager?.InternalResourceVersion ?? 0;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 默认资源加载优先级。
|
||||||
|
/// </summary>
|
||||||
|
public const int DefaultPriority = 0;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 当前最新的包裹版本。
|
||||||
|
/// </summary>
|
||||||
|
public string PackageVersion { set; get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 资源包名称。
|
||||||
|
/// </summary>
|
||||||
|
public string packageName = "DefaultPackage";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 资源系统运行模式。
|
||||||
|
/// </summary>
|
||||||
|
public EPlayMode playMode = EPlayMode.EditorSimulateMode;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 下载文件校验等级。
|
||||||
|
/// </summary>
|
||||||
|
public EVerifyLevel verifyLevel = EVerifyLevel.Middle;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 资源下载器,用于下载当前资源版本所有的资源包文件。
|
||||||
|
/// </summary>
|
||||||
|
public ResourceDownloaderOperation Downloader { get; set; }
|
||||||
|
|
||||||
|
[SerializeField]
|
||||||
|
private ReadWritePathType readWritePathType = ReadWritePathType.Unspecified;
|
||||||
|
|
||||||
|
[SerializeField]
|
||||||
|
private float minUnloadUnusedAssetsInterval = 60f;
|
||||||
|
|
||||||
|
[SerializeField]
|
||||||
|
private float maxUnloadUnusedAssetsInterval = 300f;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 设置异步系统参数,每帧执行消耗的最大时间切片(单位:毫秒)
|
||||||
|
/// </summary>
|
||||||
|
public long milliseconds = 30;
|
||||||
|
public int downloadingMaxNum = 3;
|
||||||
|
public int failedTryAgain = 3;
|
||||||
|
|
||||||
|
private IResourceManager m_ResourceManager;
|
||||||
|
private AsyncOperation m_AsyncOperation = null;
|
||||||
|
private bool m_ForceUnloadUnusedAssets = false;
|
||||||
|
private bool m_PreorderUnloadUnusedAssets = false;
|
||||||
|
private bool m_PerformGCCollect = false;
|
||||||
|
private float m_LastUnloadUnusedAssetsOperationElapseSeconds = 0f;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取或设置同时最大下载数目。
|
||||||
|
/// </summary>
|
||||||
|
public int DownloadingMaxNum
|
||||||
|
{
|
||||||
|
get => downloadingMaxNum;
|
||||||
|
set => downloadingMaxNum = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 失败尝试数目。
|
||||||
|
/// </summary>
|
||||||
|
public int FailedTryAgain
|
||||||
|
{
|
||||||
|
get => failedTryAgain;
|
||||||
|
set => failedTryAgain = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取资源读写路径类型。
|
||||||
|
/// </summary>
|
||||||
|
public ReadWritePathType ReadWritePathType => readWritePathType;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取或设置无用资源释放的最小间隔时间,以秒为单位。
|
||||||
|
/// </summary>
|
||||||
|
public float MinUnloadUnusedAssetsInterval
|
||||||
|
{
|
||||||
|
get => minUnloadUnusedAssetsInterval;
|
||||||
|
set => minUnloadUnusedAssetsInterval = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取或设置无用资源释放的最大间隔时间,以秒为单位。
|
||||||
|
/// </summary>
|
||||||
|
public float MaxUnloadUnusedAssetsInterval
|
||||||
|
{
|
||||||
|
get => maxUnloadUnusedAssetsInterval;
|
||||||
|
set => maxUnloadUnusedAssetsInterval = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取无用资源释放的等待时长,以秒为单位。
|
||||||
|
/// </summary>
|
||||||
|
public float LastUnloadUnusedAssetsOperationElapseSeconds => m_LastUnloadUnusedAssetsOperationElapseSeconds;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取资源只读路径。
|
||||||
|
/// </summary>
|
||||||
|
public string ReadOnlyPath => m_ResourceManager.ReadOnlyPath;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取资源读写路径。
|
||||||
|
/// </summary>
|
||||||
|
public string ReadWritePath => m_ResourceManager.ReadWritePath;
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private void Start()
|
||||||
|
{
|
||||||
|
RootModule baseComponent = GameEntry.GetModule<RootModule>();
|
||||||
|
if (baseComponent == null)
|
||||||
|
{
|
||||||
|
Log.Fatal("Base component is invalid.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_ResourceManager = GameFrameworkEntry.GetModule<IResourceManager>();
|
||||||
|
if (m_ResourceManager == null)
|
||||||
|
{
|
||||||
|
Log.Fatal("YooAssetsManager component is invalid.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (playMode == EPlayMode.EditorSimulateMode)
|
||||||
|
{
|
||||||
|
Log.Info("During this run, Game Framework will use editor resource files, which you should validate first.");
|
||||||
|
#if !UNITY_EDITOR
|
||||||
|
playMode = EPlayMode.OfflinePlayMode;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
m_ResourceManager.SetReadOnlyPath(Application.streamingAssetsPath);
|
||||||
|
if (readWritePathType == ReadWritePathType.TemporaryCache)
|
||||||
|
{
|
||||||
|
m_ResourceManager.SetReadWritePath(Application.temporaryCachePath);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (readWritePathType == ReadWritePathType.Unspecified)
|
||||||
|
{
|
||||||
|
readWritePathType = ReadWritePathType.PersistentData;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_ResourceManager.SetReadWritePath(Application.persistentDataPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
m_ResourceManager.PackageName = packageName;
|
||||||
|
m_ResourceManager.PlayMode = playMode;
|
||||||
|
m_ResourceManager.VerifyLevel = verifyLevel;
|
||||||
|
m_ResourceManager.Milliseconds = milliseconds;
|
||||||
|
m_ResourceManager.Initialize();
|
||||||
|
Log.Info($"AssetsComponent Run Mode:{playMode}");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 初始化操作。
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public InitializationOperation InitPackage()
|
||||||
|
{
|
||||||
|
return m_ResourceManager.InitPackage();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 异步更新最新包的版本。
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="appendTimeTicks"></param>
|
||||||
|
/// <param name="timeout">超时时间。</param>
|
||||||
|
/// <returns>请求远端包裹的最新版本操作句柄。</returns>
|
||||||
|
public UpdatePackageVersionOperation UpdatePackageVersionAsync(bool appendTimeTicks = true, int timeout = 60)
|
||||||
|
{
|
||||||
|
var package = YooAssets.GetPackage(packageName);
|
||||||
|
return package.UpdatePackageVersionAsync(appendTimeTicks,timeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 异步更新最新包的Manifest文件。
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="packageVersion">包版本信息。</param>
|
||||||
|
/// <param name="timeout">超时时间。</param>
|
||||||
|
/// <returns>向远端请求并更新清单操作句柄。</returns>
|
||||||
|
public UpdatePackageManifestOperation UpdatePackageManifestAsync(string packageVersion, int timeout = 60)
|
||||||
|
{
|
||||||
|
var package = YooAssets.GetPackage(packageName);
|
||||||
|
return package.UpdatePackageManifestAsync(packageVersion,timeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 创建资源下载器,用于下载当前资源版本所有的资源包文件。
|
||||||
|
/// </summary>
|
||||||
|
public ResourceDownloaderOperation CreateResourceDownloader()
|
||||||
|
{
|
||||||
|
var package = YooAssets.GetPackage(packageName);
|
||||||
|
Downloader = package.CreateResourceDownloader(downloadingMaxNum,failedTryAgain);
|
||||||
|
return Downloader;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 清理包裹未使用的缓存文件。
|
||||||
|
/// </summary>
|
||||||
|
public ClearUnusedCacheFilesOperation ClearUnusedCacheFilesAsync()
|
||||||
|
{
|
||||||
|
var package = YooAssets.GetPackage(packageName);
|
||||||
|
return package.ClearUnusedCacheFilesAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 清理沙盒路径。
|
||||||
|
/// </summary>
|
||||||
|
public void ClearSandbox()
|
||||||
|
{
|
||||||
|
YooAssets.ClearSandbox();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 强制执行释放未被使用的资源。
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="performGCCollect">是否使用垃圾回收。</param>
|
||||||
|
public void ForceUnloadUnusedAssets(bool performGCCollect)
|
||||||
|
{
|
||||||
|
m_ForceUnloadUnusedAssets = true;
|
||||||
|
if (performGCCollect)
|
||||||
|
{
|
||||||
|
m_PerformGCCollect = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 资源模块外部轮询(释放无用资源)。
|
||||||
|
/// </summary>
|
||||||
|
private void Update()
|
||||||
|
{
|
||||||
|
m_LastUnloadUnusedAssetsOperationElapseSeconds += Time.unscaledDeltaTime;
|
||||||
|
if (m_AsyncOperation == null && (m_ForceUnloadUnusedAssets || m_LastUnloadUnusedAssetsOperationElapseSeconds >= maxUnloadUnusedAssetsInterval || m_PreorderUnloadUnusedAssets && m_LastUnloadUnusedAssetsOperationElapseSeconds >= minUnloadUnusedAssetsInterval))
|
||||||
|
{
|
||||||
|
Log.Info("Unload unused assets...");
|
||||||
|
m_ForceUnloadUnusedAssets = false;
|
||||||
|
m_PreorderUnloadUnusedAssets = false;
|
||||||
|
m_LastUnloadUnusedAssetsOperationElapseSeconds = 0f;
|
||||||
|
m_AsyncOperation = Resources.UnloadUnusedAssets();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_AsyncOperation is { isDone: true })
|
||||||
|
{
|
||||||
|
m_ResourceManager.UnloadUnusedAssets();
|
||||||
|
m_AsyncOperation = null;
|
||||||
|
if (m_PerformGCCollect)
|
||||||
|
{
|
||||||
|
Log.Info("GC.Collect...");
|
||||||
|
m_PerformGCCollect = false;
|
||||||
|
GC.Collect();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 6e9edd9af2004f138ce8c543a2509393
|
||||||
|
timeCreated: 1680588655
|
@@ -1,35 +0,0 @@
|
|||||||
using System;
|
|
||||||
using UnityEngine;
|
|
||||||
|
|
||||||
namespace TEngine
|
|
||||||
{
|
|
||||||
[DisallowMultipleComponent]
|
|
||||||
public class ResourceModuleBase: GameFrameworkModuleBase
|
|
||||||
{
|
|
||||||
private IResourceManager m_ResourceManager;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 获取当前资源适用的游戏版本号。
|
|
||||||
/// </summary>
|
|
||||||
public string ApplicableGameVersion => m_ResourceManager?.ApplicableGameVersion ?? "Unknown";
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 获取当前内部资源版本号。
|
|
||||||
/// </summary>
|
|
||||||
public int InternalResourceVersion => m_ResourceManager?.InternalResourceVersion ?? 0;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 强制执行释放未被使用的资源。
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="performGCCollect">是否使用垃圾回收。</param>
|
|
||||||
public void ForceUnloadUnusedAssets(bool performGCCollect)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Start()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,3 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: 77d67944806247f99024bf5307adc918
|
|
||||||
timeCreated: 1680501384
|
|
@@ -235,13 +235,13 @@ namespace TEngine
|
|||||||
throw new GameFrameworkException(Utility.Text.Format("Can not find version helper type '{0}'.", m_VersionHelperTypeName));
|
throw new GameFrameworkException(Utility.Text.Format("Can not find version helper type '{0}'.", m_VersionHelperTypeName));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEngine.Version.IVersionHelper versionHelper = (TEngine.Version.IVersionHelper)Activator.CreateInstance(versionHelperType);
|
Version.IVersionHelper versionHelper = (Version.IVersionHelper)Activator.CreateInstance(versionHelperType);
|
||||||
if (versionHelper == null)
|
if (versionHelper == null)
|
||||||
{
|
{
|
||||||
throw new GameFrameworkException(Utility.Text.Format("Can not create version helper instance '{0}'.", m_VersionHelperTypeName));
|
throw new GameFrameworkException(Utility.Text.Format("Can not create version helper instance '{0}'.", m_VersionHelperTypeName));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEngine.Version.SetVersionHelper(versionHelper);
|
Version.SetVersionHelper(versionHelper);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void InitLogHelper()
|
private void InitLogHelper()
|
||||||
@@ -324,10 +324,10 @@ namespace TEngine
|
|||||||
objectPoolModule.ReleaseAllUnused();
|
objectPoolModule.ReleaseAllUnused();
|
||||||
}
|
}
|
||||||
|
|
||||||
ResourceModuleBase resourceModuleBase = GameEntry.GetModule<ResourceModuleBase>();
|
ResourceModule ResourceModule = GameEntry.GetModule<ResourceModule>();
|
||||||
if (resourceModuleBase != null)
|
if (ResourceModule != null)
|
||||||
{
|
{
|
||||||
resourceModuleBase.ForceUnloadUnusedAssets(true);
|
ResourceModule.ForceUnloadUnusedAssets(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -7,7 +7,7 @@ namespace TEngine
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class DefaultUIWindowHelper : UIWindowHelperBase
|
public class DefaultUIWindowHelper : UIWindowHelperBase
|
||||||
{
|
{
|
||||||
private ResourceModuleBase _mResourceModuleBase = null;
|
private ResourceModule _mResourceModule = null;
|
||||||
|
|
||||||
private Vector2 m_Half = new Vector2(0.5f,0.5f);
|
private Vector2 m_Half = new Vector2(0.5f,0.5f);
|
||||||
|
|
||||||
@@ -16,8 +16,8 @@ namespace TEngine
|
|||||||
private void Start()
|
private void Start()
|
||||||
{
|
{
|
||||||
m_UILayer = LayerMask.NameToLayer("UI");
|
m_UILayer = LayerMask.NameToLayer("UI");
|
||||||
_mResourceModuleBase = GameEntry.GetModule<ResourceModuleBase>();
|
_mResourceModule = GameEntry.GetModule<ResourceModule>();
|
||||||
if (_mResourceModuleBase == null)
|
if (_mResourceModule == null)
|
||||||
{
|
{
|
||||||
Log.Fatal("Resource component is invalid.");
|
Log.Fatal("Resource component is invalid.");
|
||||||
return;
|
return;
|
||||||
|
@@ -32,7 +32,7 @@ public class GameModule:MonoBehaviour
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取资源模块。
|
/// 获取资源模块。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static ResourceModuleBase Resource { get; private set; }
|
public static ResourceModule Resource { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取配置模块。
|
/// 获取配置模块。
|
||||||
@@ -55,7 +55,7 @@ public class GameModule:MonoBehaviour
|
|||||||
Debugger = Get<DebuggerModule>();
|
Debugger = Get<DebuggerModule>();
|
||||||
Fsm = Get<FsmModule>();
|
Fsm = Get<FsmModule>();
|
||||||
ObjectPool = Get<ObjectPoolModule>();
|
ObjectPool = Get<ObjectPoolModule>();
|
||||||
Resource = Get<ResourceModuleBase>();
|
Resource = Get<ResourceModule>();
|
||||||
Setting = Get<SettingModule>();
|
Setting = Get<SettingModule>();
|
||||||
UI = Get<UIModule>();
|
UI = Get<UIModule>();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user