/// <summary>
        /// Initializes the Sirenix serialization system to be compatible with Unity.
        /// </summary>
        private static void Initialize()
        {
            if (!initialized)
            {
                lock (LOCK)
                {
                    if (!initialized)
                    {
                        // Ensure that the config instance is loaded before deserialization of anything occurs.
                        // If we try to load it during deserialization, Unity will throw exceptions, as a lot of
                        // the Unity API is disallowed during serialization and deserialization.
                        GlobalSerializationConfig.LoadInstanceIfAssetExists();

                        // Custom UnityEvent formatter resolution
                        FormatterLocator.FormatterResolve += (type) =>
                        {
                            if (type != typeof(UnityEvent) &&
                                type.ImplementsOrInherits(typeof(UnityEventBase)) &&
                                (type.ImplementsOrInherits(typeof(UnityEvent)) ||
                                 type.ImplementsOpenGenericClass(typeof(UnityEvent <>)) ||
                                 type.ImplementsOpenGenericClass(typeof(UnityEvent <,>)) ||
                                 type.ImplementsOpenGenericClass(typeof(UnityEvent <, ,>)) ||
                                 type.ImplementsOpenGenericClass(typeof(UnityEvent <, , ,>))))
                            {
                                return((IFormatter)Activator.CreateInstance(typeof(UnityEventFormatter <>).MakeGenericType(type)));
                            }

                            return(null);
                        };

                        initialized = true;
                    }
                }
            }
        }
Exemple #2
0
 /// <summary>
 /// Initializes the Sirenix serialization system to be compatible with Unity.
 /// </summary>
 private static void Initialize()
 {
     if (!initialized)
     {
         lock (LOCK)
         {
             if (!initialized)
             {
                 // Ensure that the config instance is loaded before deserialization of anything occurs.
                 // If we try to load it during deserialization, Unity will throw exceptions, as a lot of
                 // the Unity API is disallowed during serialization and deserialization.
                 GlobalSerializationConfig.LoadInstanceIfAssetExists();
                 initialized = true;
             }
         }
     }
 }