-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExternalTool.cs
More file actions
55 lines (46 loc) · 1.44 KB
/
ExternalTool.cs
File metadata and controls
55 lines (46 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
public class ExternalTool : MonoBehaviour
{
[MenuItem("Tool/GetComponent")]
public static void GetComponent()
{
List<CameraFacingBillboard> list = GetAllObjsOfType<CameraFacingBillboard>(false);
foreach (CameraFacingBillboard c in list)
{
c.enabled = false;
}
}
public static List<T> GetAllObjsOfType<T>(bool onlyRoot) where T : Component
{
T[] Objs = (T[])Resources.FindObjectsOfTypeAll(typeof(T));
List<T> returnObjs = new List<T>();
foreach (T Obj in Objs)
{
if (onlyRoot)
{
if (Obj.transform.parent != null)
{
continue;
}
}
if (Obj.hideFlags == HideFlags.NotEditable || Obj.hideFlags == HideFlags.HideAndDontSave)
{
continue;
}
if (Application.isEditor)
{
//检测资源是否存在,不存在会返回null或empty的字符串,存在会返回文件名
string sAssetPath = AssetDatabase.GetAssetPath(Obj.transform.root.gameObject);
if (!string.IsNullOrEmpty(sAssetPath))
{
continue;
}
}
returnObjs.Add(Obj);
}
return returnObjs;
}
}