//private readonly object[] _listPool = new object[64];//可能造成多线程读写问题 public List <T> GetComponents <T>(int componentType, Func <MEntity, bool> condition = null) where T : MComponent { #if DEBUG MEntity.CheckComponentParams <T>(componentType); #endif int index = componentType; //UnityEngine.Debug.Log("_listPool[index]:"+ _listPool[index]); List <T> ret = new List <T>();//List<T>);_listPool[index]; //if (ret == null) //{ // ret = new List<T>(128); // _listPool[index] = ret; //} //ret.Clear(); var list = _componentGroup.GetComponents(componentType); int n = list.Count; int n2 = n; for (int i = n - 1; i >= 0; i--) { var c = list[i]; //延迟删除 if (c.Entity == null || !_entities.ContainsKey(c.Entity.Id)) { //和最后一个交换, 然后移除最后一个 n2--; list[i] = list[n2]; list.RemoveAt(n2); } else { if (condition == null || condition.Invoke(c.Entity)) { ret.Add(c as T); } } } return(ret); }