예제 #1
0
        public static T GetFirstMatchingComponentInParentsOrWarn <T>(this Component behaviour) where T : Component
        {
            Transform currentParent = behaviour.transform.parent;
            T         result        = null;

            while (result == null && currentParent != null)
            {
                result        = currentParent.GetComponent <T>();
                currentParent = currentParent.parent;
            }
            if (result == null)
            {
                Logging.Warning("{0}: Component of type {1} could not be found in any parent game object.", behaviour.name, TypeUtil.NameOf <T>());
            }
            return(result);
        }
예제 #2
0
 public static void UpdateBufferForStruct <T>(T UpdatedValue, ComputeBuffer buffer)
 {
     if (buffer != null &&
         buffer.count == 1 &&
         buffer.stride == SizeInBytes <T>())
     {
         var list = new List <T>()
         {
             UpdatedValue
         };
         buffer.SetData(list);
     }
     else
     {
         Logging.Warning <ComputeBuffer>("Unable to update ComputeBuffer with updated value of type {0}", TypeUtil.NameOf <T>());
     }
 }
예제 #3
0
        public static T FindComponentInParents <T>(this GameObject gameObject) where T : Component
        {
            Transform currentParent = gameObject.transform.parent;
            T         result        = null;

            while (result == null && currentParent != null)
            {
                result        = currentParent.GetComponent <T>();
                currentParent = currentParent.parent;
            }
            if (result == null)
            {
                Logging.Warning("{0}: Component of type {1} could not be found in any parent game object.", gameObject.name, TypeUtil.NameOf <T>());
            }
            return(result);
        }
예제 #4
0
 private static void ExceptionIfInvalidArray <T>(T[] values)
 {
     if (values == null)
     {
         throw new ArgumentException(string.Format("Invalid Argument: NULL of type '{0}' Arrary given for ComputeBuffer", TypeUtil.NameOf <T>()));
     }
     if (values.Length == 0)
     {
         throw new ArgumentException(
                   string.Format("Invalid Argument: Type '{0}' Array of 0 length given for ComputeBuffer", TypeUtil.NameOf <T>())
                   );
     }
 }