Пример #1
0
        private void GenerateColliders()
        {
            var bounds        = WallTile.GetComponent <Renderer>().bounds.size;
            var finishedTiles = new bool[MapWidth, MapHeight];
            var rectangles    = new List <Rectangle>();

            for (var i = 0; i < MapWidth; i++)
            {
                for (var j = 0; j < MapHeight; j++)
                {
                    if (finishedTiles[i, j])
                    {
                        continue;
                    }

                    if (_map[i, j].TileType == MapGenerator.TileType.Wall)
                    {
                        var rect = FindLargestRect(i, j, finishedTiles);
                        rectangles.Add(rect);
                    }
                }
            }

            foreach (var rect in rectangles)
            {
                var go = new GameObject(GameObjectNameMapping.GetObjectName(GameObjectNames.Collider));
                go.transform.parent = _collidersGameObject.transform;
                var coll = go.AddComponent <BoxCollider2D>();
                coll.offset = new Vector2(rect.X * bounds.x + rect.Width * bounds.x / 2 - bounds.x / 2, rect.Y * bounds.y + rect.Height * bounds.y / 2 - bounds.y / 2);
                coll.size   = new Vector2(rect.Width * bounds.x, rect.Height * bounds.y);
                go.layer    = Layers.GetLayer(LayerName.ShadowLayer);
            }
        }
Пример #2
0
        public void Awake()
        {
            _tilesGameObject = new GameObject(GameObjectNameMapping.GetObjectName(GameObjectNames.Tiles));
            _tilesGameObject.transform.parent = transform;

            _monstersGameObject = new GameObject(GameObjectNameMapping.GetObjectName(GameObjectNames.Monsters));
            _monstersGameObject.transform.parent = transform;

            _collidersGameObject = new GameObject(GameObjectNameMapping.GetObjectName(GameObjectNames.Colliders));
            _collidersGameObject.transform.parent = transform;

            _levelObjective = new KillAllMonstersObjective(_monstersGameObject);

            PubSub.GlobalPubSub.Subscribe <RestartLevelMessage>(m => Restart());
        }