Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Drop on Unity - Drag and drop local files on Unity GameObjects

Discussion in 'Assets and Asset Store' started by Orbcreation, Dec 22, 2014.

  1. Orbcreation

    Orbcreation

    Joined:
    May 4, 2010
    Posts:
    231
    Drag & drop local files on gameObjects at runtime.

    You can use this to let users drag their own images and textures on objects. Or let them import their own 3D models.

    Implementing Drop on Unity requires nothing more than dragging a prefab in your scene and adding a tiny script to the gameobjects that will accept the user texture.

    Here's a demo in WebGL that shows a simple room. As a user you can change the decoration of the room. Simply by dragging your own image on the picture frame on the wall. Or you can change the fabric of the sofa if you drag a nice texture on it.

    Drop on Unity is designed only for Web Player and WebGL

    Drop on Unity accepts all file formats by default, but only png and jpg are implemented to be converted to Textures.
    Other file formats are imported as text string or byte array for further handling. (for this you can use Simple OBJ or Simple Collada. Just ask if you need help with that)

    Online documentation is here

    P.S. The package is not in the asset store yet. It is pending review by the Asset Store people.

    Screenshot1.jpg
     
    Last edited: Dec 22, 2014
  2. Orbcreation

    Orbcreation

    Joined:
    May 4, 2010
    Posts:
    231
    I've put a new demo online that allows you to drag & drop your own OBJ model directly into Unity at runtime and see how it is imported by my other Asset Store package "SimpleOBJ".
    http://orbcreation.com/SimpleObjDrop/Demo.html
     
  3. bufflogic

    bufflogic

    Joined:
    Aug 8, 2012
    Posts:
    15
    Will this work on standalone, native mode without the Web platforms? like native mac or windows app?
     
  4. Orbcreation

    Orbcreation

    Joined:
    May 4, 2010
    Posts:
    231
    No sorry man. This is only for web.
     
  5. imagoculturae

    imagoculturae

    Joined:
    Apr 8, 2014
    Posts:
    81
    Is there a possibility that it will work on windows webplayer in the future?
    Many thank
     
    Last edited: Jul 18, 2015
  6. Sphax84

    Sphax84

    Joined:
    Jun 23, 2015
    Posts:
    34
    I would be VERY interested in this working for Windows App (and MacOS App)...
    I found this thread (http://answers.unity3d.com/answers/1010816/view.html) about that but I'm can't find a way to make it work yet... Do you think that could help you to enable the drag&drop feature for Windows software at least?

    Thanks
     
  7. Orbcreation

    Orbcreation

    Joined:
    May 4, 2010
    Posts:
    231
    @paganic
    The problem with Windows webplayer is that the WebPlayer component renders differently and does not behave according to the DOM model. When you drag something on it, the webpage will try to load the dragged object instead of sending the appropriate events down the chain so DropOnUnity can pick them up. I tried dozens of dirty tricks to make this working, but so far no luck. If anyone has a good idea, I'm all ears.

    @Sphax84 The link you posted doesn't seem to exist.
     
  8. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    946
    Is it working for WebPlayer or not?
    If you are saying it is designed for Web Player and WebGL.
    I have just got lost here.
    If it is working could you publish a WebPlayer demo like you did for WebGL?
     
  9. Orbcreation

    Orbcreation

    Joined:
    May 4, 2010
    Posts:
    231
    It works on Mac WebPlayer, not Windows.
    And it works on WebGL on both Mac and Windows.
     
  10. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    946
    Thanks. But if you had published both demos it could be seen more clearly.:)
     
  11. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    946
    Is that supposed to work on Edge?
    I am getting no-entry sign probably similar to one appearing over the Webplayer as it is mentioned above.
     
  12. vismonkey

    vismonkey

    Joined:
    Jul 23, 2013
    Posts:
    7
    Can this be modified so that it will work for 2d Sprites?
     
  13. Orbcreation

    Orbcreation

    Joined:
    May 4, 2010
    Posts:
    231
    When you want a 2D Sprite, you need to convert the Texture that you receive from DropOnUnity into a Sprite, which is fairly basic:
    Texture2D aTex; // Set this to the texture you received from Drop On Unity
    Sprite mySprite = Sprite.Create(aTex, new Rect(0, 0, aTex.width, aTex.height), Vector2.zero, 1.0f);
     
  14. vismonkey

    vismonkey

    Joined:
    Jul 23, 2013
    Posts:
    7
    Orbcreation,

    Thanks for taking the time to reply. My knowledge of code is very basic. How would I implement the code that you provided above? Is that just additional code that would be added to one of the scripts in the DropOnUnity package?

    Sorry for such a basic question... if it's too complicated to explain to someone with my limited knowledge I completely understand.

    Thanks
     
  15. Orbcreation

    Orbcreation

    Joined:
    May 4, 2010
    Posts:
    231
    To use drag & drop you need to add a DropOnUnityTarget component to your gameObject. This DropOnUnityTarget.cs script has the following piece of code starting on line 20:
    Code (CSharp):
    1.     public void OnExternalDragEnd(Texture2D aTexture) {
    2.         if(growOnExternalDragOver) transform.localScale = dftScale;
    3.         gameObject.GetComponent<Renderer>().material.mainTexture = aTexture;
    4.         // what we receive is a newly instatiated texture,
    5.         // you may want to clean up the previous texture
    6.     }
    7.  
    You change this into:
    Code (CSharp):
    1.     public void OnExternalDragEnd(Texture2D aTexture) {
    2.         if(growOnExternalDragOver) transform.localScale = dftScale;
    3.         Sprite sprite = Sprite.Create(aTexture, new Rect(0, 0, aTexture.width, aTexture.height), Vector2.zero, 1.0f);
    4.         SpriteRenderer spriteRenderer = gameObject.GetComponent<SpriteRenderer>();
    5.         if(spriteRenderer == null) {
    6.             Debug.LogError("There is SpriteRenderer component on this gameobject " + gameObject.name);
    7.             return;
    8.         }
    9.         spriteRenderer.sprite = sprite;
    10.     }
    11.  
    What happens is this:
    - When the image is released over your gameObject, this function is called
    - The scale is returned to the normal size (the gamobject's size was increased when you hovered over it)
    - It creates a Sprite from the Texture2D
    - It looks up the SpriteRenderer component. If you are using something else on your gameObject to show the sprite, you should use that instead.
    - It checks to see if the SpriteRenderer was found
    - And finally sets the new sprite

    Hope this helps.
     
  16. the_greenlig

    the_greenlig

    Joined:
    Feb 5, 2013
    Posts:
    29
    Hi Orb,

    We're using this asset but finding it crashes if you load too many assets by drag/drop? Seems like it runs out of memory. If you use your webGL demo (http://orbcreation.com/DropOnUnity/Demo.html), and drag a 3mb image file onto each object and repeat this several times, it crashes. Is there a way around this?

    Cheers,
    greenlig
     
  17. Orbcreation

    Orbcreation

    Joined:
    May 4, 2010
    Posts:
    231
    I already made a few optimizations that make it take longer before all memory is consumed, But essentially, no there is no way around this. The Unity WebGL implementation is a big black magic box, that handles things for you where you have no control over. All we can do is try to use as little memory as possible.

    If you send me an email I can give you the updated code.
     
  18. the_greenlig

    the_greenlig

    Joined:
    Feb 5, 2013
    Posts:
    29
    Thanks for the super fast reply! I thought that might be the case. That's a bit problematic for us, we allow users to drag/drop multiple files. Might need to set up an intermediary or something.

    I'll shoot you an email soon.
     
  19. RazaTech

    RazaTech

    Joined:
    Feb 27, 2015
    Posts:
    178
    Great Asset But it would be more useful if we can use it for standalone build too..
    Kindly Provide it and i will be the first one to buy it..
     
  20. Taurunium

    Taurunium

    Joined:
    Jan 16, 2018
    Posts:
    2
    Hello guys,
    I'm trying to use Drop on Unity plugin which is perfect solution for my problem. But it seems that there is some bug and it doesn't work when I want to implement it. Even I tried with Demo scene.
    Here is the link:
    http://marena-fanzine.rs/wp-content/uploads/TestingDragAndDrop/

    I also checked option "Run in background" in Player settings. I noticed in console this error

    "TypeError: Cannot read property 'addEventListener' of null"

    Do you have any suggestion what's causing this problem?

    Thanks in advance!
     
  21. arun15794kumar

    arun15794kumar

    Joined:
    Jul 7, 2018
    Posts:
    2
    Hi @Taurunium i am facing the same problem , did you find any solution ?
     
  22. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    946
    Your link is dead.
    It is working for me in 2017.4.
    As long as drag and drop is working on windows explorer, because sometimes it gets blocked.
     
    Last edited: Aug 5, 2018
  23. arun15794kumar

    arun15794kumar

    Joined:
    Jul 7, 2018
    Posts:
    2
    I also tried it in 2017.3 and below but drag and drop is not working
    and it is working fine in demo link , but not in the package ,so if it was a file explorer blockage thing it shouldn't have worked for demo link provided above too
     
  24. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    946
    You can check if the plugin initializes properly in the web browser inspector. The plugin should append a file input element to the document (in case of uploading with system open file window) or add event listeners to the document body for dragenter, dragover and drop (in case of uploading with drag & drop).
     
    Last edited: Aug 6, 2018
  25. ghallo-K

    ghallo-K

    Joined:
    Jan 9, 2018
    Posts:
    1
    Will the package with the codes and other stuff be released? I have been looking all over the internet for some examples but it seems like documentations are nonexistent besides the website...
     
  26. Cyber-Dog

    Cyber-Dog

    Joined:
    Sep 12, 2018
    Posts:
    352
    Hey is this project dead, does anybody know of an alternative. Need it for WebGL..
    I want to build a sprite sheet generator tool were users can drop multiple images into it and export as one.