174 lines
4.1 KiB
C#
174 lines
4.1 KiB
C#
// ***********************************************************************
|
|
// Assembly : Unity
|
|
// Author : Kimch
|
|
// Created :
|
|
//
|
|
// Last Modified By : Kimch
|
|
// Last Modified On :
|
|
// ***********************************************************************
|
|
// <copyright file= "AssetProxy" company=""></copyright>
|
|
// <summary></summary>
|
|
// ***********************************************************************
|
|
#if UNITY_EDITOR
|
|
#define USE_ADDRESSABLES
|
|
//#define USE_ASSETDATABASE
|
|
#else
|
|
#endif
|
|
|
|
namespace G
|
|
{
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.ResourceManagement.AsyncOperations;
|
|
|
|
partial class AssetProxy
|
|
{
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
private readonly Dictionary<string, Dictionary<string, AsyncOperationHandle>> _autoReleasePools = new Dictionary<string, Dictionary<string, AsyncOperationHandle>>();
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="pool"></param>
|
|
public void CreateReleasePool(string pool)
|
|
{
|
|
if (!string.IsNullOrEmpty(pool) && !_autoReleasePools.ContainsKey(pool))
|
|
{
|
|
var releasePool = new Dictionary<string, AsyncOperationHandle>();
|
|
_autoReleasePools.Add(pool, releasePool);
|
|
}
|
|
else
|
|
{
|
|
Debug.LogWarning($"Auto release pool ({pool}) exist.");
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="pool"></param>
|
|
public bool RemoveReleasePool(string pool)
|
|
{
|
|
if (_autoReleasePools.TryGetValue(pool, out Dictionary<string, AsyncOperationHandle> releasePool))
|
|
{
|
|
_autoReleasePools.Remove(pool);
|
|
foreach (var item in releasePool)
|
|
{
|
|
Release(item.Value);
|
|
}
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="key"></param>
|
|
/// <param name="value"></param>
|
|
/// <param name="pool"></param>
|
|
private void AddHandleToReleasePool(string key, AsyncOperationHandle value, string pool)
|
|
{
|
|
if (_autoReleasePools.TryGetValue(pool, out Dictionary<string, AsyncOperationHandle> releasePool))
|
|
{
|
|
releasePool.Add(key, value);
|
|
}
|
|
else
|
|
{
|
|
Debug.LogWarning($"Auto release pool ({pool}) not exist.");
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="key"></param>
|
|
/// <param name="pool"></param>
|
|
private void RemoveHandleInReleasePool(string key, string pool)
|
|
{
|
|
if (_autoReleasePools.TryGetValue(pool, out Dictionary<string, AsyncOperationHandle> releasePool))
|
|
{
|
|
releasePool.Remove(key);
|
|
}
|
|
else
|
|
{
|
|
Debug.LogWarning($"Auto release pool ({pool}) not exist.");
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="key"></param>
|
|
/// <param name="value"></param>
|
|
/// <param name="pool"></param>
|
|
/// <returns></returns>
|
|
private bool TryGetHandleInReleasePool(string key, out AsyncOperationHandle value, string pool)
|
|
{
|
|
if (_autoReleasePools.TryGetValue(pool, out Dictionary<string, AsyncOperationHandle> releasePool))
|
|
{
|
|
return releasePool.TryGetValue(key, out value);
|
|
}
|
|
else
|
|
{
|
|
Debug.LogWarning($"Auto release pool ({pool}) not exist.");
|
|
value = default;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
class PoolInstance
|
|
{
|
|
public int status;
|
|
public string key;
|
|
public AsyncOperationHandle<GameObject> handle;
|
|
|
|
public GameObject go => handle.Result;
|
|
}
|
|
|
|
private void AddPoolInstance(string key, AsyncOperationHandle<GameObject> handle)
|
|
{
|
|
if (!_poolInstanceNodes.ContainsKey(key))
|
|
{
|
|
var node = _poolInstances.AddLast(new PoolInstance
|
|
{
|
|
handle = handle,
|
|
status = 0,
|
|
});
|
|
_poolInstanceNodes.Add(key, node);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="key"></param>
|
|
private void ReleasePoolInstance(string key)
|
|
{
|
|
if (_poolInstanceNodes.TryGetValue(key, out var result))
|
|
{
|
|
result.Value.status = Time.frameCount;
|
|
_poolInstanceNodes.Remove(key);
|
|
}
|
|
}
|
|
|
|
Dictionary<string, LinkedListNode<PoolInstance>> _poolInstanceNodes = new Dictionary<string, LinkedListNode<PoolInstance>>();
|
|
private LinkedList<PoolInstance> _poolInstances = new LinkedList<PoolInstance>();
|
|
|
|
private void UpdatePool()
|
|
{
|
|
|
|
}
|
|
|
|
void OnLowMemoryCallback()
|
|
{
|
|
|
|
}
|
|
}
|
|
}
|