// ***********************************************************************
// Assembly : Unity
// Author : Kimch
// Created :
//
// Last Modified By : Kimch
// Last Modified On :
// ***********************************************************************
//
//
// ***********************************************************************
#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
{
///
///
///
private readonly Dictionary> _autoReleasePools = new Dictionary>();
///
///
///
///
public void CreateReleasePool(string pool)
{
if (!string.IsNullOrEmpty(pool) && !_autoReleasePools.ContainsKey(pool))
{
var releasePool = new Dictionary();
_autoReleasePools.Add(pool, releasePool);
}
else
{
Debug.LogWarning($"Auto release pool ({pool}) exist.");
}
}
///
///
///
///
public bool RemoveReleasePool(string pool)
{
if (_autoReleasePools.TryGetValue(pool, out Dictionary releasePool))
{
_autoReleasePools.Remove(pool);
foreach (var item in releasePool)
{
Release(item.Value);
}
return true;
}
else
{
return false;
}
}
///
///
///
///
///
///
private void AddHandleToReleasePool(string key, AsyncOperationHandle value, string pool)
{
if (_autoReleasePools.TryGetValue(pool, out Dictionary releasePool))
{
releasePool.Add(key, value);
}
else
{
Debug.LogWarning($"Auto release pool ({pool}) not exist.");
}
}
///
///
///
///
///
private void RemoveHandleInReleasePool(string key, string pool)
{
if (_autoReleasePools.TryGetValue(pool, out Dictionary releasePool))
{
releasePool.Remove(key);
}
else
{
Debug.LogWarning($"Auto release pool ({pool}) not exist.");
}
}
///
///
///
///
///
///
///
private bool TryGetHandleInReleasePool(string key, out AsyncOperationHandle value, string pool)
{
if (_autoReleasePools.TryGetValue(pool, out Dictionary 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 handle;
public GameObject go => handle.Result;
}
private void AddPoolInstance(string key, AsyncOperationHandle handle)
{
if (!_poolInstanceNodes.ContainsKey(key))
{
var node = _poolInstances.AddLast(new PoolInstance
{
handle = handle,
status = 0,
});
_poolInstanceNodes.Add(key, node);
}
}
///
///
///
///
private void ReleasePoolInstance(string key)
{
if (_poolInstanceNodes.TryGetValue(key, out var result))
{
result.Value.status = Time.frameCount;
_poolInstanceNodes.Remove(key);
}
}
Dictionary> _poolInstanceNodes = new Dictionary>();
private LinkedList _poolInstances = new LinkedList();
private void UpdatePool()
{
}
void OnLowMemoryCallback()
{
}
}
}