コード例 #1
0
        public static void OneSelectionPackUnpack()
        {
            var obj = UnityEditor.Selection.gameObjects;

            if (obj != null)
            {
                var serializers = Builder.GetAllSerializers();

                // pack
                var data           = ME.UAB.Builder.Pack(obj, null, serializers);
                var dataSerialized = UABSerializer.SerializeValueType(data);
                var zipped         = Zipper.ZipString(dataSerialized);
                Debug.Log(dataSerialized);
                Debug.Log(string.Format("Json length: {0}, Zipped length: {1}, Objects inside: {2}, Binaries inside: {3}.", dataSerialized.Length, zipped.Length, data.objects.Length, data.binaryData.Length));

                // unpack
                var gos = ME.UAB.Builder.Unpack(zipped, null, serializers);
                for (int i = 0; i < gos.Length; ++i)
                {
                    GameObject.Instantiate(gos[i]);
                }
            }
            else
            {
                Debug.LogError("Please, select one gameobject to pack and unpack");
            }
        }
コード例 #2
0
        public static void JsonEncodeDecode()
        {
            var package      = new UABPackage();
            var serialized   = UABSerializer.SerializeValueType(package);
            var deserialized = UABSerializer.DeserializeValueType <UABPackage>(serialized);
            var serialized2  = UABSerializer.SerializeValueType(deserialized);

            NUnit.Framework.Assert.IsTrue(serialized == serialized2);
        }
コード例 #3
0
        public static void PackUnpackGameObject()
        {
            var objs = UABTests.GetTestObjects();

            var serializers = Builder.GetAllSerializers();
            var config      = Builder.GetDefaultConfig(required: true);

            var data           = ME.UAB.Builder.Pack(objs, config, serializers);
            var dataSerialized = UABSerializer.SerializeValueType(data);
            var zipped         = Zipper.ZipString(dataSerialized);

            var unzipped         = Zipper.UnzipString(zipped);
            var dataDeserialized = UABSerializer.DeserializeValueType <UABPackage>(unzipped);
            var gos = ME.UAB.Builder.Unpack(dataDeserialized, config, serializers);

            NUnit.Framework.Assert.IsTrue(UABTests.CompareTestObjects(objs, gos));
        }
コード例 #4
0
        public static void OneSelectionPackToFile(string filename)
        {
            var obj = UnityEditor.Selection.gameObjects;

            if (obj != null)
            {
                var serializers = Builder.GetAllSerializers();

                Debug.Log(string.Format("Packing... Objects: {0}", obj.Length));

                // pack
                var data           = ME.UAB.Builder.Pack(obj, null, serializers);
                var dataSerialized = UABSerializer.SerializeValueType(data);
                var zipped         = Zipper.ZipString(dataSerialized);
                Debug.Log(dataSerialized);
                Debug.Log(string.Format("Json length: {0}, Zipped length: {1}, Objects inside: {2}, Binaries inside: {3}.", dataSerialized.Length, zipped.Length, data.objects.Length, data.binaryData.Length));

                System.IO.File.WriteAllBytes(filename, zipped);
            }
            else
            {
                Debug.LogError("Please, select one gameobject to pack and unpack");
            }
        }
コード例 #5
0
        public static bool CompareType <T>(bool system, params System.Type[] requiredTypes) where T : Object
        {
            var types = new List <System.Type>();
            var reqs  = typeof(T).GetCustomAttributes(typeof(RequireComponent), inherit: true);

            if (reqs != null)
            {
                for (int i = 0; i < reqs.Length; ++i)
                {
                    var req = reqs[i] as RequireComponent;
                    if (req != null)
                    {
                        if (req.m_Type0 != null)
                        {
                            types.Add(req.m_Type0);
                        }
                        if (req.m_Type1 != null)
                        {
                            types.Add(req.m_Type1);
                        }
                        if (req.m_Type2 != null)
                        {
                            types.Add(req.m_Type2);
                        }
                    }
                }
            }

            if (requiredTypes != null)
            {
                types.AddRange(requiredTypes);
            }
            types.Add(typeof(T));

            var go   = new GameObject("UTest", types.ToArray());
            var objs = new GameObject[1] {
                go
            };

            if (typeof(T) == typeof(Animator))
            {
                go.GetComponent <Animator>().bodyRotation = Quaternion.identity;
            }

                        #if UNITY_5_5_OR_NEWER
            if (typeof(T) == typeof(ParticleSystem))
            {
                go.GetComponent <ParticleSystem>().useAutoRandomSeed = false;
            }
                        #endif

            //go.SendMessage("OnValidate");

            var serializers = Builder.GetAllSerializers();
            var config      = Builder.GetDefaultConfig(required: true);

            var data           = ME.UAB.Builder.Pack(objs, config, serializers);
            var dataSerialized = UABSerializer.SerializeValueType(data);
            var zipped         = Zipper.ZipString(dataSerialized);

            var unzipped         = Zipper.UnzipString(zipped);
            var dataDeserialized = UABSerializer.DeserializeValueType <UABPackage>(unzipped);
            var gos = ME.UAB.Builder.Unpack(dataDeserialized, config, serializers);

            for (int i = 0; i < gos.Length; ++i)
            {
                var t1      = gos[i].GetComponent <T>();
                var fields1 = t1.GetType().GetAllProperties().Where(x => x.GetCustomAttributes(true).Any(a => a is System.ObsoleteAttribute) == false && x.CanWrite == true && UABSerializer.FilterProperties(x) == true).ToArray();

                var t2      = objs[i].GetComponent <T>();
                var fields2 = t1.GetType().GetAllProperties().Where(x => x.GetCustomAttributes(true).Any(a => a is System.ObsoleteAttribute) == false && x.CanWrite == true && UABSerializer.FilterProperties(x) == true).ToArray();

                var result = UABTests.CompareFields(fields1, fields2, t1, t2, system);
                if (result == false)
                {
                    return(false);
                }
            }

            return(true);
        }