Ejemplo n.º 1
0
    public System.Collections.Generic.List <GameObject> getObjectsOnlyInA(WorldBox boxA, WorldBox boxB)
    {
        System.Collections.Generic.List <GameObject>    results = new System.Collections.Generic.List <GameObject>();
        System.Collections.Generic.HashSet <GameObject> localItems;
        IndexBox box1 = this.getIndexBoxFromWorldBox(boxA);
        IndexBox box2 = this.getIndexBoxFromWorldBox(boxB);

        int[] coordinates = new int[2];
        int[] indices     = new int[2];
        //int i;
        IndexBox itemIndexBox;

        //GameObject currentItem;
        // Check each box inside the larger indexbox
        for (coordinates[0] = box1.getLowCoordinate(0); coordinates[0] <= box1.getHighCoordinate(0); coordinates[0]++)
        {
            // wraparound
            indices[0] = coordinates[0] % this.numBlocks[0];
            if (indices[0] < 0)
            {
                indices[0] += this.numBlocks[0];
            }
            for (coordinates[1] = box1.getLowCoordinate(1); coordinates[1] <= box1.getHighCoordinate(1); coordinates[1]++)
            {
                // wraparound
                indices[1] = coordinates[1] % this.numBlocks[1];
                if (indices[1] < 0)
                {
                    indices[1] += this.numBlocks[1];
                }
                // Make sure that the current point isn't inside the smaller index box
                if (!(box2.contains(coordinates)))
                {
                    // Iterate over each item inside the box
                    localItems = this.worldBlocks[indices[0], indices[1]];
                    foreach (GameObject currentItem in localItems)
                    {
                        //currentItem = localItems[i];
                        itemIndexBox = this.getIndexBoxFromWorldBox(currentItem.getBoundingBox());
                        // Make sure that the item does intersect the larger box but not the smaller index box
                        if (itemIndexBox.intersects(box1) && !(itemIndexBox.intersects(box2)))
                        {
                            // Now add it to the resultant list if needed
                            if (!results.Contains(currentItem))
                            {
                                results.Add(currentItem);
                            }
                        }
                    }
                }
            }
        }
        return(results);
    }