首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >正在从sdcard的根加载assetbundle

正在从sdcard的根加载assetbundle
EN

Stack Overflow用户
提问于 2018-02-19 20:09:54
回答 2查看 828关注 0票数 0

我正在尝试从内部存储读取资产捆绑包。这是可行的:

代码语言:javascript
复制
void Start()
{
    var myLoadedAssetBundle = AssetBundle.LoadFromFile(Application.persistentDataPath + "/AssetBundles/model_objs");
    if (myLoadedAssetBundle == null)
    {
        Debug.Log("Failed to load AssetBundle!");
        return;
    }

    GameObject wheel = (GameObject)myLoadedAssetBundle.LoadAsset("01_obj");
    Instantiate(wheel);
}

但是,当我尝试将其重定向到根目录时,如下所示:

代码语言:javascript
复制
void Start()
{
    var myLoadedAssetBundle = AssetBundle.LoadFromFile("/storage/emulated/0/AssetBundles/model_objs");
    if (myLoadedAssetBundle == null)
    {
        Debug.Log("Failed to load AssetBundle!");
        return;
    }

    GameObject wheel = (GameObject)myLoadedAssetBundle.LoadAsset("01_obj");
    Instantiate(wheel);
}

我在logcat上得到了一个Unable to open archive file: /storage/emulated/0/AssetBundles/model_objs

该包完全相同,并且位于两个位置

EN

回答 2

Stack Overflow用户

发布于 2018-02-19 21:43:44

Colin Young是对的,我在自动生成的清单上遇到了问题。默认清单如下:

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.demo.relativeAssets" xmlns:tools="http://schemas.android.com/tools" android:versionName="1.0" android:versionCode="1" android:installLocation="auto">
  <supports-screens android:smallScreens="true" android:normalScreens="true" android:largeScreens="true" android:xlargeScreens="true" android:anyDensity="true" />
  <application android:theme="@style/UnityThemeSelector" android:icon="@drawable/app_icon" android:label="@string/app_name" android:isGame="true" android:banner="@drawable/app_banner">
    <activity android:name="com.unity3d.player.UnityPlayerActivity" android:label="@string/app_name" android:screenOrientation="fullSensor" android:launchMode="singleTask" android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale|layoutDirection|density">
      <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
        <category android:name="android.intent.category.LEANBACK_LAUNCHER" />
      </intent-filter>
      <meta-data android:name="unityplayer.UnityActivity" android:value="true" />
    </activity>
    <meta-data android:name="unity.build-id" android:value="11967537-6671-47db-ad0a-c4fc8a8d10c0" />
    <meta-data android:name="unity.splash-mode" android:value="0" />
    <meta-data android:name="unity.splash-enable" android:value="True" />
    <meta-data android:name="android.max_aspect" android:value="2.1" />
  </application>
  <uses-sdk android:minSdkVersion="21" android:targetSdkVersion="26" />
  <uses-feature android:glEsVersion="0x00020000" />
  <uses-permission android:name="android.permission.INTERNET" />
  <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="18" />
  <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" android:maxSdkVersion="18" />
  <uses-feature android:name="android.hardware.touchscreen" android:required="false" />
  <uses-feature android:name="android.hardware.touchscreen.multitouch" android:required="false" />
  <uses-feature android:name="android.hardware.touchscreen.multitouch.distinct" android:required="false" />
</manifest>

当我从<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" android:maxSdkVersion="18" />中删除android:maxSdkVersion="18"时,我解决了这个问题。

为了获得默认清单,我构建了我的项目并访问了{PROJECT DIRECTORY}\Temp\StagingArea\AndroidManifest.xml。然后,我在unity项目中创建了以下嵌套文件夹:Assets/Plugins/Android/,并粘贴了前面提到的带有更改的文件。

票数 0
EN

Stack Overflow用户

发布于 2018-06-19 15:05:23

如果您想要直接访问资产包,请使用LoadFromFileAsync而不是LoadFromFile:

代码语言:javascript
复制
        private AssetBundleRequest bundleRequest;
        private string yourAssetBundle;    //name of your asset bundle

        string path = "/storage/emulated/0/AssetBundles/" + yourAssetBundle;
        //Please note that while doing this you must have a folder named "AssetBundles" in your
        //root directory with your asset "yourAssetBundle" existing in it.

        AssetBundleCreateRequest loadedAssetbundle = AssetBundle.LoadFromFileAsync(path);
        bundleRequest = loadedAssetbundle.assetBundle.LoadAssetAsync<GameObject> (yourAssetBundle);

        //further you can instantiate it as a gameobject
        GameObject augmentedObj = Instantiate (bundleRequest.asset, Vector3.zero, Quaternion.identity) as GameObject;
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48865942

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档