Пример #1
0
    void Awake()
    {
        if (Instance == null)
        {
            Instance = this;
        }
        unwalkable = new Unwalkable();


        //pathGeneration = new PathGeneration(centroids);
    }
Пример #2
0
        public void Init()
        {
            var mappath = Path.Combine("map", diskName);
            var fileStr = File.Exists(mappath);

            if (!fileStr)
            {
                throw new Exception("Map File not found");
            }

            var input = File.ReadAllBytes(mappath);

            byte[] temp = new byte[4];

            Array.Copy(input, 72, temp, 0, 4);
            int objStrCnt = BitConverter.ToInt32(temp, 0);


            sizeX = input[0x20];
            sizeY = input[0x24];
            int cnt = sizeX * sizeY;
            int itr = 0, res2 = 0, res1 = 0;

            Tiles = new Tile[sizeX, sizeY];

            while (itr != cnt)
            {
                Array.Copy(input, offset + (itr * 4), temp, 0, 4);
                temp[3] = 0;
                if (itr % sizeX == 0 && itr != 0)
                {
                    res2++;
                    res1 = 0;
                }
                if (Unwalkable.Where(xe => xe[0] == temp[0] && xe[1] == temp[1] && xe[2] == temp[2]).FirstOrDefault() != null)
                {
                    var tile = new Tile(res1, res2, 0);
                    Tiles[res1++, res2] = tile;
                }
                else
                {
                    var tile = new Tile(res1, res2, (int)Tile.E_WalkFlags.Walkable);
                    Tiles[res1++, res2] = tile;
                }
                itr++;
            }
            AddNeighbours();

            var strOff = offset + cnt * 4;

            byte[] tempObj = new byte[32];
            itr = 0;
            while (itr != objStrCnt)
            {
                Array.Copy(input, strOff + (itr * 32), tempObj, 0, 32);
                int oX = tempObj[0];
                int oY = tempObj[4];

                var objName = Encoding.GetEncoding(949).GetString(tempObj, 16, 16);
                var oName   = objName.Split(new char[] { '\0' }, StringSplitOptions.RemoveEmptyEntries)[0];
                MapObjects.SetCollisions(oName, Tiles, MapTiles, oX, oY);

                itr++;
            }
        }