Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
2
Question by naruse · May 19, 2011 at 08:07 PM · editor-scriptingassetbundle

Load Asset Bundle in Editor

Hey Guys!,

I've been trying to load an asset bundle from an editor script but I'm just unable to do it :/...

you might think "Why would you do that?" well... the answer is simple. I have a Library of asset bundles and have a program to place the assets easily so what I just need is to load lets say the asset X which resides in the address http://myserver.com/myasset.unity3dbundle

and load in the Editor, so I can calculate a light map of the generated scene..

Here is what I have written:

using UnityEngine; using UnityEditor;

using System.Collections;

public class DecryptAssetBundle : EditorWindow {

 private string assetURL = "";
 private static WWW request;
 [MenuItem("Bundles/Decrypt Asset Bundle")]
 static void Init () {    
     DecryptAssetBundle window = EditorWindow.GetWindow(typeof(DecryptAssetBundle)) as DecryptAssetBundle;
     window.position = new Rect(Screen.width/2,Screen.height/2, 400,150);
 }
 void OnGUI()
 {
     assetURL = EditorGUILayout.TextField("Asset bundle URL: ", assetURL);

     GUILayout.BeginHorizontal();
     if(GUILayout.Button("Clear"))
     {
         assetURL = "";
     }
     if(GUILayout.Button("Decrypt"))
     {
         MonoBehaviour m = new MonoBehaviour(); //Shouldnt do this but is the only way to make StartCoproutine work
         m.StartCoroutine(LoadAsset(assetURL));//doesnt work!!!!

     }
     GUILayout.EndHorizontal();
 }

 private IEnumerator LoadAsset(string s)
 {
     Debug.Log("Loading " + s + " ...");
     request = new WWW(s);
     yield return request;
     if(request.error != null)
         Debug.LogError(request.error);
     GameObject g = (GameObject) request.assetBundle.mainAsset as GameObject;
     Instantiate(g);
 }

}

Any help would be greatly appreciated :)

Thanks!

Comment
Add comment
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

3 Replies

· Add your reply
  • Sort: 
avatar image
3
Best Answer

Answer by msknapp · Sep 23, 2011 at 07:16 PM

I have actually accomplished this with my own script. You have the wrong idea here, you cannot use StartCoroutine except during runtime. My script is designed to not freeze up the editor while running. Use this instead:

 public class DecryptAssetBundle : EditorWindow {
 
 private string assetURL = "";
 private static WWW request;
 
 private static bool run = false;
 private static IEnumerator en = null;
 
 [MenuItem("Bundles/Decrypt Asset Bundle")]
 static void Init () {    
     DecryptAssetBundle window = EditorWindow.GetWindow(typeof(DecryptAssetBundle)) as DecryptAssetBundle;
     window.position = new Rect(Screen.width/2,Screen.height/2, 400,150);
 }
 void OnGUI()
 {
     assetURL = EditorGUILayout.TextField("Asset bundle URL: ", assetURL);
 
     GUILayout.BeginHorizontal();
     if(GUILayout.Button("Clear"))
     {
         assetURL = "";
     }
     if(GUILayout.Button("Decrypt"))
     {
         run=true;
     }
     if(GUILayout.Button("Abort"))
     {
         run=false;
     }
     GUILayout.EndHorizontal();
 }
 
 public void Update() {
     if (!run) {
         if (en != null)
             en = null;
         return;
     }
     if (en == null) {
         en = LoadAsset(assetUrl);
     }
     if (! en.MoveNext())
         run=false;
 }
 
 private IEnumerator LoadAsset(string s)
 {
     Debug.Log("Loading " + s + " ...");
     request = new WWW(s);
     while (! request.isDone)
         // avoid freezing the editor:
         yield return ""; // just wait.
     // I don't like the following line because it will freeze up 
     // your editor.  So I commented it out.  
     // yield return request;
     if(request.error != null)
         Debug.LogError(request.error);
     GameObject g = (GameObject) request.assetBundle.mainAsset as GameObject;
     Instantiate(g);
 }
 
 } 
Comment
Add comment · Show 1 · 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
avatar image naruse · Nov 23, 2011 at 04:42 PM 0
Share

Awesome! thansk! :)

avatar image
0

Answer by ckfinite · May 19, 2011 at 08:13 PM

Have you seen the example code here? http://unity3d.com/support/documentation/ScriptReference/AssetBundle.html. It seems like it is similar to what you want to do.

Comment
Add comment · Show 1 · 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
avatar image ocimum · Dec 18, 2015 at 12:55 PM 0
Share

link is broken

avatar image
0

Answer by dm · Nov 17, 2011 at 12:15 PM

http://www.unifycommunity.com/wiki/index.php?title=LoadAssetBundle

Comment
Add comment · Show 2 · 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
avatar image ocimum · Dec 18, 2015 at 12:55 PM 0
Share

link is broken

avatar image dm_bond ocimum · Dec 18, 2015 at 02:05 PM 0
Share

http://wiki.unity3d.com/index.php/LoadAssetBundle

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

6 People are following this question.

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

Related Questions

Missing textures & materials in asset bundle 1 Answer

How do you set asset bundle name on prefab through code? 0 Answers

Loading Assetbundles in Editor-script 2 Answers

BuildStreamedSceneAssetBundle causes UnityEditor error 0 Answers

Dynamically loading scripts 4 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