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.
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
Will this work on standalone, native mode without the Web platforms? like native mac or windows app?
No sorry man. This is only for web.
Is there a possibility that it will work on windows webplayer in the future?
Many thank
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
@imagoculturae
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.
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?
It works on Mac WebPlayer, not Windows.
And it works on WebGL on both Mac and Windows.
Thanks. But if you had published both demos it could be seen more clearly.
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.
Can this be modified so that it will work for 2d Sprites?
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);
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
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:
public void OnExternalDragEnd(Texture2D aTexture) {
if(growOnExternalDragOver) transform.localScale = dftScale;
gameObject.GetComponent<Renderer>().material.mainTexture = aTexture;
// what we receive is a newly instatiated texture,
// you may want to clean up the previous texture
}
You change this into:
public void OnExternalDragEnd(Texture2D aTexture) {
if(growOnExternalDragOver) transform.localScale = dftScale;
Sprite sprite = Sprite.Create(aTexture, new Rect(0, 0, aTexture.width, aTexture.height), Vector2.zero, 1.0f);
SpriteRenderer spriteRenderer = gameObject.GetComponent<SpriteRenderer>();
if(spriteRenderer == null) {
Debug.LogError("There is SpriteRenderer component on this gameobject " + gameObject.name);
return;
}
spriteRenderer.sprite = sprite;
}
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.
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
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.
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.
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…
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!