Advertisement
Guest User

Untitled

a guest
Jun 30th, 2015
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.92 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using NoobsUnited;
  4. using NoobsUnited.Swizzle;
  5.  
  6. namespace UnityEngine
  7. {
  8.     public partial class VPhysics2D : MonoBehaviour
  9.     {
  10.         public static RaycastHit2D[]  BoxCastAll(Vector2 origin, Vector2 size, float angle, Vector2 direction, float distance = Mathf.Infinity, int layerMask = Physics.DefaultRaycastLayers, float minDepth = -Mathf.Infinity, float maxDepth = Mathf.Infinity)
  11.         {
  12.             GenerateRenderer ();
  13.             CubeGeometry originGeometry = new CubeGeometry(origin, size);
  14.             RaycastHit2D[] hits = Physics2D.BoxCastAll (origin, size, angle, direction, distance, layerMask, minDepth, maxDepth);
  15.             if(hits.Length > 0)
  16.             {
  17.                 foreach(RaycastHit2D hit in hits)
  18.                 {
  19.                     originGeometry.contactPoints.Add (hit.point);
  20.                 }
  21.                
  22.                 CubeGeometry endCube = new CubeGeometry(origin + direction * distance, size);
  23.                 endCube.color.a = .5f;
  24.                 _geometry.Add (endCube);
  25.                
  26.                 LineGeometry directionIndicatorAbove = new LineGeometry(origin + Vector2.up * size.y, endCube.origin.xy() + Vector2.up * size.y);
  27.                 directionIndicatorAbove.color.a = .3f;
  28.                 _geometry.Add (directionIndicatorAbove);
  29.                
  30.                 LineGeometry directionIndicatorBelow = new LineGeometry(origin - Vector2.up * size.y, endCube.origin.xy() - Vector2.up * size.y);
  31.                 directionIndicatorBelow.color.a = .3f;
  32.                 _geometry.Add (directionIndicatorBelow);
  33.             }
  34.             else
  35.             {
  36.                 if(distance == Mathf.Infinity)
  37.                 {
  38.                     _geometry.Add (new LineGeometry(originGeometry.origin, originGeometry.origin + (Vector3)direction.normalized * maxShapeCastDistance));
  39.                    
  40.                     CubeGeometry endCube = new CubeGeometry(origin + direction * maxShapeCastDistance, size);
  41.                     endCube.color.a = .5f;
  42.                     _geometry.Add (endCube);
  43.                    
  44.                     LineGeometry directionIndicatorAbove = new LineGeometry(origin + Vector2.up * size.y, endCube.origin.xy() + Vector2.up * size.y);
  45.                     directionIndicatorAbove.color.a = .3f;
  46.                     _geometry.Add (directionIndicatorAbove);
  47.                    
  48.                     LineGeometry directionIndicatorBelow = new LineGeometry(origin - Vector2.up * size.y, endCube.origin.xy() - Vector2.up * size.y);
  49.                     directionIndicatorBelow.color.a = .3f;
  50.                     _geometry.Add (directionIndicatorBelow);
  51.                 }
  52.                 else if(distance != Mathf.Infinity && distance >= 0)
  53.                 {
  54.                     CubeGeometry endCube = new CubeGeometry(origin + direction * distance, size);
  55.                     endCube.color.a = .5f;
  56.                     _geometry.Add (endCube);
  57.                    
  58.                     LineGeometry directionIndicatorAbove = new LineGeometry(origin + Vector2.up * size.y, endCube.origin.xy() + Vector2.up * size.y);
  59.                     directionIndicatorAbove.color.a = .3f;
  60.                     _geometry.Add (directionIndicatorAbove);
  61.                    
  62.                     LineGeometry directionIndicatorBelow = new LineGeometry(origin - Vector2.up * size.y, endCube.origin.xy() - Vector2.up * size.y);
  63.                     directionIndicatorBelow.color.a = .3f;
  64.                     _geometry.Add (directionIndicatorBelow);
  65.                 }
  66.             }
  67.            
  68.             _geometry.Add(originGeometry);
  69.             return hits;
  70.         }
  71.     }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement