Unity3d Mouse picking small function collection

Source: Internet
Author: User

Recently, some optimization tools have been made to extract the mouse-picking function separately.

Can traverse all selected types of resources, recursively folders

Can compile a component of all prefab, which is also recursive

Using unityengine;using system.collections;using unityeditor;using system.collections.generic;using System.componentmodel;using Object = unityengine.object;//Find public static class Enumselection {//Enumerate all resources of type T in the selected resource public static ienumerable<t> enumincurrentselection<t> () where t:object{object[] Selectionasset = Selection.getfiltered (typeof (Object), selectionmode.deepassets), foreach (Var s in selectionasset) {var temp = s as t;if (n Ull! = temp) {yield return temp;}} Yield break;} Enumerates all the gameobject types of resources public static ienumerable<gameobject> enumgameobjectincurrentselection () {foreach (var s) In Enumincurrentselection<gameobject> ()) {yield return s;} Yield break;} Recursively enumerates all gameobjectpublic static ienumerable<gameobject> enumgameobjectrecursiveincurrentselection () {foreach (Var s in enumincurrentselection<gameobject> ()) {foreach (var g in enumgameobjectrecursive (s)) {yield return g;}}} public static ienumerable<gameobject> enumgameobjectrecursive (Gameobject gO) {yield return go;for (int i=0; i<go.transform.childcount; i++) {foreach (Var t in Enumgameobjectrecursive ( Go.transform.GetChild (i). Gameobject) {yield return t;}}} Recursively enumerates all compoentpublic static ienumerable<t> enumcomponentrecursiveincurrentselection<t> () where T: Unityengine.component{foreach (Var go in enumincurrentselection<gameobject> ()) {foreach (var c in go.) Getcomponentsinchildren<t> (True)) {yield return C;}}}

  

Unity3d Mouse picking small function collection

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.