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); }
static void Import() { var filePath = EditorUtility.OpenFilePanel("Import .unm file", "", "unm"); if (string.IsNullOrEmpty(filePath)) { return; } Mesh mesh; using (Stream stream = new FileStream(filePath, FileMode.Open)) { mesh = UnityMeshFile.Read(stream); } var filename = Path.GetFileNameWithoutExtension(filePath); filePath = EditorUtility.SaveFilePanelInProject("Save asset", filename, "asset", ""); if (string.IsNullOrEmpty(filePath)) { return; } AssetDatabase.CreateAsset(mesh, filePath); }