AreBoxexOverlapping() public static method

public static AreBoxexOverlapping ( GameObject box1, Vector3 box2Size, Vector3 box2Position ) : bool
box1 GameObject
box2Size Vector3
box2Position Vector3
return bool
Esempio n. 1
0
    public bool IsGameObjectIn(GameObject box1, GameObject box2)
    {
        Vector3 size     = box2.transform.localScale;
        Vector3 position = box2.transform.position;

        return(OOBCollisionDetection.AreBoxexOverlapping(box1, size, position));
    }
Esempio n. 2
0
    void Update()
    {
        if (!LoadingCorrupted && Generator.generatorDone && !FileLoaded && SaveFileExist() && !GenerationDone)
        {
            FileLoaded = LoadFile();

            if (FileLoaded == false)
            {
                LoadingCorrupted = true;
            }
            else
            {
                GenerationDone = true;
                Debug.Log("Waypoints succesfully loaded from file");
                SaveToFile();
            }
        }
        else if (!GenerationDone && QuadTree.generationDone && Generator.generatorDone)
        {
            for (int i = 0; i < pathNodes.Count; i++)
            {
                if (pathNodes[i] != null)
                {
                    pathNodes[i].nodeValid = false;
                    pathNodes[i]           = null;
                }
            }

            pathNodes.Clear();

            Debug.Log("Waypoint generation");

            QuadTree qt = GameObject.Find("QuadTreeGenerator").GetComponent <QuadTree>();

            float startX = CenterX - Width / 2.0f;
            float startY = CenterY - Width / 2.0f;

            float endX = CenterX + Width / 2.0f;
            float endY = CenterY + Width / 2.0f;


            matrix = new PathNode[(int)Width][];

            for (int x = 0; x < Width; x += 1)
            {
                matrix[x] = new PathNode[(int)Width];

                for (int y = 0; y < Width; y += 1)
                {
                    matrix[x][y] = null;
                }
            }

            int   x1, y1;
            float xf;
            float yf;

            for (xf = startX, x1 = 0; xf < endX && x1 < Width; xf += Step, x1++)
            {
                for (yf = startY, y1 = 0; yf < endY && y1 < Width; yf += Step, y1++)
                {
                    Vector3 position = new Vector3(xf, 0.5f, yf);

                    //List<GameObject> result = qt.GetObjectsInside(position);

                    QuadTreeItem qi = qt.GetQuadTreeItemFor(position, 4);

                    if (qi == null || qi.GameObjects == null)
                    {
                        continue;
                    }

                    GameObject closest = GetClosestObject(qi, position);

                    if (IsInside(qi.GameObjects, position))
                    {
                        continue;
                    }

                    if (closest == null || (closest != null && Vector3.Distance(closest.transform.position, position) > 1.0f))
                    {
                        PrepareNode(x1, y1, position, "regular generation");
                    }
                    else
                    {
                        matrix[x1][y1] = null;
                    }
                }
            }

            //SaveToFile();

            GenerationDone = true;

            GameObject enemyGenerator = GameObject.Find("EnemyGenerator");

            if (QuadTree.waypointsNeedRegeneration)
            {
                enemyGenerator.GetComponent <EnemyGenerator>().WaypointSystemChangedCallback();
            }

            QuadTree.waypointsNeedRegeneration = false;
        }
        else if (QuadTree.waypointsNeedRegeneration && !QuadTree.rebuildingQuadTree)
        {
            QuadTree qt = GameObject.Find("QuadTreeGenerator").GetComponent <QuadTree>();

            Debug.Log("Regenerating waypoints (selective)");

            float startX = CenterX - Width / 2.0f;
            float startY = CenterY - Width / 2.0f;

            float endX = CenterX + Width / 2.0f;
            float endY = CenterY + Width / 2.0f;

            int   x1, y1;
            float xf, yf;

            Debug.Log("Qti's to regenerate: " + qt.qtisToRegenerate.Count);

            foreach (QuadTreeItem qti in qt.qtisToRegenerate)
            {
                for (xf = startX, x1 = 0; xf < endX && x1 < Width; xf += Step, x1++)
                {
                    for (yf = startY, y1 = 0; yf < endY && y1 < Width; yf += Step, y1++)
                    {
                        Vector3 position = new Vector3(xf, 0.5f, yf);

                        if (OOBCollisionDetection.AreBoxexOverlapping(qti.Size, qti.Position, new Vector3(Step, Step, Step), position))
                        {
                            if (IsInside(qti.GameObjects, position))
                            {
                                PathNodeDelete(position);
                                continue;
                            }

                            if (matrix[x1][y1] != null && matrix[x1][y1].nodeEnabled)
                            {
                                continue;
                            }

                            GameObject closest = GetClosestObject(qti, position);

                            if (closest == null || (closest != null && Vector3.Distance(closest.transform.position, position) > 1.0f))
                            {
                                PrepareNode(x1, y1, position, "regenerate" + qti.name);
                            }
                        }
                    }
                }
            }

            qt.qtisToRegenerate.Clear();

            GameObject enemyGenerator = GameObject.Find("EnemyGenerator");
            enemyGenerator.GetComponent <EnemyGenerator>().WaypointSystemChangedCallback();
            QuadTree.waypointsNeedRegeneration = false;
        }
    }
Esempio n. 3
0
    public bool IsGameObjectIn(GameObject bigger, Vector3 smallerPos)
    {
        Vector3 size = new Vector3(Width, 1, Width);

        return(OOBCollisionDetection.AreBoxexOverlapping(bigger, size, smallerPos));
    }