9
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

WWWクラスでローカルファイルを読み込む

Last updated at Posted at 2015-04-01

参考ページ:
 http://docs.unity3d.com/ja/current/Manual/StreamingAssets.html
 http://neareal.net/index.php?ComputerGraphics%2FUnity%2FTips%2FScript%2FLoadFileByUsingWWW

●Streaming Assetsなら
// Application.dataPathはAssetsの直下のフォルダの事
string path = Application.streamingAssetsPath + "/myAssetBundle.unity3d";

●Assets直下なら
// Application.dataPathはAssetsの直下のフォルダの事
string path = Application.dataPath + "/myAssetBundle.unity3d";

●アセットバンドルロードに利用してみる

LoadAssetBundleData.cs
using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class LoadAssetBundleData : MonoBehaviour {

    public void OnLoadAssetBundle()
    {
        StartCoroutine(LoadAssetBundle_CreateMemory());
    }

    IEnumerator LoadAssetBundle_CreateMemory()
    {
        // Application.dataPathはAssetsの直下のフォルダの事
        string path = Application.dataPath + "/StreamingAssets/myAssetBundle.unity3d";
        
        WWW www = new WWW("file://" + path);
        yield return www;
        var assetBundleCreateRequest = AssetBundle.CreateFromMemory(www.bytes);
        yield return assetBundleCreateRequest;
        AssetBundle assetBundle = assetBundleCreateRequest.assetBundle;

        Object[] objectArray = assetBundle.LoadAll();
        List<Object> myList = new List<Object>();

        myList.AddRange(objectArray);

        foreach(Object obj in myList)
        {
            Instantiate(obj);
        }
    }
}
9
12
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?