Exemplo n.º 1
0
        ///----------------------------------------------------------------------------------------------

        ///<summary>Serialize to json</summary>
        public static string Serialize(Type type, object instance, List <UnityEngine.Object> references = null, bool pretyJson = false)
        {
            lock ( serializerLock ) {
                serializer.PurgeTemporaryData();
                serializer.ReferencesDatabase = references;

                fsData data;
                //We override the UnityObject converter if we serialize a UnityObject directly.
                //UnityObject converter will still be used for every serialized property found within the object though.
                var overrideConverterType = typeof(UnityEngine.Object).RTIsAssignableFrom(type) ? typeof(fsReflectedConverter) : null;
                var r = serializer.TrySerialize(type, instance, out data, overrideConverterType).AssertSuccess();
                if (r.HasWarnings)
                {
                    Logger.LogWarning(r.ToString(), "Serialization");
                }

                serializer.ReferencesDatabase = null;

                var json = fsJsonPrinter.ToJson(data, pretyJson);

                if (Threader.applicationIsPlaying || UnityEngine.Application.isPlaying)
                {
                    dataCache[json] = data;
                }

                return(json);
            }
        }