private static void InitializeAssetNode(AssetNode assetNode) { assetNode.Target = null; assetNode.Name = string.Empty; assetNode.ReferenceCount = 1; assetNode.LastAccessTime = Time.unscaledTime; }
protected void AddAssetToCachePool(string assetName, Object targetObj) { if (targetObj != null) { var assetNode = LoadAsset(assetName, null); if (assetNode == null) { assetNode = AssetNode.GetAssetNode(); assetNode.Target = targetObj; m_AssetCachePool.AddAssetNode(assetName, assetNode); } } else { Debug.LogError("Asset doesn't exist at ResourcesAssetManager.LoadAssetAsync,Asset name is <color=#ff0000>" + assetName + "</color>"); } }
public override void LoadAssetSync(string assetName, UnityAction <Object> loadedCallback) { var assetNode = LoadAsset(assetName, loadedCallback); if (assetNode == null) { var targetObj = m_AssetLoader.LoadAssetSync(assetName); if (targetObj != null) { assetNode = AssetNode.GetAssetNode(); assetNode.Target = targetObj; m_AssetCachePool.AddAssetNode(assetName, assetNode); SafeInvokeDoneAction(loadedCallback, assetNode.Target); } else { Debug.LogError("Asset doesn't exist at ResourcesAssetManager.LoadAssetSync,Asset name is <color=#ff0000>" + assetName + "</color>"); } } }
public void AddAssetNode(string assetName, AssetNode assetNode) { if (!m_AssetNodeIndexMap.ContainsKey(assetName)) { assetNode.LastAccessTime = Time.unscaledTime; assetNode.Name = assetName; if (m_FreeIndexList.Count > 0) { var index = m_FreeIndexList[m_FreeIndexList.Count - 1]; m_FreeIndexList.RemoveAt(m_FreeIndexList.Count - 1); m_AssetNodeList[index] = assetNode; m_AssetNodeIndexMap.Add(assetName, index); } else { m_AssetNodeList.Add(assetNode); m_AssetNodeIndexMap.Add(assetName, m_AssetNodeList.Count - 1); } } }
IEnumerator WaitCheckExpiredAssetDone() { var checkNum = 0; for (int i = 0; i < m_AssetNodeList.Count; ++i) { if (m_AssetNodeList[i] != null) { var deltaTime = Time.unscaledTime - m_AssetNodeList[i].LastAccessTime; if (deltaTime >= AssetLoadConfig.AssetExpirationTime) { --m_AssetNodeList[i].ReferenceCount; if (deltaTime >= AssetLoadConfig.AssetReleaseExpirationTime) { m_AssetNodeList[i].ReferenceCount = 0; } } if (m_AssetNodeList[i].ReferenceCount <= 0) { var assetNode = m_AssetNodeList[i]; RemoveAssetNode(assetNode.Name); m_RecycleAssetEvent.Invoke(assetNode.Name, assetNode.Target); AssetNode.ReleaseAssetNode(assetNode); } ++checkNum; if (checkNum >= AssetLoadConfig.CheckAssetNumPerFrame) { checkNum = 0; yield return(null); } } } m_CheckingExpiredAsset = false; m_CheckAssetDoneEvent.Invoke(); }
public AssetNode GetAssetNode(string assetName) { if (m_RecycleAssetIndexMap.ContainsKey(assetName)) { var assetReference = m_RecycleAssetList[m_RecycleAssetIndexMap[assetName]]; if (assetReference.IsAlive()) { var target = assetReference.GetTarget() as Object; if (target == null) { RemoveAsset(assetName); return(null); } var assetNode = AssetNode.GetAssetNode(); assetNode.Target = assetReference.GetTarget() as Object; assetNode.LastAccessTime = Time.unscaledTime; return(assetNode); } RemoveAsset(assetName); } return(null); }
public static void ReleaseAssetNode(AssetNode assetNode) { assetNode.Target = null; s_AssetNodes.Release(assetNode); }