-
Notifications
You must be signed in to change notification settings - Fork 0
/
Behavior.cs
98 lines (86 loc) · 2.41 KB
/
Behavior.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
using UnityEngine;
using System.Collections.Generic;
namespace UnityBasics
{
/// <summary>
/// A base class for Unity script components that a protected interface for
/// convenient use in scripts.
/// </summary>
public abstract class Behavior : MonoBehaviour
{
/// <summary>
/// Get all immediate children of the <c>Transform</c>.
/// </summary>
protected IEnumerable<Transform> Children()
{
return transform.Children();
}
/// <summary>
/// Get all descendants of the <c>Transform</c>.
/// </summary>
protected IEnumerable<Transform> Descendants()
{
return transform.Descendants();
}
/// <summary>
/// Get lineage of <c>Transform</c>. ie. its parent, its parent's
/// parent etc.
/// </summary>
protected IEnumerable<Transform> Ancestors()
{
return transform.Ancestors();
}
protected Transform Parent()
{
return transform.parent;
}
/// <summary>
/// Return <c>Transform</c> and all its immediate children.
/// </summary>
protected IEnumerable<Transform> SelfChildren()
{
return transform.SelfChildren();
}
/// <summary>
/// Return <c>Transform</c> and all its descendants.
/// </summary>
protected IEnumerable<Transform> SelfDescendants()
{
return transform.SelfDescendants();
}
/// <summary>
/// Return <c>Transform</c> and its ancestors.
/// </summary>
protected IEnumerable<Transform> SelfAncestors()
{
return transform.SelfAncestors();
}
/// <summary>
/// Get a <c>Component</c> attached to this <c>GameObject</c> or throw a
/// <c>ComponentNotFoundException</c>.
/// </summary>
protected TComponent Component<TComponent>()
where TComponent : Component
{
return gameObject.Component<TComponent>();
}
/// <summary>
/// Get a <c>Component</c> attached to this <c>GameObject</c> or return
/// null.
/// </summary>
protected TComponent ComponentOrNull<TComponent>()
where TComponent : Component
{
return gameObject.ComponentOrNull<TComponent>();
}
/// <summary>
/// Get all <c>Component</c>s of a given type attached to this
/// <c>GameObject</c>.
/// </summary>
protected IEnumerable<TComponent> Components<TComponent>()
where TComponent : Component
{
return gameObject.Components<TComponent>();
}
}
}