Ejemplo n.º 1
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));
        }
Ejemplo n.º 2
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);
        }