Esempio n. 1
0
        private static void RegisterBaseImporters()
        {
            ImporterFunc importer = (object input) => Convert.ToByte((int)input);

            JsonMapper.RegisterImporter(JsonMapper.base_importers_table, typeof(int), typeof(byte), importer);
            importer = ((object input) => Convert.ToUInt64((int)input));
            JsonMapper.RegisterImporter(JsonMapper.base_importers_table, typeof(int), typeof(ulong), importer);
            importer = ((object input) => Convert.ToSByte((int)input));
            JsonMapper.RegisterImporter(JsonMapper.base_importers_table, typeof(int), typeof(sbyte), importer);
            importer = ((object input) => Convert.ToInt16((int)input));
            JsonMapper.RegisterImporter(JsonMapper.base_importers_table, typeof(int), typeof(short), importer);
            importer = ((object input) => Convert.ToUInt16((int)input));
            JsonMapper.RegisterImporter(JsonMapper.base_importers_table, typeof(int), typeof(ushort), importer);
            importer = ((object input) => Convert.ToUInt32((int)input));
            JsonMapper.RegisterImporter(JsonMapper.base_importers_table, typeof(int), typeof(uint), importer);
            importer = ((object input) => Convert.ToSingle((int)input));
            JsonMapper.RegisterImporter(JsonMapper.base_importers_table, typeof(int), typeof(float), importer);
            importer = ((object input) => Convert.ToDouble((int)input));
            JsonMapper.RegisterImporter(JsonMapper.base_importers_table, typeof(int), typeof(double), importer);
            importer = ((object input) => Convert.ToDecimal((double)input));
            JsonMapper.RegisterImporter(JsonMapper.base_importers_table, typeof(double), typeof(decimal), importer);
            importer = ((object input) => Convert.ToUInt32((long)input));
            JsonMapper.RegisterImporter(JsonMapper.base_importers_table, typeof(long), typeof(uint), importer);
            importer = ((object input) => Convert.ToChar((string)input));
            JsonMapper.RegisterImporter(JsonMapper.base_importers_table, typeof(string), typeof(char), importer);
            importer = ((object input) => Convert.ToDateTime((string)input, JsonMapper.datetime_format));
            JsonMapper.RegisterImporter(JsonMapper.base_importers_table, typeof(string), typeof(DateTime), importer);
        }
 public JsonPlayerLoader(Uri uri)
 {
     JsonMapper jsonMapper = new JsonMapper();
     jsonMapper.RegisterImporter<JsonReader, KeyControl>(deserializeKeyControl);
     Stream jsonStream = Application.GetContentStream(uri).Stream;
     string jsonStr = new StreamReader(jsonStream, Encoding.UTF8).ReadToEnd();
     this.dummyPlayer = jsonMapper.ToObject<DummyPlayer>(jsonStr);
 }
Esempio n. 3
0
        public static void AddExtentds()
        {
            // Rect exporter
            ExporterFunc <UnityEngine.Rect> rectExporter = new ExporterFunc <UnityEngine.Rect>(JsonExtend.rectexp);

            JsonMapper.RegisterExporter <UnityEngine.Rect>(rectExporter);

            // UnityEngine.Color exporter
            ExporterFunc <UnityEngine.Color> colorExporter = new ExporterFunc <UnityEngine.Color>(JsonExtend.colorexp);

            JsonMapper.RegisterExporter <UnityEngine.Color>(colorExporter);

            // UnityEngine.GameObject exporter
            ExporterFunc <UnityEngine.GameObject> gameObjectExporter = new ExporterFunc <UnityEngine.GameObject>(JsonExtend.gameObjexp);

            JsonMapper.RegisterExporter <UnityEngine.GameObject>(gameObjectExporter);

            // UnityEngine.Quaternion exporter
            ExporterFunc <UnityEngine.Quaternion> quaternionExporter = new ExporterFunc <UnityEngine.Quaternion>(JsonExtend.quaternionexp);

            JsonMapper.RegisterExporter <UnityEngine.Quaternion>(quaternionExporter);

            // UnityEngine.Object exporter
            ExporterFunc <UnityEngine.Object> objectExporter = new ExporterFunc <UnityEngine.Object>(JsonExtend.objectexp);

            JsonMapper.RegisterExporter <UnityEngine.Object>(objectExporter);

            // Vector4 exporter
            ExporterFunc <Vector4> vector4Exporter = new ExporterFunc <Vector4>(JsonExtend.vector4exp);

            JsonMapper.RegisterExporter <Vector4>(vector4Exporter);

            // Vector3 exporter
            ExporterFunc <Vector3> vector3Exporter = new ExporterFunc <Vector3>(JsonExtend.vector3exp);

            JsonMapper.RegisterExporter <Vector3>(vector3Exporter);

            // Vector2 exporter
            ExporterFunc <Vector2> vector2Exporter = new ExporterFunc <Vector2>(JsonExtend.vector2exp);

            JsonMapper.RegisterExporter <Vector2>(vector2Exporter);

            // float to double
            ExporterFunc <float> float2double = new ExporterFunc <float>(JsonExtend.float2double);

            JsonMapper.RegisterExporter <float>(float2double);

            // double to float
            ImporterFunc <double, Single> double2float = new ImporterFunc <double, Single>(JsonExtend.double2float);

            JsonMapper.RegisterImporter <double, Single>(double2float);
        }
Esempio n. 4
0
        public static void AddExtentds()
        {
            // Vector4 exporter
            ExporterFunc <Vector4> vector4Exporter = new ExporterFunc <Vector4>(JsonExtend.vector4exp);

            JsonMapper.RegisterExporter <Vector4>(vector4Exporter);

            // Vector3 exporter
            ExporterFunc <Vector3> vector3Exporter = new ExporterFunc <Vector3>(JsonExtend.vector3exp);

            JsonMapper.RegisterExporter <Vector3>(vector3Exporter);

            // Vector2 exporter
            ExporterFunc <Vector2> vector2Exporter = new ExporterFunc <Vector2>(JsonExtend.vector2exp);

            JsonMapper.RegisterExporter <Vector2>(vector2Exporter);

            // float to double
            ExporterFunc <float> float2double = new ExporterFunc <float>(JsonExtend.float2double);

            JsonMapper.RegisterExporter <float>(float2double);

            // double to float
            ImporterFunc <double, Single> double2float = new ImporterFunc <double, Single>(JsonExtend.double2float);

            JsonMapper.RegisterImporter <double, Single>(double2float);

            // string to vector3
            ImporterFunc <string, Vector3> string2vector3 = new ImporterFunc <string, Vector3>(JsonExtend.string2vector3);

            JsonMapper.RegisterImporter <string, Vector3>(string2vector3);

            // string to int
            ImporterFunc <string, int> string2int = new ImporterFunc <string, int>(JsonExtend.string2int);

            JsonMapper.RegisterImporter <string, int>(string2int);

            JsonMapper.RegisterImporter <int, long>((int value) => {
                return((long)value);
            });

            JsonMapper.RegisterImporter <uint, Int64>((uint value) => {
                return((Int64)value);
            });
        }
Esempio n. 5
0
        private static void RegisterBaseImporters()
        {
            ImporterFunc importer1 = (ImporterFunc)(input => (object)Convert.ToByte((int)input));

            JsonMapper.RegisterImporter(JsonMapper.base_importers_table, typeof(int), typeof(byte), importer1);
            ImporterFunc importer2 = (ImporterFunc)(input => (object)Convert.ToUInt64((int)input));

            JsonMapper.RegisterImporter(JsonMapper.base_importers_table, typeof(int), typeof(ulong), importer2);
            ImporterFunc importer3 = (ImporterFunc)(input => (object)Convert.ToSByte((int)input));

            JsonMapper.RegisterImporter(JsonMapper.base_importers_table, typeof(int), typeof(sbyte), importer3);
            ImporterFunc importer4 = (ImporterFunc)(input => (object)Convert.ToInt16((int)input));

            JsonMapper.RegisterImporter(JsonMapper.base_importers_table, typeof(int), typeof(short), importer4);
            ImporterFunc importer5 = (ImporterFunc)(input => (object)Convert.ToUInt16((int)input));

            JsonMapper.RegisterImporter(JsonMapper.base_importers_table, typeof(int), typeof(ushort), importer5);
            ImporterFunc importer6 = (ImporterFunc)(input => (object)Convert.ToUInt32((int)input));

            JsonMapper.RegisterImporter(JsonMapper.base_importers_table, typeof(int), typeof(uint), importer6);
            ImporterFunc importer7 = (ImporterFunc)(input => (object)Convert.ToSingle((int)input));

            JsonMapper.RegisterImporter(JsonMapper.base_importers_table, typeof(int), typeof(float), importer7);
            ImporterFunc importer8 = (ImporterFunc)(input => (object)Convert.ToDouble((int)input));

            JsonMapper.RegisterImporter(JsonMapper.base_importers_table, typeof(int), typeof(double), importer8);
            ImporterFunc importer9 = (ImporterFunc)(input => (object)Convert.ToDecimal((double)input));

            JsonMapper.RegisterImporter(JsonMapper.base_importers_table, typeof(double), typeof(Decimal), importer9);
            ImporterFunc importer10 = (ImporterFunc)(input => (object)Convert.ToUInt32((long)input));

            JsonMapper.RegisterImporter(JsonMapper.base_importers_table, typeof(long), typeof(uint), importer10);
            ImporterFunc importer11 = (ImporterFunc)(input => (object)Convert.ToChar((string)input));

            JsonMapper.RegisterImporter(JsonMapper.base_importers_table, typeof(string), typeof(char), importer11);
            ImporterFunc importer12 = (ImporterFunc)(input => (object)Convert.ToDateTime((string)input, JsonMapper.datetime_format));

            JsonMapper.RegisterImporter(JsonMapper.base_importers_table, typeof(string), typeof(DateTime), importer12);
        }
Esempio n. 6
0
        public static void RegisterImporter <TJson, TValue>(ImporterFunc <TJson, TValue> importer)
        {
            ImporterFunc importer2 = (object input) => importer((TJson)((object)input));

            JsonMapper.RegisterImporter(JsonMapper.custom_importers_table, typeof(TJson), typeof(TValue), importer2);
        }
Esempio n. 7
0
 public static void RegisterImporter(Type TJson, Type TValue, ImporterFunc importer)
 {
     JsonMapper.RegisterImporter(JsonMapper.custom_importers_table, TJson, TValue, importer);
 }
Esempio n. 8
0
        public static void Register()
        {
            // 注册Type类型的Exporter
            JsonMapper.RegisterExporter <Type>((v, w) =>
            {
                w.Write(v.FullName);
            });

            JsonMapper.RegisterImporter <string, Type>((s) =>
            {
                return(Type.GetType(s));
            });

            // 注册Vector2类型的Exporter
            Action <UnityEngine.Vector2, JsonWriter> writeVector2 = (v, w) =>
            {
                w.WriteObjectStart();
                w.WriteProperty("x", v.x);
                w.WriteProperty("y", v.y);
                w.WriteObjectEnd();
            };

            JsonMapper.RegisterExporter <UnityEngine.Vector2>((v, w) =>
            {
                writeVector2(v, w);
            });

            // 注册Vector3类型的Exporter
            Action <UnityEngine.Vector3, JsonWriter> writeVector3 = (v, w) =>
            {
                w.WriteObjectStart();
                w.WriteProperty("x", v.x);
                w.WriteProperty("y", v.y);
                w.WriteProperty("z", v.z);
                w.WriteObjectEnd();
            };

            JsonMapper.RegisterExporter <UnityEngine.Vector3>((v, w) =>
            {
                writeVector3(v, w);
            });

            // 注册Vector4类型的Exporter
            JsonMapper.RegisterExporter <UnityEngine.Vector4>((v, w) =>
            {
                w.WriteObjectStart();
                w.WriteProperty("x", v.x);
                w.WriteProperty("y", v.y);
                w.WriteProperty("z", v.z);
                w.WriteProperty("w", v.w);
                w.WriteObjectEnd();
            });

            // 注册Quaternion类型的Exporter
            JsonMapper.RegisterExporter <UnityEngine.Quaternion>((v, w) =>
            {
                w.WriteObjectStart();
                w.WriteProperty("x", v.x);
                w.WriteProperty("y", v.y);
                w.WriteProperty("z", v.z);
                w.WriteProperty("w", v.w);
                w.WriteObjectEnd();
            });

            // 注册Color类型的Exporter
            JsonMapper.RegisterExporter <UnityEngine.Color>((v, w) =>
            {
                w.WriteObjectStart();
                w.WriteProperty("r", v.r);
                w.WriteProperty("g", v.g);
                w.WriteProperty("b", v.b);
                w.WriteProperty("a", v.a);
                w.WriteObjectEnd();
            });

            // 注册Color32类型的Exporter
            JsonMapper.RegisterExporter <UnityEngine.Color32>((v, w) =>
            {
                w.WriteObjectStart();
                w.WriteProperty("r", v.r);
                w.WriteProperty("g", v.g);
                w.WriteProperty("b", v.b);
                w.WriteProperty("a", v.a);
                w.WriteObjectEnd();
            });

            // 注册Bounds类型的Exporter
            JsonMapper.RegisterExporter <UnityEngine.Bounds>((v, w) =>
            {
                w.WriteObjectStart();

                w.WritePropertyName("center");
                writeVector3(v.center, w);

                w.WritePropertyName("size");
                writeVector3(v.size, w);

                w.WriteObjectEnd();
            });

            // 注册Rect类型的Exporter
            JsonMapper.RegisterExporter <UnityEngine.Rect>((v, w) =>
            {
                w.WriteObjectStart();
                w.WriteProperty("x", v.x);
                w.WriteProperty("y", v.y);
                w.WriteProperty("width", v.width);
                w.WriteProperty("height", v.height);
                w.WriteObjectEnd();
            });

            // 注册RectOffset类型的Exporter
            JsonMapper.RegisterExporter <UnityEngine.RectOffset>((v, w) =>
            {
                w.WriteObjectStart();
                w.WriteProperty("top", v.top);
                w.WriteProperty("left", v.left);
                w.WriteProperty("bottom", v.bottom);
                w.WriteProperty("right", v.right);
                w.WriteObjectEnd();
            });
        }
Esempio n. 9
0
        public static void Register()
        {
            if (registerd)
            {
                return;
            }
            registerd = true;

            // If you seralize using WriteProperty()
            // LitJson will attempt to bind property
            // names to class members instead of using
            // an importer.

            // -- Type
            JsonMapper.RegisterExporter <Type>((v, w) => {
                w.Write(v.FullName);
            });

            JsonMapper.RegisterImporter <string, Type>((s) => {
                return(Type.GetType(s));
            });

            // -- Vector2
            Action <Vector2, JsonWriter> writeVector2 = (v, w) => {
                w.WriteObjectStart();
                w.WriteProperty("x", v.x);
                w.WriteProperty("y", v.y);
                w.WriteObjectEnd();
            };

            JsonMapper.RegisterExporter <Vector2>((v, w) => {
                writeVector2(v, w);
            });

            // -- Vector3
            Action <Vector3, JsonWriter> writeVector3 = (v, w) => {
                w.WriteObjectStart();
                w.WriteProperty("x", v.x);
                w.WriteProperty("y", v.y);
                w.WriteProperty("z", v.z);
                w.WriteObjectEnd();
            };

            JsonMapper.RegisterExporter <Vector3>((v, w) => {
                writeVector3(v, w);
            });

            // -- Vector4
            JsonMapper.RegisterExporter <Vector4>((v, w) => {
                w.WriteObjectStart();
                w.WriteProperty("x", v.x);
                w.WriteProperty("y", v.y);
                w.WriteProperty("z", v.z);
                w.WriteProperty("w", v.w);
                w.WriteObjectEnd();
            });

            // -- Quaternion
            JsonMapper.RegisterExporter <Quaternion>((v, w) => {
                w.WriteObjectStart();
                w.WriteProperty("x", v.x);
                w.WriteProperty("y", v.y);
                w.WriteProperty("z", v.z);
                w.WriteProperty("w", v.w);
                w.WriteObjectEnd();
            });

            // -- Color
            JsonMapper.RegisterExporter <Color>((v, w) => {
                w.WriteObjectStart();
                w.WriteProperty("r", v.r);
                w.WriteProperty("g", v.g);
                w.WriteProperty("b", v.b);
                w.WriteProperty("a", v.a);
                w.WriteObjectEnd();
            });

            // -- Color32
            JsonMapper.RegisterExporter <Color32>((v, w) => {
                w.WriteObjectStart();
                w.WriteProperty("r", v.r);
                w.WriteProperty("g", v.g);
                w.WriteProperty("b", v.b);
                w.WriteProperty("a", v.a);
                w.WriteObjectEnd();
            });

            // -- Bounds
            JsonMapper.RegisterExporter <Bounds>((v, w) => {
                w.WriteObjectStart();

                w.WritePropertyName("center");
                writeVector3(v.center, w);

                w.WritePropertyName("size");
                writeVector3(v.size, w);

                w.WriteObjectEnd();
            });

            // -- Rect
            JsonMapper.RegisterExporter <Rect>((v, w) => {
                w.WriteObjectStart();
                w.WriteProperty("x", v.x);
                w.WriteProperty("y", v.y);
                w.WriteProperty("width", v.width);
                w.WriteProperty("height", v.height);
                w.WriteObjectEnd();
            });

            // -- RectOffset
            JsonMapper.RegisterExporter <RectOffset>((v, w) => {
                w.WriteObjectStart();
                w.WriteProperty("top", v.top);
                w.WriteProperty("left", v.left);
                w.WriteProperty("bottom", v.bottom);
                w.WriteProperty("right", v.right);
                w.WriteObjectEnd();
            });
        }
        public static void Register()
        {
            if (registerd)
            {
                return;
            }
            registerd = true;

            // If you seralize using WriteProperty()
            // LitJson will attempt to bind property
            // names to class members instead of using
            // an importer.

            // -- Type
            JsonMapper.RegisterExporter <Type>((v, w) => {
                w.Write(v.FullName);
            });

            JsonMapper.RegisterImporter <string, Type>((s) => {
                return(Type.GetType(s));
            });
            //DateTimeOffset
            //Action<DateTimeOffset, JsonWriter> writeDateTimeOffset = (v, w) => {
            //    //{"D1":"2018-03-21T03:54:36.2747187Z","D2":"2018-03-21T03:54:36.2747187+00:00"}
            //    w.WriteObjectStart();
            //    //w.WriteProperty("D1", string.Format("{0}-{1}-{2}T{3}:{4}:{5}Z",
            //    //    v.Year,v.Month,v.Date,
            //    //    v.Hour,v.Minute,v.Second+v.Millisecond*0.001f));
            //    w.WriteProperty("D2", string.Format("{0}-{1}-{2}T{3}:{4}:{5}+{6}:{7}",
            //         v.Year, v.Month, v.Date,
            //         v.Hour, v.Minute, v.Second + v.Millisecond * 0.001f,
            //         //时区
            //         "00","00"
            //         ));
            //    w.WriteObjectEnd();

            //};
            //JsonMapper.RegisterExporter<DateTimeOffset>((v,w)=> {
            //    writeDateTimeOffset(v,w);
            //});
            ////Action<DateTimeOffset, JsonReader> readDateTimeOffset=((v,r)=> {
            ////    //怎么读呢
            ////});
            ////JsonMapper.RegisterImporter((s) => {
            ////    return
            ////});
            //JsonMapper.RegisterFactory<DateTimeOffset>(()=> {
            //    return new DateTimeOffset();
            //});
            // -- Vector2
            Action <Vector2, JsonWriter> writeVector2 = (v, w) => {
                w.WriteObjectStart();
                w.WriteProperty("x", v.x);
                w.WriteProperty("y", v.y);
                w.WriteObjectEnd();
            };

            JsonMapper.RegisterExporter <Vector2>((v, w) => {
                writeVector2(v, w);
            });

            // -- Vector3
            Action <Vector3, JsonWriter> writeVector3 = (v, w) => {
                w.WriteObjectStart();
                w.WriteProperty("x", v.x);
                w.WriteProperty("y", v.y);
                w.WriteProperty("z", v.z);
                w.WriteObjectEnd();
            };

            JsonMapper.RegisterExporter <Vector3>((v, w) => {
                writeVector3(v, w);
            });

            // -- Vector4
            JsonMapper.RegisterExporter <Vector4>((v, w) => {
                w.WriteObjectStart();
                w.WriteProperty("x", v.x);
                w.WriteProperty("y", v.y);
                w.WriteProperty("z", v.z);
                w.WriteProperty("w", v.w);
                w.WriteObjectEnd();
            });

            // -- Quaternion
            JsonMapper.RegisterExporter <Quaternion>((v, w) => {
                w.WriteObjectStart();
                w.WriteProperty("x", v.x);
                w.WriteProperty("y", v.y);
                w.WriteProperty("z", v.z);
                w.WriteProperty("w", v.w);
                w.WriteObjectEnd();
            });

            // -- Color
            JsonMapper.RegisterExporter <Color>((v, w) => {
                w.WriteObjectStart();
                w.WriteProperty("r", v.r);
                w.WriteProperty("g", v.g);
                w.WriteProperty("b", v.b);
                w.WriteProperty("a", v.a);
                w.WriteObjectEnd();
            });

            // -- Color32
            JsonMapper.RegisterExporter <Color32>((v, w) => {
                w.WriteObjectStart();
                w.WriteProperty("r", v.r);
                w.WriteProperty("g", v.g);
                w.WriteProperty("b", v.b);
                w.WriteProperty("a", v.a);
                w.WriteObjectEnd();
            });

            // -- Bounds
            JsonMapper.RegisterExporter <Bounds>((v, w) => {
                w.WriteObjectStart();

                w.WritePropertyName("center");
                writeVector3(v.center, w);

                w.WritePropertyName("size");
                writeVector3(v.size, w);

                w.WriteObjectEnd();
            });

            // -- Rect
            JsonMapper.RegisterExporter <Rect>((v, w) => {
                w.WriteObjectStart();
                w.WriteProperty("x", v.x);
                w.WriteProperty("y", v.y);
                w.WriteProperty("width", v.width);
                w.WriteProperty("height", v.height);
                w.WriteObjectEnd();
            });

            // -- RectOffset
            JsonMapper.RegisterExporter <RectOffset>((v, w) => {
                w.WriteObjectStart();
                w.WriteProperty("top", v.top);
                w.WriteProperty("left", v.left);
                w.WriteProperty("bottom", v.bottom);
                w.WriteProperty("right", v.right);
                w.WriteObjectEnd();
            });
        }