網(wǎng)絡(luò)讀取
private string url="http://localhost/GoodsTable.txt";
private WWW www;
這是攜程
public IEnumerator Start(){
//聲明www(要下載的鏈接本地和網(wǎng)絡(luò)都可以)
www=new WWW(url);
//等待www是否下載完成
yield return www;
//輸出www是否下載完成
print(www.isDone);
//www的錯(cuò)誤 www.error是空的字符串證明沒錯(cuò)
if (!string.IsNullOrEmpty (www.error)) {
Debug.LogError (www.error);
} else {
//將www當(dāng)中下載的所有字節(jié)轉(zhuǎn)換為string類型
txt = System.Text.Encoding.UTF8.GetString (www.bytes);
}
本地讀取
現(xiàn)在Unity里面建立一個(gè) StreamingAssets的文件夾
然后把建立的Txt文件 放到這個(gè)文件夾下面
void Start(){
private string path="file://"+Application.streamingAssetsPath+"/"+path;
}
private 私有的是不會(huì)自動(dòng)默認(rèn)實(shí)例化的
public 編譯器是會(huì)自動(dòng)實(shí)例化的
在Unity里面導(dǎo)入DBAccess
運(yùn)用類名 Mono.Data.Sqlite
先在建立StreamingAssets文件夾然后用代碼在他底下生成SQL文件
path = Application.streamingAssetsPath+"/MySql0.db";
//生成完了之后 就沒用了 注銷 0.0;
// if (!File.Exists (path)) {
// File.Create (path);
// }
用數(shù)據(jù)庫(kù)索引各種數(shù)據(jù)
