Пример #1
0
        public T GetOrCreate <T>(int fbPos) where T : new()
        {
            try {
                UnityEngine.Profiling.Profiler.BeginSample("GetOrCreate");

                if (typeof(T) == typeof(UnityEngine.Vector2))
                {
                    return(GetOrCreate <T, Serial.FBVector2>(fbPos));
                }
                else if (typeof(T) == typeof(UnityEngine.Vector3))
                {
                    return(GetOrCreate <T, Serial.FBVector3>(fbPos));
                }
                else if (typeof(T) == typeof(UnityEngine.Vector4))
                {
                    return(GetOrCreate <T, Serial.FBVector4>(fbPos));
                }
                else if (typeof(T) == typeof(UnityEngine.Quaternion))
                {
                    return(GetOrCreate <T, Serial.FBQuaternion>(fbPos));
                }
                else
                {
                    return(FlatBufferSerializer.GetOrCreateDeserialize <T>(GetFBRef(fbPos)));
                }
            }
            finally {
                UnityEngine.Profiling.Profiler.EndSample();
            }
        }
Пример #2
0
        /// <summary>
        /// Get a list that was created with FlatBufferSerializer.CreateTypedList(...)
        /// This list saves also the type of the object along the data and makes it possible to have Lists of super-types and its inhertied classes
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="fbPos"></param>
        /// <param name="input"></param>
        /// <returns></returns>
        public ICollection <T> GetTypedList <T>(int fbPos, ICollection <T> input = null)
        {
            if (input == null)
            {
                input = new List <T>();
            }
            int listLength = GetListLength(fbPos);

            for (int i = 0; i < listLength; i = i + 2)
            {
                string typeName = GetStringListElementAt(fbPos, i);
                if (typeName == null)
                {
                    input.Add(default(T));
                    continue;
                }
                Type         type   = Type.GetType(typeName);
                Serial.FBRef?fbObj  = GetListElemAt <Serial.FBRef>(fbPos, i + 1);
                object       result = FlatBufferSerializer.GetOrCreateDeserialize(fbObj, type);
                input.Add((T)result);
            }
            return(input);
        }
Пример #3
0
 public virtual void Deserialize(object incoming)
 {
     Serial.FBComponent data = (Serial.FBComponent)incoming;
     ID     = FlatBufferSerializer.GetOrCreateDeserialize <UID>(data.Id);
     Entity = FlatBufferSerializer.GetOrCreateDeserialize <UID>(data.Entity);
 }
Пример #4
0
        public TResult GetObject <TSerialized, TResult>(int fbPos) where TResult : IFBSerializable, new() where TSerialized : IFlatbufferObject, new()
        {
            TResult result = FlatBufferSerializer.GetOrCreateDeserialize <TResult>(CreateSerialObject <TSerialized>(fbPos));

            return(result);
        }
Пример #5
0
        public T GetOrCreate <T, S>(int fbPos) where T : new() where S : IFlatbufferObject, new()
        {
            S s = CreateSerialObject <S>(fbPos);

            return(FlatBufferSerializer.GetOrCreateDeserialize <T>(s));
        }