internal static IEnumerable <FieldInfo> GetAllSerializableFields(System.Type tp)
        {
            var nonSerializedAttrib = typeof(System.NonSerializedAttribute);
            var serializedAttrib    = typeof(UnityEngine.SerializeField);

            while (tp != null)
            {
                foreach (var fi in tp.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly))
                {
                    if (UnityDataFormatter.IsUnitySerializable(fi.FieldType))
                    {
                        if (fi.IsPublic)
                        {
                            if (!System.Attribute.IsDefined(fi, nonSerializedAttrib))
                            {
                                yield return(fi);
                            }
                        }
                        else
                        {
                            if (System.Attribute.IsDefined(fi, serializedAttrib))
                            {
                                yield return(fi);
                            }
                        }
                    }
                }
                tp = tp.BaseType;
            }
        }
        public static UnityDataFormatter GetFormatter <T>() where T : IFormatter
        {
            if (_formatterPools == null)
            {
                _formatterPools = new Dictionary <System.Type, ObjectCachePool <UnityDataFormatter> >();
            }

            var tp = typeof(T);
            UnityDataFormatter formatter;

            if (_formatterPools.ContainsKey(tp))
            {
                formatter = _formatterPools[tp].GetInstance();
            }
            else
            {
                var pool = new ObjectCachePool <UnityDataFormatter>(10, () =>
                {
                    var f            = new UnityDataFormatter(System.Activator.CreateInstance <T>());
                    f._pooledTypeKey = typeof(T);
                    return(f);
                });
                _formatterPools.Add(tp, pool);
                formatter = pool.GetInstance();
            }

            return(formatter);
        }
 ISerializationSurrogate ISurrogateSelector.GetSurrogate(Type type, StreamingContext context, out ISurrogateSelector selector)
 {
     if (UnityDataFormatter.IsUnitySerializable(type))
     {
         selector = this;
         return(this);
     }
     else
     {
         selector = null;
         return(null);
     }
 }