Created
July 11, 2015 14:41
-
-
Save baba-s/ec65b88f4cc553ca8bd4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class NullableComponentExtensions | |
{ | |
public static UnityEngine.Component GetComponentIfNotNull( this UnityEngine.Component self, System.Type type ) | |
{ | |
if ( self == null ) | |
{ | |
return default( UnityEngine.Component ); | |
} | |
return self.GetComponent( type ); | |
} | |
public static T GetComponentIfNotNull<T>( this UnityEngine.Component self ) | |
{ | |
if ( self == null ) | |
{ | |
return default( T ); | |
} | |
return self.GetComponent<T>( ); | |
} | |
public static UnityEngine.Component GetComponentIfNotNull( this UnityEngine.Component self, System.String type ) | |
{ | |
if ( self == null ) | |
{ | |
return default( UnityEngine.Component ); | |
} | |
return self.GetComponent( type ); | |
} | |
public static UnityEngine.Component GetComponentInChildrenIfNotNull( this UnityEngine.Component self, System.Type t ) | |
{ | |
if ( self == null ) | |
{ | |
return default( UnityEngine.Component ); | |
} | |
return self.GetComponentInChildren( t ); | |
} | |
public static T GetComponentInChildrenIfNotNull<T>( this UnityEngine.Component self ) | |
{ | |
if ( self == null ) | |
{ | |
return default( T ); | |
} | |
return self.GetComponentInChildren<T>( ); | |
} | |
public static UnityEngine.Component[] GetComponentsInChildrenIfNotNull( this UnityEngine.Component self, System.Type t ) | |
{ | |
if ( self == null ) | |
{ | |
return default( UnityEngine.Component[] ); | |
} | |
return self.GetComponentsInChildren( t ); | |
} | |
public static UnityEngine.Component[] GetComponentsInChildrenIfNotNull( this UnityEngine.Component self, System.Type t, System.Boolean includeInactive ) | |
{ | |
if ( self == null ) | |
{ | |
return default( UnityEngine.Component[] ); | |
} | |
return self.GetComponentsInChildren( t, includeInactive ); | |
} | |
public static T[] GetComponentsInChildrenIfNotNull<T>( this UnityEngine.Component self, System.Boolean includeInactive ) | |
{ | |
if ( self == null ) | |
{ | |
return default( T[] ); | |
} | |
return self.GetComponentsInChildren<T>( includeInactive ); | |
} | |
public static void GetComponentsInChildrenIfNotNull<T>( this UnityEngine.Component self, System.Boolean includeInactive, System.Collections.Generic.List<T> result ) | |
{ | |
if ( self == null ) | |
{ | |
return; | |
} | |
self.GetComponentsInChildren<T>( includeInactive, result ); | |
} | |
public static T[] GetComponentsInChildrenIfNotNull<T>( this UnityEngine.Component self ) | |
{ | |
if ( self == null ) | |
{ | |
return default( T[] ); | |
} | |
return self.GetComponentsInChildren<T>( ); | |
} | |
public static void GetComponentsInChildrenIfNotNull<T>( this UnityEngine.Component self, System.Collections.Generic.List<T> results ) | |
{ | |
if ( self == null ) | |
{ | |
return; | |
} | |
self.GetComponentsInChildren<T>( results ); | |
} | |
public static UnityEngine.Component GetComponentInParentIfNotNull( this UnityEngine.Component self, System.Type t ) | |
{ | |
if ( self == null ) | |
{ | |
return default( UnityEngine.Component ); | |
} | |
return self.GetComponentInParent( t ); | |
} | |
public static T GetComponentInParentIfNotNull<T>( this UnityEngine.Component self ) | |
{ | |
if ( self == null ) | |
{ | |
return default( T ); | |
} | |
return self.GetComponentInParent<T>( ); | |
} | |
public static UnityEngine.Component[] GetComponentsInParentIfNotNull( this UnityEngine.Component self, System.Type t ) | |
{ | |
if ( self == null ) | |
{ | |
return default( UnityEngine.Component[] ); | |
} | |
return self.GetComponentsInParent( t ); | |
} | |
public static UnityEngine.Component[] GetComponentsInParentIfNotNull( this UnityEngine.Component self, System.Type t, System.Boolean includeInactive ) | |
{ | |
if ( self == null ) | |
{ | |
return default( UnityEngine.Component[] ); | |
} | |
return self.GetComponentsInParent( t, includeInactive ); | |
} | |
public static T[] GetComponentsInParentIfNotNull<T>( this UnityEngine.Component self, System.Boolean includeInactive ) | |
{ | |
if ( self == null ) | |
{ | |
return default( T[] ); | |
} | |
return self.GetComponentsInParent<T>( includeInactive ); | |
} | |
public static void GetComponentsInParentIfNotNull<T>( this UnityEngine.Component self, System.Boolean includeInactive, System.Collections.Generic.List<T> results ) | |
{ | |
if ( self == null ) | |
{ | |
return; | |
} | |
self.GetComponentsInParent<T>( includeInactive, results ); | |
} | |
public static T[] GetComponentsInParentIfNotNull<T>( this UnityEngine.Component self ) | |
{ | |
if ( self == null ) | |
{ | |
return default( T[] ); | |
} | |
return self.GetComponentsInParent<T>( ); | |
} | |
public static UnityEngine.Component[] GetComponentsIfNotNull( this UnityEngine.Component self, System.Type type ) | |
{ | |
if ( self == null ) | |
{ | |
return default( UnityEngine.Component[] ); | |
} | |
return self.GetComponents( type ); | |
} | |
public static void GetComponentsIfNotNull( this UnityEngine.Component self, System.Type type, System.Collections.Generic.List<UnityEngine.Component> results ) | |
{ | |
if ( self == null ) | |
{ | |
return; | |
} | |
self.GetComponents( type, results ); | |
} | |
public static void GetComponentsIfNotNull<T>( this UnityEngine.Component self, System.Collections.Generic.List<T> results ) | |
{ | |
if ( self == null ) | |
{ | |
return; | |
} | |
self.GetComponents<T>( results ); | |
} | |
public static T[] GetComponentsIfNotNull<T>( this UnityEngine.Component self ) | |
{ | |
if ( self == null ) | |
{ | |
return default( T[] ); | |
} | |
return self.GetComponents<T>( ); | |
} | |
public static System.Boolean CompareTagIfNotNull( this UnityEngine.Component self, System.String tag ) | |
{ | |
if ( self == null ) | |
{ | |
return default( System.Boolean ); | |
} | |
return self.CompareTag( tag ); | |
} | |
public static void SendMessageUpwardsIfNotNull( this UnityEngine.Component self, System.String methodName, System.Object value, UnityEngine.SendMessageOptions options ) | |
{ | |
if ( self == null ) | |
{ | |
return; | |
} | |
self.SendMessageUpwards( methodName, value, options ); | |
} | |
public static void SendMessageUpwardsIfNotNull( this UnityEngine.Component self, System.String methodName, System.Object value ) | |
{ | |
if ( self == null ) | |
{ | |
return; | |
} | |
self.SendMessageUpwards( methodName, value ); | |
} | |
public static void SendMessageUpwardsIfNotNull( this UnityEngine.Component self, System.String methodName ) | |
{ | |
if ( self == null ) | |
{ | |
return; | |
} | |
self.SendMessageUpwards( methodName ); | |
} | |
public static void SendMessageUpwardsIfNotNull( this UnityEngine.Component self, System.String methodName, UnityEngine.SendMessageOptions options ) | |
{ | |
if ( self == null ) | |
{ | |
return; | |
} | |
self.SendMessageUpwards( methodName, options ); | |
} | |
public static void SendMessageIfNotNull( this UnityEngine.Component self, System.String methodName, System.Object value, UnityEngine.SendMessageOptions options ) | |
{ | |
if ( self == null ) | |
{ | |
return; | |
} | |
self.SendMessage( methodName, value, options ); | |
} | |
public static void SendMessageIfNotNull( this UnityEngine.Component self, System.String methodName, System.Object value ) | |
{ | |
if ( self == null ) | |
{ | |
return; | |
} | |
self.SendMessage( methodName, value ); | |
} | |
public static void SendMessageIfNotNull( this UnityEngine.Component self, System.String methodName ) | |
{ | |
if ( self == null ) | |
{ | |
return; | |
} | |
self.SendMessage( methodName ); | |
} | |
public static void SendMessageIfNotNull( this UnityEngine.Component self, System.String methodName, UnityEngine.SendMessageOptions options ) | |
{ | |
if ( self == null ) | |
{ | |
return; | |
} | |
self.SendMessage( methodName, options ); | |
} | |
public static void BroadcastMessageIfNotNull( this UnityEngine.Component self, System.String methodName, System.Object parameter, UnityEngine.SendMessageOptions options ) | |
{ | |
if ( self == null ) | |
{ | |
return; | |
} | |
self.BroadcastMessage( methodName, parameter, options ); | |
} | |
public static void BroadcastMessageIfNotNull( this UnityEngine.Component self, System.String methodName, System.Object parameter ) | |
{ | |
if ( self == null ) | |
{ | |
return; | |
} | |
self.BroadcastMessage( methodName, parameter ); | |
} | |
public static void BroadcastMessageIfNotNull( this UnityEngine.Component self, System.String methodName ) | |
{ | |
if ( self == null ) | |
{ | |
return; | |
} | |
self.BroadcastMessage( methodName ); | |
} | |
public static void BroadcastMessageIfNotNull( this UnityEngine.Component self, System.String methodName, UnityEngine.SendMessageOptions options ) | |
{ | |
if ( self == null ) | |
{ | |
return; | |
} | |
self.BroadcastMessage( methodName, options ); | |
} | |
public static System.String ToStringIfNotNull( this UnityEngine.Component self ) | |
{ | |
if ( self == null ) | |
{ | |
return default( System.String ); | |
} | |
return self.ToString( ); | |
} | |
public static System.Boolean EqualsIfNotNull( this UnityEngine.Component self, System.Object o ) | |
{ | |
if ( self == null ) | |
{ | |
return default( System.Boolean ); | |
} | |
return self.Equals( o ); | |
} | |
public static System.Int32 GetHashCodeIfNotNull( this UnityEngine.Component self ) | |
{ | |
if ( self == null ) | |
{ | |
return default( System.Int32 ); | |
} | |
return self.GetHashCode( ); | |
} | |
public static System.Int32 GetInstanceIDIfNotNull( this UnityEngine.Component self ) | |
{ | |
if ( self == null ) | |
{ | |
return default( System.Int32 ); | |
} | |
return self.GetInstanceID( ); | |
} | |
public static System.Type GetTypeIfNotNull( this UnityEngine.Component self ) | |
{ | |
if ( self == null ) | |
{ | |
return default( System.Type ); | |
} | |
return self.GetType( ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment