Quellcode durchsuchen

修复内置unity类型不能用litjson序列化的问题

tanghai vor 3 Jahren
Ursprung
Commit
b90e2a8de1

+ 2 - 0
Unity/Assets/Mono/MonoBehaviour/Init.cs

@@ -29,6 +29,8 @@ namespace ET
 			SynchronizationContext.SetSynchronizationContext(ThreadSynchronizationContext.Instance);
 			
 			DontDestroyOnLoad(gameObject);
+			
+			LitJson.UnityTypeBindings.Register();
 
 			ETTask.ExceptionHandler += Log.Error;
 

+ 4 - 14
Unity/Assets/ThirdParty/LitJson/UnityTypeBindings.cs

@@ -1,20 +1,16 @@
 using System;
-
 using LitJson.Extensions;
 
 namespace LitJson
 {
-
-#if !SERVER
-#endif
     /// <summary>
     /// Unity内建类型拓展
     /// </summary>
+#if UNITY_EDITOR
+    [UnityEditor.InitializeOnLoad]
+#endif
     public static class UnityTypeBindings
     {
-
-        static bool registerd;
-
         static UnityTypeBindings()
         {
             Register();
@@ -22,11 +18,6 @@ namespace LitJson
 
         public static void Register()
         {
-
-            if (registerd) return;
-            registerd = true;
-
-
             // 注册Type类型的Exporter
             JsonMapper.RegisterExporter<Type>((v, w) =>
             {
@@ -37,7 +28,7 @@ namespace LitJson
             {
                 return Type.GetType(s);
             });
-#if !SERVER
+            
             // 注册Vector2类型的Exporter
             Action<UnityEngine.Vector2, JsonWriter> writeVector2 = (v, w) =>
             {
@@ -146,7 +137,6 @@ namespace LitJson
                 w.WriteProperty("right", v.right);
                 w.WriteObjectEnd();
             });
-#endif
         }
 
     }