Unity output PC-side (Windows) Drag and drop files into the app

Source: Internet
Author: User

Requirements: Write a PC-side (Window) Excel guide to your planners. Originally with OpenFile open Fileexplorerdialog after let them choose to add Excel file on the line, the result has a demand is to drag and drop Excel file directly added, think this is more convenient.

Desktop applications with WinForm and WPF to write, this feature should be very good to do, with unity to do is compared to the egg hurt ... Check it out. More is the API that calls Win32.

To summarize, you need to drag the file Manager to select files, and drag-and-drop file selection by mouse.

The key points of this guide tool are:

1. Import Excel files in normal way. Unity with Ugui to make a good interface, do an item template (can be used as a prefab preform), click the button to open Fileexplorerdialog, multi-select Excel file, press OK, dynamically generated item added to ScrollView content. The content under ScrollView is required to add the content Size fitter and grid Layout group components. This type of import is recommended with the Crosstale Filebrowser plugin (here).

2. Add files by dragging and dropping files to the App window under window platform. It is recommended to use this tool (here), mainly C # to invoke the Win32 API. There are examples of usages in the FileDragAndDrop.cs file. Add a word to the MessageBox output and drag it into the app's file path:

voidOnfiles (list<string>pathList, point APos) {    //Do something with the dropped file names. APos would contain the//mouse position within the window where the files has been dropped.Debug.Log ("Dropped"+pathlist.count+"files at:"+ APos +"\ n"+Pathlist.aggregate ((A, B)= A +"\ n"+b)); StringBuilder SB=NewStringBuilder (); Sb. Append ("drag the file in. \ n"); foreach(varPathinchpathList) {sb.        Append (path); Sb. Append (". \ n"); } MessageBox.Show (sb.) ToString ());}

Test, drag the file after running, the effect is as follows:

Unity output PC-side (Windows) Drag and drop files into the app

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.