使用例
string stCurrentDir = System.IO.Directory.GetCurrentDirectory();
Image img = ゲームオブジェクト.GetComponent<Image>();Texture2D tex = readImage (stCurrentDir + @"/datas/tatie.png");
img.sprite = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), Vector2.zero);
外部ファイルの読み取り
public byte[] LoadBytes(string path) {FileStream fs = new FileStream(path, FileMode.Open);
BinaryReader br = new BinaryReader(fs);
byte[] result = br.ReadBytes((int)br.BaseStream.Length);
br.Close();
return result;
}
public Texture2D readImage (string name) {
Texture2D tex = new Texture2D(0, 0);
tex.LoadImage(LoadBytes(name));
return tex;
}
0 件のコメント:
コメントを投稿