Unity Plugin Development--selection

Source: Internet
Author: User
Tags unique id

Selection is a static class whose primary function is to get the object selected by the mouse in the Project window or the currently displayed object of the Inspector window. It has a field

Activegameobject

Activeinstanceid

Activeobject

Activetransform

Gameobjects

Instanceids

Objects

Transforms

Where Activegameobject and Activetransform are the gameobject and transform that correspond to the current display object of the Inspector window. Join is not currently a gameobject, then Activegameobject is empty, Activetransform is the same. Activeinstanceid is the unique ID of the selected file in the project, and the unique file can be found by this ID. Objects is a multi-choice case of all selected objects, these objects can be of various types, generally, unresolved objects, such as folders, ordinary files, the default is the object type. Compared to gameobjects, the official is more recommended to use transforms, their role is only to select all the objects to do type matching filter, return the results after filtering.

In these fields, the use of more is activeobject,objects, because it is a base class, so we can do a variety of judgments and processing. Like what:

var objs=selection.objects;

foreach (Var obj in Objs)

{

if (obj is Gameobject)

Debug.log (Obj.name);

}

The above code is the traversal of all selected objects, if the object is Gameobject (prefab is also gameobject), output the name of the object.

In addition, selection provides a contains method to determine whether the selected object does contain an object, and also provides a getfiltered method for filtering.

Unity Plugin Development--selection

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.