Unity プロジェクトに Firebase を追加する
https://firebase.google.com/docs/unity/setup?hl=ja
// ローカルのパス(保存先)の指定 string local_url = Application.dataPath + "/StreamingAssets/" + fileName + ".png";
Unity 公式スクリプトリファレンス
Application.dataPath
https://docs.unity3d.com/ja/current/ScriptReferenc...
Qiita @w_yang 様
unityでplatformによって取得できるパス
https://qiita.com/w_yang/items/8458cd790607d14b1b3...
// FirebaseStorage の初期化 FirebaseStorage storage = FirebaseStorage.DefaultInstance;
Firebase マニュアル
FirebaseStorage.DefaultInstance
https://firebase.google.com/docs/reference/unity/c...
// 引数で指定した URL を指定し利用できる状態にする StorageReference gs_reference = storage.GetReferenceFromUrl("gs://"自分のFireBaseのアドレス".appspot.com/"フォルダ名。ここではTexture/" + fileName + ".png");
Firebase マニュアル
FirebaseStorage.GetReferenceFromUrl
https://firebase.google.com/docs/reference/android...
// FireBaseからデータをダウンロードし、引数で指定したローカルのパス(フォルダ)に入れる gs_reference.GetFileAsync(local_url).ContinueWith(task => { // 処理に失敗しておらず、かつ、処理をキャンセルしていない場合 if (!task.IsFaulted && !task.IsCanceled) { Debug.Log("File downloaded."); isLoad = false; } });
Firebase マニュアル
Firebase.Storage.StorageReference.GetFileAsync
https://firebase.google.com/docs/reference/unity/c...
// ロードしたいファイルのあるローカル内のパスを指定 string local_url = Application.dataPath + "/StreamingAssets/" + "ダウンロードしたファイルの名前を指定します" + ".png"; // ファイルをバイト配列に読み取る byte[] imgData = File.ReadAllBytes(local_url);
MicroSoft
File.ReadAllBytes
https://docs.microsoft.com/ja-jp/dotnet/api/system...
// バイト配列の情報をテクスチャに変換 texture.LoadImage(imgData, false);
Unity公式スクリプトリファレンス
ImageConversion.LoadImage
https://docs.unity3d.com/ja/current/ScriptReferenc...
// テクスチャを元に Sprite を新規作成。サイズと Pivot を指定 sprite = Sprite.Create(texture, new Rect(0.0f, 0.0f, texture.width, texture.height), new Vector2(0.5f, 0.5f));
Unity公式スクリプトリファレンス
Sprite.Create
https://docs.unity3d.com/jp/current/ScriptReferenc...