zoukankan      html  css  js  c++  java
  • Unity3d 鼠标拣选小功能集合

    最近在做一些优化工具,把鼠标拣选的功能单独抽出来。

    可遍历所有选中的某类型资源,会递归文件夹

    可编译所有prefab的某个Component,也是递归的

    using UnityEngine;
    using System.Collections;
    using UnityEditor;
    using System.Collections.Generic;
    using System.ComponentModel;
    using Object = UnityEngine.Object;
    
    //在选中的资源中查找
    public static class EnumSelection {
    
    	//枚举所有的T类型的资源 
    	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 (null != temp)
    			{
    				yield return temp;
    			}
    		}
    
    		yield break;
    	}
    
    	//枚举所有的GameObject类型的资源 
    	public static IEnumerable<GameObject> EnumGameObjectInCurrentSelection()  
    	{
    		foreach (var s in EnumInCurrentSelection<GameObject>())
    		{
    			yield return s;
    		}
    
    		yield break;
    	}
    
    	//递归枚举所有GameObject
    	public 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;
    			}
    		}
    	}
    
    	//递归枚举所有Compoent
    	public 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;
    			}
    		}
    	}
    
    }
    

      

  • 相关阅读:
    承载进程 (vshost.exe)
    命令行生成解决方案
    【SQL Server】存储过程的设计概念(3)TSQL的编译和执行过程
    .NET Framework 4
    reflector最新说明
    应用程序域
    vi 编辑器的用法(2013最新整理)
    linux中查看日志的方法
    修改linux主机名的方法介绍
    如何获得桌面上任意一个位置的颜色的 rgb 或者16进制值了
  • 原文地址:https://www.cnblogs.com/mrblue/p/4962998.html
Copyright © 2011-2022 走看看