예제 #1
0
 public static SerializerFactory DefaultFactory()
 {
     var serializer = new SerializerFactory();
     serializer.RegisterSerializer(new MaterialSerializer());
     serializer.RegisterSerializer(new SkinnedMeshSerializer());
     return serializer;
 }
예제 #2
0
        protected override void Serialize(Material obj, ref BinaryWriter writer, SerializerFactory serializerFactory)
        {
            writer.Write(obj.shader.name);

            writer.Write(Colors.Length);
            writer.Write(Textures.Length);
            writer.Write(Floats.Length);
            writer.Write(Matrices.Length);

            foreach (var c in Colors)
            {
                //we write the property names so others can deserialize
                writer.Write(c);
                writer.Write(obj.GetColor(c));
            }

            foreach (var t in Textures)
            {
                writer.Write(t);
                var tex = obj.GetTexture(t);
                if (tex)
                {
                    //todo: write a better texture path
                    writer.Write(tex.name);
                }
                else
                {
                    writer.Write("");
                }
            }

            foreach (var f in Floats)
            {
                //todo: write float values
            }

            foreach (var m in Matrices)
            {
                //todo: write matrix values
            }
        }
예제 #3
0
 /// <summary>
 /// set up with a custom factory
 /// </summary>
 /// <param name="serializer"></param>
 public UnityModelFile(SerializerFactory serializer)
 {
     _serializer = serializer;
 }
예제 #4
0
 /// <summary>
 /// set up with a DefaultFactory
 /// </summary>
 public UnityModelFile()
 {
     _serializer = SerializerFactory.DefaultFactory();
 }
예제 #5
0
 protected override void Serialize(Component obj, ref BinaryWriter writer, SerializerFactory serializer)
 {
     throw new NotImplementedException();
 }
예제 #6
0
 protected override Component Deserialize(ref BinaryReader reader, Object parent, SerializerFactory serializer)
 {
     throw new NotImplementedException();
 }
예제 #7
0
 protected abstract void Serialize(T obj, ref BinaryWriter writer, SerializerFactory serializer);
예제 #8
0
 protected abstract T Deserialize(ref BinaryReader reader, Object parent, SerializerFactory serializer);
예제 #9
0
 Object IObjectSerializer.Deserialize(ref BinaryReader reader, Object parent, SerializerFactory serializerFactory)
 {
     return(Deserialize(ref reader, parent, serializerFactory));
 }
예제 #10
0
 void IObjectSerializer.Serialize(Object obj, ref BinaryWriter writer, SerializerFactory serializerFactory)
 {
     Serialize(obj as T, ref writer, serializerFactory);
 }
예제 #11
0
        protected override Material Deserialize(ref BinaryReader reader, Object parent, SerializerFactory serializerFactory)
        {
            var shaderName = reader.ReadString();
            var shader     = Shader.Find(shaderName);
            var mat        = new Material(shader);

            var colorCount   = reader.ReadInt32();
            var textureCount = reader.ReadInt32();
            var floatCount   = reader.ReadInt32();
            var matrixCount  = reader.ReadInt32();

            string prop;

            for (int i = 0; i < colorCount; i++)
            {
                prop = reader.ReadString();
                mat.SetColor(prop, reader.ReadColor());
            }
            for (int i = 0; i < textureCount; i++)
            {
                prop = reader.ReadString();
                var texPath = reader.ReadString();
                //TODO: load texture from path
            }
            for (int i = 0; i < floatCount; i++)
            {
                prop = reader.ReadString();
            }
            for (int i = 0; i < matrixCount; i++)
            {
                prop = reader.ReadString();
            }

            return(mat);
        }
예제 #12
0
        protected override void Serialize(SkinnedMeshRenderer obj, ref BinaryWriter writer, SerializerFactory serializer)
        {
            Stream stream = null;

            if (StoreInline)
            {
                stream = writer.BaseStream;
            }
            else
            {
                //TODO: write relative file path
                throw new NotImplementedException("Cannot store meshes in a separate file yet");
            }

            //store bones
            writer.Write(obj.bones.Length);
            foreach (var bone in obj.bones)
            {
                writer.Write(serializer.ReferenceMap[bone]);
            }


            writer.Write(obj.sharedMaterials.Length);
            foreach (var material in obj.sharedMaterials)
            {
                serializer.InternalSerialize(material, ref writer);
            }

            writer.Write((int)obj.quality);
            writer.Write(obj.localBounds);

            //store mesh
            UnityMeshFile.Write(stream, obj.sharedMesh, meshConfig);
        }
예제 #13
0
        protected override SkinnedMeshRenderer Deserialize(ref BinaryReader reader, Object parent, SerializerFactory serializer)
        {
            Stream stream = null;

            if (StoreInline)
            {
                stream = reader.BaseStream;
            }
            else
            {
                //TODO: write relative file path
                throw new NotImplementedException("Cannot read meshes from a separate file yet");
            }

            var skin = (parent as Transform).gameObject.AddComponent <SkinnedMeshRenderer>();

            var boneCount = reader.ReadInt32();
            var bones     = new Transform[boneCount];

            for (int i = 0; i < bones.Length; i++)
            {
                var boneID = reader.ReadInt32();
                bones[i] = serializer.ReferenceMap[boneID] as Transform;
            }

            var materialCount = reader.ReadInt32();
            var materials     = new Material[materialCount];

            //todo: serialize materials
            for (int i = 0; i < materialCount; i++)
            {
                materials[i] = serializer.InternalDeserialize(ref reader, skin) as Material;
            }

            var quality = (SkinQuality)reader.ReadInt32();
            var bounds  = reader.ReadBounds();

            var mesh = UnityMeshFile.Read(stream, meshConfig);

            skin.sharedMesh  = mesh;
            skin.bones       = bones;
            skin.quality     = quality;
            skin.localBounds = bounds;

            return(skin);
        }
예제 #14
0
 /// <summary>
 /// set up with a custom factory
 /// </summary>
 /// <param name="serializer"></param>
 public UnityModelFile(SerializerFactory serializer)
 {
     _serializer = serializer;
 }
예제 #15
0
 /// <summary>
 /// set up with a DefaultFactory
 /// </summary>
 public UnityModelFile()
 {
     _serializer = SerializerFactory.DefaultFactory();
 }