-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCommon.Tag.cs
48 lines (42 loc) · 1.35 KB
/
Common.Tag.cs
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
using System.Linq;
using UnityEngine;
namespace VirtueSky.Misc
{
public static partial class Common
{
public static T FindComponentInChildWithTag<T>(this GameObject parent, string tag) where T : Component
{
Transform t = parent.transform;
foreach (Transform tr in t)
{
if (tr.tag == tag)
{
return tr.GetComponent<T>();
}
}
return null;
}
public static GameObject SetLayerForAllChildObject(this GameObject obj, int layerIndex)
{
obj.layer = layerIndex;
obj.GetComponentsInChildren<Transform>().ToList().ForEach(x => { x.gameObject.layer = layerIndex; });
return obj;
}
public static GameObject SetLayer(this GameObject obj, int layerIndex)
{
obj.layer = layerIndex;
return obj;
}
public static GameObject SetTagForAllChildObject(this GameObject obj, string tag)
{
obj.tag = tag;
obj.GetComponentsInChildren<Transform>().ToList().ForEach(x => { x.gameObject.tag = tag; });
return obj;
}
public static GameObject SetTag(this GameObject obj, string tag)
{
obj.gameObject.tag = tag;
return obj;
}
}
}