コード例 #1
0
        /// <summary>
        /// Loads the specified mesh file.
        /// </summary>
        /// <param name="fileName">Name of the saved mesh file. Exclude path and extension.</param>
        /// <returns>Collection of Mesh objects read from the file.</returns>
        /// <remarks>Determines the path from which to load and automatically applies the file extension.</remarks>
        public static IEnumerable <Mesh> Load(string fileName)
        {
            if (string.IsNullOrEmpty(fileName))
            {
                throw new ArgumentException("Must specify a valid fileName.");
            }

            List <Mesh> meshes = new List <Mesh>();

            // Open the mesh file.
            String folderName = MeshFolderName;

            //   Debug.Log(String.Format("Loading mesh file: {0}", Path.Combine(folderName, fileName + fileExtension)));

            using (Stream stream = OpenFileForRead(folderName, fileName + fileExtension))
            {
                // Read the file and deserialize the meshes.
                byte[] data = new byte[stream.Length];
                stream.Read(data, 0, data.Length);

                meshes.AddRange(SimpleMeshSerializerOld.Deserialize(data));
            }

            //  Debug.Log("Mesh file loaded.");

            return(meshes);
        }
コード例 #2
0
        /// <summary>
        /// Saves the provided meshes to the specified file.
        /// </summary>
        /// <param name="fileName">Name to give the saved mesh file. Exclude path and extension.</param>
        /// <param name="meshes">The collection of Mesh objects to save.</param>
        /// <returns>Fully qualified name of the saved mesh file.</returns>
        /// <remarks>Determines the save path to use and automatically applies the file extension.</remarks>
        public static string Save(string fileName, IEnumerable <Mesh> meshes)
        {
            if (string.IsNullOrEmpty(fileName))
            {
                throw new ArgumentException("Must specify a valid fileName.");
            }

            if (meshes == null)
            {
                throw new ArgumentNullException("Value of meshes cannot be null.");
            }

            // Create the mesh file.
            String folderName = MeshFolderName;

            Debug.Log(String.Format("Saving mesh file: {0}", Path.Combine(folderName, fileName + fileExtension)));

            using (Stream stream = OpenFileForWrite(folderName, fileName + fileExtension))
            {
                // Serialize and write the meshes to the file.
                byte[] data = SimpleMeshSerializerOld.Serialize(meshes);
                stream.Write(data, 0, data.Length);
                stream.Flush();
            }

            Debug.Log("Mesh file saved.");

            return(Path.Combine(folderName, fileName + fileExtension));
        }