コード例 #1
0
    /// <summary>
    /// 可视化方法
    /// </summary>
    public void ToDebug(GameObject line)
    {
        //TODO 进行单元格的可视化

        for (int i = 0; i < cellNumX; i++)
        {
            for (int j = 0; j < cellNumY; j++)
            {
                Vector3 upLeft  = new Vector3(cells[i, j].Pos.x, cells[i, j].Pos.y + cellH, -6);
                Vector3 upRight = new Vector3(cells[i, j].Pos.x + cellW, cells[i, j].Pos.y + cellH, -6);

                Vector3 downLeft  = new Vector3(cells[i, j].Pos.x, cells[i, j].Pos.y, -6);
                Vector3 downRight = new Vector3(cells[i, j].Pos.x + cellW, cells[i, j].Pos.y, -6);

                GameObject go = GameObject.Instantiate(line, new Vector3(0, 0, 0), Quaternion.identity);
                go.name = "up";

                DebugLine up = go.AddComponent(typeof(DebugLine)) as DebugLine;

                up.SetDebugLine(upLeft, upRight, go.GetComponent <LineRenderer>());

                go      = GameObject.Instantiate(line, new Vector3(0, 0, 0), Quaternion.identity);
                go.name = "down";
                DebugLine down = go.AddComponent(typeof(DebugLine)) as DebugLine;

                down.SetDebugLine(downLeft, downRight, go.GetComponent <LineRenderer>());

                go      = GameObject.Instantiate(line, new Vector3(), Quaternion.identity);
                go.name = "left";
                DebugLine left = go.AddComponent(typeof(DebugLine)) as DebugLine;

                left.SetDebugLine(upLeft, downLeft, go.GetComponent <LineRenderer>());

                go      = GameObject.Instantiate(line, new Vector3(), Quaternion.identity);
                go.name = "right";
                DebugLine right = go.AddComponent(typeof(DebugLine)) as DebugLine;

                right.SetDebugLine(upRight, downRight, go.GetComponent <LineRenderer>());

                //Debug.Log(""+i+","+j+"  "+cells[i,j].GetContainer().Count);
            }
        }
    }