示例#1
0
        static ShapeObject[] OverlapCheck(Vector3 point, Vector3 size, Func <ShapeObject, CollisionData> CollidedCheckHandler)
        {
            ShapeObject[]      checking       = ShapeQuadTree.OverlapRect(point, size);
            List <ShapeObject> IsOverlapShape = new List <ShapeObject>();

            for (int i = 0; i < checking.Length; i++)
            {
                ShapeObject checkedShape = checking[i];
                if (CollidedCheckHandler.Invoke(checkedShape).HasCollision)
                {
                    IsOverlapShape.Add(checkedShape);
                }
            }

            return(IsOverlapShape.ToArray());
        }
示例#2
0
        static void GlobalCollisionCheck()
        {
            for (int i = 0; i < ShapeObject.ShapeObjects.Count; i++)
            {
                ShapeObject checkedShape = ShapeObject.ShapeObjects[i];
                Color       shapeColor   = checkedShape.RigidbodyType == RigidbodyType.Dynamic ? Color.green : checkedShape.RigidbodyType == RigidbodyType.Kinmatic ? Color.blue : Color.red;
                checkedShape.SetColor(shapeColor);

                ShapeObject[] checkedTargets = ShapeQuadTree.OverlapShape(checkedShape);

                for (int ti = 0; ti < checkedTargets.Length; ti++)
                {
                    ShapeObject target = checkedTargets[ti];

                    CollisionData collision = ShapesCollision.IsShapesCollided(checkedShape, target);
                    if (collision.HasCollision)
                    {
                        OnShapesCollisionEvent?.Invoke(checkedShape, target, collision);
                    }
                }
            }
        }
示例#3
0
        //Raycast Check
        public static ShapeObject[] RayCast(Vector3 origin, Vector3 dirction)
        {
            dirction = dirction.normalized;

            ShapeObject[]      checking       = ShapeQuadTree.OverlapLine(origin, dirction);
            List <ShapeObject> IsCastHitShape = new List <ShapeObject>();

            if (DrawOverlap)
            {
                Debug.DrawRay(origin, dirction * 50);
            }

            for (int i = 0; i < checking.Length; i++)
            {
                ShapeObject checkedShape  = checking[i];
                Vector3     rayProjection = Vector2.Perpendicular(dirction);
                if (ShapeDirctionOfRayCast(checkedShape, origin, dirction) && ShapeProjectionOverlapWithPoint(checkedShape, origin, rayProjection).HasCollision)
                {
                    IsCastHitShape.Add(checkedShape);
                }
            }

            return(IsCastHitShape.ToArray());
        }
示例#4
0
 public ElasticCollisionData(ShapeObject collision, ShapeObject target, CollisionData collisionData)
 {
     this.onCollision   = collision;
     this.target        = target;
     this.collisionData = collisionData;
 }