「Unity/AssetBundle/AssetBundleをサーバーから読込」の版間の差分
提供: 初心者エンジニアの簡易メモ
(ページの作成:「==サンプル== #AssetBundlesを生成する #例として、user.csvのアセットバンドルファイル(userとuser.manifest)を上げる。 #以下サンプルを...」) |
|||
| 行41: | 行41: | ||
公式マニュアル:https://docs.unity3d.com/ja/current/ScriptReference/Networking.UnityWebRequestAssetBundle.GetAssetBundle.html | 公式マニュアル:https://docs.unity3d.com/ja/current/ScriptReference/Networking.UnityWebRequestAssetBundle.GetAssetBundle.html | ||
| + | |||
| + | ==既にロード済みのエラーが出る場合== | ||
| + | 以下エラーが出るとき | ||
| + | can't be loaded because another AssetBundle with the same files is already loaded. | ||
| + | 既に同じファイルが、別ロジックからロードされてないか確認。 | ||
2021年8月5日 (木) 17:12時点における最新版
サンプル
- AssetBundlesを生成する
- 例として、user.csvのアセットバンドルファイル(userとuser.manifest)を上げる。
- 以下サンプルを実行。
using UnityEngine;
using UnityEngine.Networking;
using System.Collections;
public class SampleScene : MonoBehaviour
{
public static TextAsset csv;
void Start()
{
StartCoroutine(GetAssetBundle());
}
IEnumerator GetAssetBundle()
{
string url = "ttp://www.my-server.com/";
string assetGroupName = "usergroup";
using (UnityWebRequest uwr = UnityWebRequestAssetBundle.GetAssetBundle(url + assetGroupName))
{
yield return uwr.SendWebRequest();
if (uwr.isNetworkError || uwr.isHttpError)
{
Debug.Log(uwr.error);
}
else
{
AssetBundle assetBundle = DownloadHandlerAssetBundle.GetContent(uwr);
string assetFileName = "user";
csv = assetBundle.LoadAsset<TextAsset>(assetFileName);
Debug.Log("csv.text=" + csv.text);
}
}
}
}
csv.textのところで、ファイル内のデータが、改行を含んで表示された。
既にロード済みのエラーが出る場合
以下エラーが出るとき
can't be loaded because another AssetBundle with the same files is already loaded.
既に同じファイルが、別ロジックからロードされてないか確認。
