XNA学习笔记(一) content学习

     (2012-05-01 16:43:12)

     个人感觉,XNA中content并非是一个单纯供人读取的素材区或作为默认读取路径的文件夹,我们一般不需要把在content中没有对应content importer和content processor的文件格式放入content中。(和iOS中的默认bundle不太一样!)


     一般如常见的图片格式,模型格式,音频格式可以放入其中,因为有对应的content importer和content processor去处理(框架已经为我们完成的代码),我们可以直接用类似“bm = game.Content.Load<Texture2D>("mybm");”的方式去载入资源,这些处理方式是已经做好的接口。
 
     但对于txt等没有对应content importer和content processor的文件格式,放入content后会出错,我们需要自己去写content importer和content processor后才能载入资源。但是一般来说,此时,以txt文件为例,我们可以把txt放入项目路径的文件夹下,然后通过C#传统的读取txt文件方式去读取它....

顺带附上貌似是官方给的C#读取文件例子:

 1 using System; 
 2 using System.IO; 
 3 class Test { 
 4     public static void Main() { 
 5         string path = @"c:\temp\MyTest.txt"; 
 6         try { 
 7             if (File.Exists(path)) { 
 8                 File.Delete(path); 
 9             } 
10             using (StreamWriter sw = new StreamWriter(path)) { 
11                 sw.WriteLine("This"); 
12                 sw.WriteLine("is some text"); 
13                 sw.WriteLine("to test"); 
14                 sw.WriteLine("Reading"); 
15             } 
16             using (StreamReader sr = new StreamReader(path)) { 
17                 while (sr.Peek() > -1) { 
18                     Console.WriteLine(sr.ReadLine()); 
19                 } 
20             } 
21         } 
22         catch (Exception e) { 
23             Console.WriteLine("The process failed: {0}", e.ToString()); 
24         }
25     }
26 }
原文地址:https://www.cnblogs.com/mzdbskipop/p/3137404.html