示例#1
0
    // Private members

    // this is a stupid method , we should write better logic
    private void InitializeData( )
    {
        for (int r = 0; r < Constants.ROWS; r++)
        {
            for (int c = 0; c < Constants.COLS; c++)
            {
                int index = r * Constants.ROWS + c;

                int quad = GetQuadrant(r, c);

                boxes[r, c] = new Box();

                boxesArray [index] = boxes[r, c];

                //Debug.Log(r.ToString() + "," + c.ToString() + "->" + quad.ToString());
                boxes[r, c].Init(r, c, index, quad, GetBoxOfIndex);
            }
        }

        for (int r = 0; r < Constants.ROWS; r++)
        {
            for (int c = 0; c < Constants.COLS; c++)
            {
                Box box = boxes[r, c];

                for (int rOther = 0; rOther < Constants.ROWS; rOther++)
                {
                    for (int cOther = 0; cOther < Constants.COLS; cOther++)
                    {
                        Box boxOther = boxes[rOther, cOther];

                        if (box.Row == boxOther.Row)
                        {
                            box.AddSiblingRowBox(boxOther);
                        }

                        if (box.Col == boxOther.Col)
                        {
                            box.AddSiblingColBox(boxOther);
                        }

                        if (box.Quadrant == boxOther.Quadrant)
                        {
                            box.AddSiblingQuadBox(boxOther);
                        }
                    }
                }

                if (box.OtherBoxesInSameRow.Count != (Constants.MAX - 1))
                {
                    Debug.LogError("Something went wrong");
                }

                if (box.OtherBoxesInSameCol.Count != (Constants.MAX - 1))
                {
                    Debug.LogError("Something went wrong");
                }

                if (box.OtherBoxesInSameQuad.Count != (Constants.MAX - 1))
                {
                    Debug.LogError("Something went wrong");
                }
            }
        }
    }