Strength Package: Unity Pack Assetbundle (iv)

Source: Internet
Author: User

→→ previously Summary: Window beginning ←←

Let the user select the files to be packaged

Today, the way we choose to package files is still a mouse click in the Project Panel or hierarchy panel. Now that we have the window, we naturally want to be able to list all the files in the window, and then make a selection in the window, to implement this function today.

Now that we want to show all the files, we must first know what files are in the project directory and get their paths. There are many examples of recursion to get all the files under a certain directory, here is not a detail, but be careful to filter out. Meta files, which are automatically generated by Unity for each resource file, the guid,unity that stores the resources is the GUID that refers to the resource. Unity's resource files are placed under the Assets folder, and the packaged API can only package files in this folder.

The relative paths of all the resource files that we will get (the file path beginning with assets) are stored in a string list. This list can be defined as follows, in addition to defining a bool array of the same length as the linked list, and a vector of type Vector2 ↓↓

  List<stringlist<stringbool[assetspath.  Scallpos;       

Then add the following code to the Ongui function ↓↓

    Guilayout.Space (20);Guilayout.Label ("Select the Files you want to package:");Scallpos=Editorguilayout.Beginscrollview (Scallpos,Guilayout.Height (300));foreach (IntI=0;i < assetspath.count; i++) {  String lable = path.getfilename (assetspath[i]);  flags[i] = Span class= "cm-variable" >editorguilayout. toggleleft (lable, flags[i]); } editorguilayout. endscrollview ();            

Click the menu to run the window, you can already see the effect, but also good.

A few notes ↓↓

    1. Guilayout.space (int) is used to draw a blank area, mainly to make the controls spaced a bit larger and less crowded.

    2. Editorguilayout.beginscrollview can create a scrolling view that must be used with Endscrollview, and it is necessary to make them scroll when there are a lot of resource files. The first parameter of the Beginscrollview is a Vector2 vector that represents the scroll position, and the return value must also be assigned back to the same variable, otherwise the view is scrolled, which is why you define a Scrollpos variable. The second parameter limits a height to the scrolling area.

    3. Path.getfilename is used to get the file name (including the extension) in a path, and the path class has a lot of static functions about the path operation and is interested in digging it yourself.

    4. Editorguilayout.toggleleft Create a box at the left and the text in the Right check box. The first argument is the text to be displayed next to the box, and the second argument is a bool variable that represents the check box's selected state. Again, the function return value is to be paid to this parameter, otherwise the check box is not selectable, so we want to define an array of type bool with the same length as Assetspath.

This is the basic operation, and with these basics, it's not a problem to make other tricks.

I'll see you next time.

Strength Package: Unity Pack Assetbundle (iv)

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.