コード例 #1
0
    public void LoadFromPD()
    {
        if (InitPathData() == false)
        {
            return;
        }
        GameObject map = GameObject.FindWithTag("Map");

        if (map)
        {
            byte[] bytes = PathData.LoadPathData(loadFileName);
            ByteArray.StartRead(bytes);
            int width  = ByteArray.ReadInt();
            int height = ByteArray.ReadInt();
            textureGrid = new Texture2D(width, height, TextureFormat.ARGB32, false);
            aStarUtils  = new AStarUtils(textureGrid.width, textureGrid.height);
            int  x, z;
            bool bPassable;
            for (x = 0; x < textureGrid.width; x++)
            {
                for (z = 0; z < textureGrid.height; z++)
                {
                    bPassable = ByteArray.ReadByte() == 0 ? true : false;
                    textureGrid.SetPixel(x, z, bPassable ? Color.white : Color.black);
                    aStarUtils.GetNode(x, z).walkable = bPassable;
                }
            }
            textureGrid.Apply();
            gridPlane.material.mainTexture = textureGrid;
            bRayEnd = true;
            Debug.Log(width + "-" + height);
        }
    }