-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathTransformX.cs
63 lines (58 loc) · 1.61 KB
/
TransformX.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using UnityEngine;
namespace UEx
{
/// <summary>
/// Transform extensions
/// </summary>
public static class TransformX
{
/// <summary>
/// Deep search the heirarchy of the specified transform for the name. Uses width-first search.
/// </summary>
/// <param name="t"></param>
/// <param name="name"></param>
/// <returns></returns>
static public Transform DeepSearch(this Transform t, string name)
{
Transform dt = t.Find(name);
if (dt != null)
{
return dt;
}
foreach (Transform child in t)
{
dt = child.DeepSearch(name);
if (dt != null)
return dt;
}
return null;
}
/// <summary>
/// opposite of up
/// </summary>
/// <param name="t"></param>
/// <returns></returns>
public static Vector3 down(this Transform t)
{
return -t.up;
}
/// <summary>
/// opposite of right
/// </summary>
/// <param name="t"></param>
/// <returns></returns>
public static Vector3 left(this Transform t)
{
return -t.right;
}
/// <summary>
/// opposite of forward
/// </summary>
/// <param name="t"></param>
/// <returns></returns>
public static Vector3 backward(this Transform t)
{
return -t.forward;
}
}
}