Additional static functions and constants used to extend existing Component support inside of Unity.
More...
|
static T | AddComponent< T > (this GameObject targetObject, T cachedReference) |
| Adds a component to a GameObject, if that component is not already present. More...
|
|
static T | GetComponentIfNull< T > (this Component targetObject, T cachedReference) |
| Get a component reference, checking if its already referenced. More...
|
|
static T | GetComponentIfNull< T > (this GameObject targetObject, T cachedReference) |
| Get a component reference, checking if its already referenced. More...
|
|
static T | GetComponentInParents< T > (this GameObject targetObject, T cachedReference) |
| Get a component reference from a gameObjects parents. More...
|
|
static bool | HasComponent< T > (this GameObject targetObject, T cachedReference) |
| Does the GameObject have the component? More...
|
|
Additional static functions and constants used to extend existing Component support inside of Unity.
Definition at line 37 of file Components.cs.
static T Hydrogen.Components.AddComponent< T > |
( |
this GameObject |
targetObject, |
|
|
T |
cachedReference |
|
) |
| |
|
static |
Adds a component to a GameObject, if that component is not already present.
- Returns
- The desired component.
- Parameters
-
targetObject | The root object to add the component to. |
cachedReference | Possible pre-existing reference to component. |
- Template Parameters
-
private AudioSource _localAudioSource = null; public void Start() { _localAudioSource = gameObject.AddComponent<AudioSource>(_localAudioSource); }
Definition at line 58 of file Components.cs.
60 if (cachedReference != null) {
61 return cachedReference;
64 T component = (T)targetObject.GetComponent (typeof(T)) ?? (T)targetObject.AddComponent (typeof(T));
static T Hydrogen.Components.GetComponentIfNull< T > |
( |
this Component |
targetObject, |
|
|
T |
cachedReference |
|
) |
| |
|
static |
Get a component reference, checking if its already referenced.
- Returns
- The desired component.
- Parameters
-
targetObject | The object to look on for the component. |
cachedReference | Possible pre-existing reference to component. |
- Template Parameters
-
private AudioSource _localAudioSource = null; public AudioSource LocalAudioSource { get { _localAudioSource = Hydrogen.Components.GetComponentIfNull( this, _localAudioSource ); return _localAudioSource; } }
Definition at line 87 of file Components.cs.
89 if (cachedReference == null) {
90 cachedReference = (T)targetObject.GetComponent (typeof(T));
91 if (cachedReference == null) {
92 Debug.LogWarning (
"GetComponent of type " + typeof(T) +
" failed on " + targetObject.name, targetObject);
96 return cachedReference;
static T Hydrogen.Components.GetComponentIfNull< T > |
( |
this GameObject |
targetObject, |
|
|
T |
cachedReference |
|
) |
| |
|
static |
Get a component reference, checking if its already referenced.
- Returns
- The desired component.
- Parameters
-
targetObject | The object to look on for the component. |
cachedReference | Possible pre-existing reference to component. |
- Template Parameters
-
private AudioSource _localAudioSource = null; public AudioSource LocalAudioSource { get { _localAudioSource = Hydrogen.Components.GetComponentIfNull( this, _localAudioSource ); return _localAudioSource; } }
Definition at line 117 of file Components.cs.
119 if (cachedReference == null) {
120 cachedReference = (T)targetObject.GetComponent (typeof(T));
121 if (cachedReference == null) {
122 Debug.LogWarning (
"GetComponent of type " + typeof(T) +
" failed on " + targetObject.name, targetObject);
126 return cachedReference;
static T Hydrogen.Components.GetComponentInParents< T > |
( |
this GameObject |
targetObject, |
|
|
T |
cachedReference |
|
) |
| |
|
static |
Get a component reference from a gameObjects parents.
- Returns
- The desired component.
- Parameters
-
targetObject | The root object to look on for the component (backwards). |
cachedReference | Possible pre-existing reference to component. |
- Template Parameters
-
private AudioSource _localAudioSource = null; public AudioSource LocalAudioSource { get { _localAudioSource = Hydrogen.Components.GetComponentInParents( this, _localAudioSource ); return _localAudioSource; } }
Definition at line 147 of file Components.cs.
149 if (cachedReference == null) {
150 Transform p = targetObject.transform.parent;
153 var t = (T)targetObject.GetComponent (typeof(T));
158 return cachedReference;
165 if (cachedReference == null) {
166 Debug.LogWarning (
"GetComponentInParents of type " + typeof(T) +
" failed on " + targetObject.name, targetObject);
170 return cachedReference;
static bool Hydrogen.Components.HasComponent< T > |
( |
this GameObject |
targetObject, |
|
|
T |
cachedReference |
|
) |
| |
|
static |
Does the GameObject have the component?
- Returns
- If the component is added to the GameObject
- Parameters
-
targetObject | The root object to look on for the component. |
cachedReference | Possible pre-existing reference to component. |
- Template Parameters
-
private AudioSource _localAudioSource = null; public void Start() { if (gameObject.HasComponent(_localAudioSource) == false) { _localAudioSource = gameObject.AddComponent<AudioSource>(); } }
Definition at line 190 of file Components.cs.
192 return cachedReference != null || targetObject.GetComponent (typeof(T)) != null;
const string Hydrogen.Components.DefaultSingletonName = "Hydrogen" |
The GameObject name used when creating singletons automatically via any of the Hydrogen components.
Definition at line 42 of file Components.cs.