using System; using System.Collections.Generic; namespace ET { [FriendClass(typeof(UnitCacheComponent))] public class Other2UnitCache_GetUnitHandler : AMActorRpcHandler { protected override async ETTask Run(Scene scene, Other2UnitCache_GetUnit request, UnitCache2Other_GetUnit response, Action reply) { UnitCacheComponent unitCacheComponent = scene.GetComponent(); Dictionary dictionary = MonoPool.Instance.Fetch(typeof (Dictionary)) as Dictionary; try { // 先将所有需要记录的Component字典初始化置空 if (request.ComponentNameList.Count == 0) { dictionary.Add(nameof (Unit), null); foreach (var s in unitCacheComponent.UnitCacheKeyList) { dictionary.Add(s, null); } } else { foreach (var s in request.ComponentNameList) { dictionary.Add(s, null); } } foreach (var key in dictionary.Keys) { Entity entity = await unitCacheComponent.Get(request.UnitId, key); dictionary[key] = entity; } response.ComponentNameList.AddRange(dictionary.Keys); response.EntityList.AddRange(dictionary.Values); } finally { dictionary.Clear(); MonoPool.Instance.Recycle(dictionary); } reply(); await ETTask.CompletedTask; } } }