Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by VincentDB · Oct 29, 2013 at 04:00 PM · c#iosimportassetbundlepath

How use asset bundle for a image folder ?

Hi everyone,

I want create an assetbundle from a image folder (only images inside: for change textures in my scenes). I'm using this code for export the asset (in JavaScript):

 @MenuItem ("Assets/Build AssetBundle From Selection - Track dependencies")
 static function ExportBundle(){
 
         var str : String = EditorUtility.SaveFilePanel("Save Bundle...", Application.dataPath, Selection.activeObject.name, "assetbundle");
         if (str.Length != 0){
              BuildPipeline.BuildAssetBundle(Selection.activeObject, Selection.objects, str, BuildAssetBundleOptions.CompleteAssets, BuildTarget.iPhone);
         }
 }

and then use this on my image folder to got "myBundle.assetbundle" file at "Assets/Assetbundles/" path.

I use this C# script for import the asset bundle:

  using UnityEngine;
  using System.Collections;
  using System;
     
     public class ImportAssetBundle : MonoBehaviour {
         private WWW www;
         public string AssetName = "myBundle";
         
         void Start () {
         StartCoroutine( DownloadAndCache());
         }
         IEnumerator DownloadAndCache() 
         {
             string BundleURL = "file://" + Application.dataPath +  "/Assets" + "/Assetbundles" + "/" + AssetName + ".assetbundle";
            // Download the file from the URL. It will not be saved in the Cache
            using (WWW www = new WWW(BundleURL)) {
                yield return www;
                if (www.error != null)
                    throw new Exception("WWW download had an error:" + www.error);
                AssetBundle bundle = www.assetBundle;    
                if (AssetName == "")
                 Instantiate(bundle.mainAsset);
                else
                    bundle.LoadAll();
                        // Unload the AssetBundles compressed contents to conserve memory
                 bundle.Unload(false);
     
            } // memory is freed from the web stream (www.Dispose() gets called implicitly)
         }
     }

And now, i would like use these images for change all textures in another C# script, but i don't know how call these images. I want do something like:

 www = new WWW ("file://" + Application.dataPath +  "/Assets" + "/Assetbundles" + "myImage.jpg");
 myMaterial.mainTexture = www.texture;

for update new textures, but this path is wrong, "myImage.jpg" is inside my assetbundle. Note: I'm building on iOS device.

Any though? Thanks.

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image digzou · May 19, 2015 at 02:13 PM 0
Share

Hey I am facing the same issue. Were you able to find a solution? :|

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by ksiUnity · May 28, 2015 at 06:53 AM

try this : myMaterial.maintexture= (Texture)bundle.Load(AssetName,typeof(Texture));

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

17 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Automatically load asset bundles on start from cache 0 Answers

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Guideline 4.2.3-Design-Minimum Functionality 0 Answers

Disabling reimport before building of AssetBundle 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges