-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMonoBehaviourExt.cs
More file actions
61 lines (51 loc) · 1.17 KB
/
MonoBehaviourExt.cs
File metadata and controls
61 lines (51 loc) · 1.17 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
56
57
58
59
60
61
using UnityEngine;
namespace CCC.Runtime
{
/// <summary>
/// An extension of MonoBehaviour that provides cached access to commonly used components
/// (Transform and GameObject) with lazy initialization for improved performance.
/// </summary>
public class MonoBehaviourExt : MonoBehaviour
{
#region Private Fields
private Transform _transform;
private GameObject _gameObject;
private bool _transformSet;
private bool _gameObjectSet;
#endregion
#region Properties
/// <summary>
/// Gets the cached Transform component with lazy initialization.
/// </summary>
/// <value>The Transform component of this GameObject.</value>
public new Transform transform
{
get
{
if (!_transformSet)
{
_transform = base.transform;
_transformSet = true;
}
return _transform;
}
}
/// <summary>
/// Gets the cached GameObject with lazy initialization.
/// </summary>
/// <value>The GameObject this component is attached to.</value>
public new GameObject gameObject
{
get
{
if (!_gameObjectSet)
{
_gameObject = base.gameObject;
_gameObjectSet = true;
}
return _gameObject;
}
}
#endregion
}
}