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
0
Question by skoandi · Dec 25, 2012 at 05:15 PM · editorimagewwwdownloadextension

Loading images from web to editor window

Hi! I'm trying to download a image from a web, and use it. I've looked around and I can't find something. Can this even be done?

 class EditorGUITextures extends EditorWindow {
 
     var texture : Texture2D;
     var url : String = "http://images.earthcam.com/ec_metros/ourcams/fridays.jpg";
     var done : boolean = false;
     var aString : String = "nothing";
     
     @MenuItem("Examples/Texture Previewer")
     static function Init() {
         var window = GetWindow(EditorGUITextures);
         window.position = Rect(100,100,400, 200);
         window.Show();
     }
     
     function OnGUI() {
        texture = EditorGUI.ObjectField(Rect(3,3,200,20),"Add a Texture:",texture,Texture);
        GUI.Label(Rect(100,200,100,50),aString);
        if(texture){
                EditorGUI.PrefixLabel(Rect(25,45,100,15),0,GUIContent("Preview:"));
             EditorGUI.DrawPreviewTexture(Rect(25,60,100,100),texture);
        }
        if(GUI.Button(Rect(0,190,100,30),"Download")){
                GetIcon();
        }
     }
     function GetIcon(){
         var www : WWW = new WWW (url);
         yield www;
         aString = "Done!";
         print("done");
         texture = www.texture;
         done = true;
     }
 }
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
2
Best Answer

Answer by skoandi · Dec 26, 2012 at 12:15 PM

Yes after some more research I figured it out!! :D

 // UnityScript
 @script ExecuteInEditMode()
 
 
 
 
 class MyWindow extends EditorWindow {
     
     private var www : WWW;
     var target : Renderer;
     var texture : Texture2D;
 
     @MenuItem ("Window/My Window")
     static function ShowWindow () {
         EditorWindow.GetWindow (MyWindow);
     }
 
     function OnGUI () {
         if(GUILayout.Button("Download")){  LoadTexture("http://download.unity3d.com/webplayer/images/unity-icon-big.jpg"); }
         texture = EditorGUI.ObjectField(Rect(3,60,200,20),"Add a Texture:",texture,Texture);
         if(texture){
             EditorGUI.DrawPreviewTexture(Rect(25,150,100,100),texture);
         }
     }
     /*function OnEnable(){
         LoadTexture("http://download.unity3d.com/webplayer/images/unity-icon-big.jpg");
     }*/
     
     function LoadTexture(url)
     {
         www = new WWW(url);
         #if UNITY_EDITOR
         if (!EditorApplication.isPlaying)
             EditorApplication.update = MyUpdate;
         else
             WaitForDownload();
         #else
         WaitForDownload();
         #endif
     }
     
     #if UNITY_EDITOR
     function MyUpdate ()
     {
         if (www.isDone)
         {
             EditorApplication.update = null;
            LoadCompleted();
         }
     }
     #endif
     
     function WaitForDownload()
     {
         yield www;
         LoadCompleted();
     }
     
     function LoadCompleted()
     {
         //target.sharedMaterial.mainTexture = www.texture;
         texture = www.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
avatar image
2

Answer by smilefr · May 07, 2019 at 03:12 PM

Here is my method, works without depending on update:

         public static void DownloadImage(Material m, string url)
         {
             using (WebClient client = new WebClient())
             {
                 byte[] data = client.DownloadData(url);
                 Texture2D tex = new Texture2D(2, 2);
                 tex.LoadImage(data);
 
                 m.mainTexture = tex;
             }
         }
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 giinsen · Apr 07, 2021 at 03:57 PM 0
Share

Thanks a lot !

avatar image
0

Answer by MarkFinn · Dec 25, 2012 at 07:24 PM

I never did get any answers on this one. Not very useful ones anyway.

Short answer, yes it is possible. But : The editor goes to sleep and never properly finishes processing the WWW actions, unless you keep poking it to wake it up.

You can see a similiar question I asked some time back on my account page.

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

12 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

Related Questions

Downloading image from the server crash the game in Android Device ? 1 Answer

Downloading files in the Editor 2 Answers

Localhost does not work after launching build from hosting 1 Answer

few questions about using www for getting bunch of images... 0 Answers

Where is downloaded things from editor script being saved? 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