Exemplo n.º 1
0
        //used in edit mode only
        public void AddWall(float angle, Tile neighbour, int wallType = 0)
        {
            if (neighbour == null)
            {
                return;
            }

            if (angle > 360)
            {
                angle -= 360;
            }

            if (IsWalled(angle))
            {
                return;
            }

            float gridSize = GridManager.GetTileSize() * GridManager.GetGridToTileSizeRatio();

            if (type == _TileType.Square)
            {
                gridSize *= 2;
            }

                        #if UNITY_EDITOR
            Transform wallT = (Transform)PrefabUtility.InstantiatePrefab(GridManager.GetWallObstacleT(wallType));
            Undo.RecordObject(this, "Tile");
            Undo.RecordObject(neighbour, "NeighbourTile");
            Undo.RegisterCreatedObjectUndo(wallT.gameObject, "Wall");
                        #else
            Transform wallT = (Transform)Instantiate(GridManager.GetWallObstacleT(wallType));
                        #endif

            float wallTAngle = angle + 90;

            if (type == _TileType.Square)
            {
                wallTAngle = 360 - (angle - 90);
            }
            else if (type == _TileType.Hex)
            {
                wallTAngle = 360 - (angle - 90);
            }

            wallT.rotation    = Quaternion.Euler(0, wallTAngle, 0);
            wallT.position    = (GetPos() + neighbour.GetPos()) / 2;
            wallT.localScale *= gridSize;
            wallT.parent      = transform;
            wallList.Add(new Wall(angle, wallT));

            if ((angle += 180) >= 360)
            {
                angle -= 360;
            }

            neighbour.wallList.Add(new Wall(angle, wallT));
        }