Remove AutoReleaseGameObjectHandle param.

移除自动释放资源对象句柄的功能。
This commit is contained in:
hevinci
2022-06-25 12:09:20 +08:00
parent 6471b237ce
commit fbb9bff3c7
3 changed files with 5 additions and 86 deletions
@@ -10,12 +10,10 @@ namespace YooAsset
{
private static readonly List<AssetBundleLoaderBase> _loaders = new List<AssetBundleLoaderBase>(1000);
private static readonly List<ProviderBase> _providers = new List<ProviderBase>(1000);
private static readonly HashSet<AssetOperationHandle> _trackGameObjectHandles = new HashSet<AssetOperationHandle>();
private static readonly Dictionary<string, SceneOperationHandle> _sceneHandles = new Dictionary<string, SceneOperationHandle>(100);
private static bool _simulationOnEditor;
private static int _loadingMaxNumber;
public static bool AutoReleaseGameObjectHandle { private set; get; }
public static IDecryptionServices DecryptionServices { private set; get; }
public static IBundleServices BundleServices { private set; get; }
@@ -24,11 +22,10 @@ namespace YooAsset
/// 初始化
/// 注意:在使用AssetSystem之前需要初始化
/// </summary>
public static void Initialize(bool simulationOnEditor, int loadingMaxNumber, bool autoReleaseGameObjectHandle, IDecryptionServices decryptionServices, IBundleServices bundleServices)
public static void Initialize(bool simulationOnEditor, int loadingMaxNumber, IDecryptionServices decryptionServices, IBundleServices bundleServices)
{
_simulationOnEditor = simulationOnEditor;
_loadingMaxNumber = loadingMaxNumber;
AutoReleaseGameObjectHandle = autoReleaseGameObjectHandle;
DecryptionServices = decryptionServices;
BundleServices = bundleServices;
}
@@ -84,11 +81,6 @@ namespace YooAsset
/// </summary>
public static void UnloadUnusedAssets()
{
if (AutoReleaseGameObjectHandle)
{
CheckAutoReleaseGameObjectHandle();
}
if (_simulationOnEditor)
{
for (int i = _providers.Count - 1; i >= 0; i--)
@@ -229,29 +221,6 @@ namespace YooAsset
return provider.CreateHandle<SubAssetsOperationHandle>();
}
/// <summary>
/// 添加自动释放的游戏对象句柄
/// </summary>
public static void AddAutoReleaseGameObjectHandle(AssetOperationHandle handle)
{
if (_trackGameObjectHandles.Contains(handle) == false)
_trackGameObjectHandles.Add(handle);
}
private static void CheckAutoReleaseGameObjectHandle()
{
List<AssetOperationHandle> removeList = new List<AssetOperationHandle>();
foreach (var trackHandle in _trackGameObjectHandles)
{
trackHandle.CheckAutoReleaseHandle();
if (trackHandle.IsValidNoWarning == false)
removeList.Add(trackHandle);
}
foreach (var removeHandle in removeList)
{
_trackGameObjectHandles.Remove(removeHandle);
}
}
internal static void UnloadSubScene(ProviderBase provider)
{
string providerGUID = provider.MainAssetInfo.ProviderGUID;
@@ -133,57 +133,13 @@ namespace YooAsset
else
result = UnityEngine.Object.Instantiate(Provider.AssetObject as GameObject, parent);
}
if (AssetSystem.AutoReleaseGameObjectHandle)
{
AddTrackGameObject(result);
}
return result;
}
private InstantiateOperation InstantiateAsyncInternal(Vector3 position, Quaternion rotation, Transform parent, bool setPositionRotation)
{
InstantiateOperation operation = new InstantiateOperation(this, position, rotation, parent, setPositionRotation);
OperationSystem.StartOperaiton(operation);
if (AssetSystem.AutoReleaseGameObjectHandle)
{
operation.Completed += InstantiateOperationCompleted;
}
return operation;
}
#region 资源对象句柄相关
private readonly HashSet<GameObject> _trackGameObjects = new HashSet<GameObject>();
private void InstantiateOperationCompleted(AsyncOperationBase obj)
{
if (obj.Status == EOperationStatus.Succeed)
{
var op = obj as InstantiateOperation;
AddTrackGameObject(op.Result);
}
}
private void AddTrackGameObject(GameObject go)
{
if (go != null)
{
_trackGameObjects.Add(go);
AssetSystem.AddAutoReleaseGameObjectHandle(this);
}
}
internal void CheckAutoReleaseHandle()
{
if (IsValidNoWarning == false)
return;
if (_trackGameObjects.Count == 0)
return;
foreach (var go in _trackGameObjects)
{
if (go != null)
return;
}
ReleaseInternal();
}
#endregion
}
}