상속: System.IO.BinaryWriter
예제 #1
0
파일: Kn5.Save.cs 프로젝트: windygu/actools
        public void Save(string filename, IKn5TextureProvider textureProvider = null)
        {
            using (var writer = new Kn5Writer(File.Open(filename, FileMode.Create, FileAccess.ReadWrite))) {
                writer.Write(Header);

                writer.Write(Textures.Count);
                foreach (var texture in Textures.Values)
                {
                    if (TexturesData.TryGetValue(texture.Name, out var data) && data.Length > 0)
                    {
                        texture.Length = data.Length;
                        writer.Write(texture);
                        writer.Write(data);
                    }
                    else
                    {
                        textureProvider?.GetTexture(texture.Name, size => {
                            texture.Length = size;
                            writer.Write(texture);
                            writer.Flush();
                            return(writer.BaseStream);
                        });
                    }
                }

                writer.Write(Materials.Count);
                foreach (var material in Materials.Values)
                {
                    writer.Write(material);
                }

                Save_Node(writer, RootNode);
            }
        }
예제 #2
0
        public void Save(string filename, bool saveNodes = false)
        {
            using (var writer = new Kn5Writer(filename)) {
                writer.Write(Header);

                writer.Write(Textures.Count);
                foreach (var texture in Textures.Values)
                {
                    var data = TexturesData[texture.Name];
                    texture.Length = data.Length;
                    writer.Write(texture);
                    writer.Write(data);
                }

                writer.Write(Materials.Count);
                foreach (var material in Materials.Values)
                {
                    writer.Write(material);
                }

                if (saveNodes)
                {
                    Save_Node(writer, RootNode);
                }
                else
                {
                    if (NodesBytes == null)
                    {
                        throw new Exception("NodesBytes = null");
                    }

                    writer.Write(NodesBytes);
                }
            }
        }
예제 #3
0
파일: Kn5.Save.cs 프로젝트: windygu/actools
 private static void Save_Node(Kn5Writer writer, Kn5Node node)
 {
     writer.Write(node);
     foreach (var t in node.Children)
     {
         Save_Node(writer, t);
     }
 }