Exemplo n.º 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());
        }
Exemplo n.º 2
0
    void OverlapCheck()
    {
        //Overlap Check
        ShapeObject[] shapes = ShapeQuadTree.OverlapRect(mousePoint, checkRegion);

        foreach (var shape in shapes)
        {
            shape.SetColor(Color.black * 0.8f);
        }

        checkAngle += Input.mouseScrollDelta.y * 5;
        ShapeObject[] overlap = ShapesCollision.OverlapRectangle(mousePoint, checkAngle, checkRegion);
        foreach (var shape in overlap)
        {
            shape.SetColor(Color.white);
        }
        text.text = overlap.Length.ToString();
        text.transform.position = new Vector3(mousePoint.x, mousePoint.y);
    }
Exemplo n.º 3
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);
                    }
                }
            }
        }
Exemplo n.º 4
0
    void RayCastCheck()
    {
        if (Input.GetMouseButtonDown(1))
        {
            lineOrigin = mousePoint;
        }

        Vector3 dirction = mousePoint - lineOrigin;

        ShapeObject[] shapes = ShapeQuadTree.OverlapLine(lineOrigin, dirction);

        foreach (var shape in shapes)
        {
            shape.SetColor(Color.black * 0.8f);
        }

        shapes = ShapesCollision.RayCast(lineOrigin, dirction);
        foreach (var shape in shapes)
        {
            shape.SetColor(Color.white * 0.8f);
        }
        text.text = shapes.Length.ToString();
        text.transform.position = lineOrigin;
    }
Exemplo n.º 5
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());
        }