protected override fsResult DoDeserialize(Dictionary <string, fsData> data, ref Texture2D model)
        {
            var result = fsResult.Success;

            int width;

            result += DeserializeMember(data, null, "width", out width);

            int height;

            result += DeserializeMember(data, null, "height", out height);

            TextureFormat format;

            result += DeserializeMember(data, null, "format", out format);

            string path;

            result += DeserializeMember(data, null, "path", out path);

            float mipmapBias;

            result += DeserializeMember(data, null, "mipmapBias", out mipmapBias);

            TextureWrapMode wrapMode;

            result += DeserializeMember(data, null, "wrapMode", out wrapMode);

            FilterMode filterMode;

            result += DeserializeMember(data, null, "filterMode", out filterMode);

            int anisoLevel;

            result += DeserializeMember(data, null, "anisoLevel", out anisoLevel);

            model            = new Texture2D(width, height, format, mipmapBias >= 0, filterMode == FilterMode.Point);
            model.mipMapBias = mipmapBias;
            model.wrapMode   = wrapMode;
            model.filterMode = filterMode;
            model.anisoLevel = anisoLevel;
            model.LoadRawTextureData(SerializerHelpers.LoadAsset(path));
            model.Apply();

            return(result);
        }
Exemplo n.º 2
0
        public XElement Serialize(string name, object rootObject, Serializer serializer)
        {
            XElement root = new XElement(name);

            //Обрабатываем кольцевые ссылки
            if (serializer.CheckCircularReferences(root, rootObject))
            {
                return(root);
            }

            //Сериализуем метаданные
            Serializer.SerializeMetadata(root, rootObject);
            //Сериализуем имя типа
            Serializer.SerializeTypeName(root, typeof(Body));

            Body body = (Body)rootObject;

            root.Add(
                new XAttribute("BodyType", DefaultConverters.IntToString((int)body.BodyType)),
                new XAttribute("Active", DefaultConverters.BoolToString(body.Enabled)),
                new XAttribute("AllowSleep", DefaultConverters.BoolToString(body.SleepingAllowed)),
                new XAttribute("Angle", DefaultConverters.FloatToString(body.Rotation)),
                new XAttribute("AngularDamping", DefaultConverters.FloatToString(body.AngularDamping)),
                new XAttribute("AngularVelocity", DefaultConverters.FloatToString(body.AngularVelocity)),
                new XAttribute("Awake", DefaultConverters.BoolToString(body.Awake)),
                new XAttribute("Bullet", DefaultConverters.BoolToString(body.IsBullet)),
                new XAttribute("FixedRotation", DefaultConverters.BoolToString(body.FixedRotation)),
                new XAttribute("LinearDamping", DefaultConverters.FloatToString(body.LinearDamping)),
                new XAttribute("LinearVelocity", DefaultConverters.Vector2ToString(body.LinearVelocity)),
                new XAttribute("Position", DefaultConverters.Vector2ToString(body.Position)),
                serializer.SerializeObject("World", SerializerHelpers.GetFieldValue(body, "World")));

            XElement fixtures = new XElement("Fixtures");

            for (int i = 0; i < body.FixtureList.Count; i++)
            {
                fixtures.Add(serializer.SerializeObject("Fixture", body.FixtureList[i]));
            }

            root.Add(fixtures);
            return(root);
        }
Exemplo n.º 3
0
        protected override fsResult DoDeserialize(Dictionary <string, fsData> data, ref GameObject model)
        {
            var result = fsResult.Success;

            string path;

            result += DeserializeMember(data, null, "path", out path);

            byte[] bytes = SerializerHelpers.LoadAsset(path);

            model = null;

            if (bytes == null)
            {
                return(result);
            }

            bytes.LoadObjectTree();

            return(result);
        }
Exemplo n.º 4
0
    private void OnDeserialized()
    { //So, we need to mod a little bit
        bool av = true;

        try
        { //First, try to know if the data come from Editor
            Vector3[] v = vertices;
            if (v.Length == 0)
            {
                av = false;
            }
        }
        catch
        {               //If it's from Editor nothing wouldn't be stored, so we have to take action in it...
            av = false; // vv As we saved it before in GameObject_DirectConvert, we can restore it safely!
        }
        Mesh mesh = new Mesh();

        if (av)
        {
            mesh.vertices     = vertices;
            mesh.normals      = normals;
            mesh.uv           = uv;
            mesh.uv2          = uv1;
            mesh.uv2          = uv2;
            mesh.colors       = colors;
            mesh.tangents     = tangents;
            mesh.subMeshCount = subMeshCount;
            for (var i = 0; i < subMeshCount; ++i)
            {
                mesh.SetTriangles(triangles[i], i);
            }
            mesh.RecalculateBounds();
            if (filter != null)
            {
                filter.mesh = mesh;
            }
            else if (skinnedMeshRenderer != null)
            {
                skinnedMeshRenderer.sharedMesh = mesh;
            }
        }
        else
        { //If it's from Editor nothing wouldn't be stored, so we have to take action in it...
            byte[] b = SerializerHelpers.LoadAsset("Mesh/" + LevelLoader.Current.Last.name + ".asset");
            if (b == null)
            {
                Debug.LogErrorFormat("{0} mesh couldn't be loaded.", LevelLoader.Current.Last.name);
                return;
            }
            mesh = MeshSerializer.ReadMesh(b); //As we saved it before in GameObject_DirectConvert, we can restore it safely!
            if (mesh == null)
            {
                Debug.LogFormat("{0} couldn't be rebuilt.", LevelLoader.Current.Last.name);
                return;
            }
        }
        if (filter != null)
        {
            filter.mesh = mesh;
        }
        else if (skinnedMeshRenderer != null)
        {
            skinnedMeshRenderer.sharedMesh = mesh;
        }
    }