-
Notifications
You must be signed in to change notification settings - Fork 294
/
Copy pathCacheBehaviour.cs
140 lines (108 loc) · 5.23 KB
/
CacheBehaviour.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
using UnityEngine;
using System;
namespace UnityToolbag
{
/// <summary>
/// A safe, drop-in replacement for MonoBehaviour as your base class. Each property value is cached
/// and GetComponent will be called if the instance is null or is destroyed.
/// </summary>
public abstract class CacheBehaviour : MonoBehaviour
{
[HideInInspector, NonSerialized]
private Animation _animation;
/// <summary>
/// Gets the Animation attached to the object.
/// </summary>
public new Animation animation { get { return _animation ? _animation : (_animation = GetComponent<Animation>()); } }
[HideInInspector, NonSerialized]
private AudioSource _audio;
/// <summary>
/// Gets the AudioSource attached to the object.
/// </summary>
public new AudioSource audio { get { return _audio ? _audio : (_audio = GetComponent<AudioSource>()); } }
[HideInInspector, NonSerialized]
private Camera _camera;
/// <summary>
/// Gets the Camera attached to the object.
/// </summary>
public new Camera camera { get { return _camera ? _camera : (_camera = GetComponent<Camera>()); } }
[HideInInspector, NonSerialized]
private Collider _collider;
/// <summary>
/// Gets the Collider attached to the object.
/// </summary>
public new Collider collider { get { return _collider ? _collider : (_collider = GetComponent<Collider>()); } }
[HideInInspector, NonSerialized]
private Collider2D _collider2D;
/// <summary>
/// Gets the Collider2D attached to the object.
/// </summary>
public new Collider2D collider2D { get { return _collider2D ? _collider2D : (_collider2D = GetComponent<Collider2D>()); } }
[HideInInspector, NonSerialized]
private ConstantForce _constantForce;
/// <summary>
/// Gets the ConstantForce attached to the object.
/// </summary>
public new ConstantForce constantForce { get { return _constantForce ? _constantForce : (_constantForce = GetComponent<ConstantForce>()); } }
[HideInInspector, NonSerialized]
private GUIText _guiText;
/// <summary>
/// Gets the GUIText attached to the object.
/// </summary>
public new GUIText guiText { get { return _guiText ? _guiText : (_guiText = GetComponent<GUIText>()); } }
[HideInInspector, NonSerialized]
private GUITexture _guiTexture;
/// <summary>
/// Gets the GUITexture attached to the object.
/// </summary>
public new GUITexture guiTexture { get { return _guiTexture ? _guiTexture : (_guiTexture = GetComponent<GUITexture>()); } }
[HideInInspector, NonSerialized]
private HingeJoint _hingeJoint;
/// <summary>
/// Gets the HingeJoint attached to the object.
/// </summary>
public new HingeJoint hingeJoint { get { return _hingeJoint ? _hingeJoint : (_hingeJoint = GetComponent<HingeJoint>()); } }
[HideInInspector, NonSerialized]
private Light _light;
/// <summary>
/// Gets the Light attached to the object.
/// </summary>
public new Light light { get { return _light ? _light : (_light = GetComponent<Light>()); } }
[HideInInspector, NonSerialized]
private NetworkView _networkView;
/// <summary>
/// Gets the NetworkView attached to the object.
/// </summary>
public new NetworkView networkView { get { return _networkView ? _networkView : (_networkView = GetComponent<NetworkView>()); } }
[HideInInspector, NonSerialized]
private ParticleEmitter _particleEmitter;
/// <summary>
/// Gets the ParticleEmitter attached to the object.
/// </summary>
public new ParticleEmitter particleEmitter { get { return _particleEmitter ? _particleEmitter : (_particleEmitter = GetComponent<ParticleEmitter>()); } }
[HideInInspector, NonSerialized]
private ParticleSystem _particleSystem;
/// <summary>
/// Gets the ParticleSystem attached to the object.
/// </summary>
public new ParticleSystem particleSystem { get { return _particleSystem ? _particleSystem : (_particleSystem = GetComponent<ParticleSystem>()); } }
[HideInInspector, NonSerialized]
private Renderer _renderer;
/// <summary>
/// Gets the Renderer attached to the object.
/// </summary>
public new Renderer renderer { get { return _renderer ? _renderer : (_renderer = GetComponent<Renderer>()); } }
[HideInInspector, NonSerialized]
private Rigidbody _rigidbody;
/// <summary>
/// Gets the Rigidbody attached to the object.
/// </summary>
public new Rigidbody rigidbody { get { return _rigidbody ? _rigidbody : (_rigidbody = GetComponent<Rigidbody>()); } }
[HideInInspector, NonSerialized]
private Rigidbody2D _rigidbody2D;
/// <summary>
/// Gets the Rigidbody2D attached to the object.
/// </summary>
public new Rigidbody2D rigidbody2D { get { return _rigidbody2D ? _rigidbody2D : (_rigidbody2D = GetComponent<Rigidbody2D>()); } }
}
}