blog games developers documentation portfolio gallery

More in this category:

Target object script

In the "Drop on Unity" target object, you will need a script to catch the messages that are broadcasted by the DropOnUnityTarget. The script DropOnUnityTarget can be used as example or can be used unchanged to drag and drop images on gameObjects and change their mainTexture. You can either implement all of these functions or only use what you need.

Those messages can be:
- void OnExternalDragOver(Vector3 cursorPosition)
This is send whenever the user drags a file over the GameObject's Collider inside Unity, but the user hasn't dropped the file yet. It passes the current cursor position

- void OnExternalDragCancel()
Send when the drag is canceled or when the cursor is no longer over the collider

- void OnExternalDragFilesToExpect(int nrOfFilesToExpect)
Is send upon drop and before any file is processed. If there are multiple files dropped in 1 go, the nrOfFilesToExpect will be greater than 1.

- void OnExternalDragFileName(string fileName)
Send just before a file is processed. The argument holds the name of the file including the extension, but without the path.

- void OnExternalDragFileExtension(string lowercaseFileExtension)
Send just before a file is processed. The argument holds the extension of the file in lowercase and without the dot.

- void OnExternalDragAllFilesReceived()
Send after all files have been processed

- void OnExternalDragEnd(Texture2D aTexture)
Send when a Drag&Drop is complete and the cursor has been released over the collider of this GameObject. It passes a newly created texture if the file was a PNG or JPG image.

- void OnExternalDragEnd(string aString)
Send when a Drag&Drop is complete and the cursor has been released over the collider of this GameObject. It passes the contents of the file as a string if the file was a plain text file.

- void OnExternalDragEnd(byte[] bytes)
Send when a Drag&Drop is complete and the cursor has been released over the collider of this GameObject. It passes the raw contents of the file as a byte array if the file was not a plain text file or a PNG or JPG file.

When you assign a fixed TargetObject in the DropOnUnityCtrl component, this GameObject will receive the same messages regardless whether or not the cursor is over the GameObject or not.







follow us