Пример #1
0
        public ICollection <TResult> GetNonPrimList <TSerialized, TResult>(int fbPos, ICollection <TResult> result = null) where TSerialized : struct, IFlatbufferObject where TResult : new()
        {
            try {
                UnityEngine.Profiling.Profiler.BeginSample("GetNonPrimList");
                int    bufPos       = GetBufferPos(fbPos);
                object cachedResult = FlatBufferSerializer.FindInDeserializeCache <TResult>(bufPos);
                if (cachedResult != null)
                {
                    if (cachedResult.GetType() != typeof(TResult))
                    {
                        UnityEngine.Debug.LogError("Got cached value but the types are different! Cached:" + cachedResult.GetType() + " Expected:" + typeof(TResult));
                    }
                    return((List <TResult>)cachedResult);
                }
                int listSize = GetListLength(fbPos);

                List <object> tempList = FlatBufferSerializer.poolListObject.GetList(listSize);
                // first create List<object> of all results and then pass this to the Create-method. Didn't find a better way,yet Generics with T? do not work for interfaces
                for (int i = 0; i < listSize; i++)
                {
                    tempList.Add(GetListElemAt <TSerialized>(fbPos, i));
                }
                result = FlatBufferSerializer.DeserializeList <TResult, TSerialized>(bufPos, listSize, tempList, result);
                FlatBufferSerializer.poolListObject.Release(tempList);
                return(result);
            }
            finally {
                UnityEngine.Profiling.Profiler.EndSample();
            }
        }