예제 #1
0
    public void LinkChildsToEntities(Contexts contexts, IView view, IdService idService)
    {
        view.Transform.GetComponentsInChildren(_emitterBuffer);
        foreach (var emitter in _emitterBuffer)
        {
            var e = emitter.Emit();
            e.AddId(idService.GetNext());
            e.AddChildOf(view.Id);

            var child = emitter.Transform;
            child.SetParent(_root);

            var childView = child.GetComponent <IView>();
            if (childView != null)
            {
                childView.InitializeView(contexts, e);
                e.AddView(childView);
            }

            child.GetComponents(_eventListenerBuffer);
            foreach (var listener in _eventListenerBuffer)
            {
                listener.RegisterListeners(e);
            }
        }
    }
    public void Execute()
    {
        var player = _contexts.game.playerEntity;

        if (player != null && player.hasPosition)
        {
            var playerPosition    = player.position.Value;
            var nextChunkPosition = _contexts.gameState.nextChunkPosition.Value;
            var chunkDistance     = _contexts.config.chunkCreationDistance.Value;

            if (playerPosition.x + chunkDistance > nextChunkPosition)
            {
                var definitions = _contexts.config.chunkDefinitions.Value.Definitions;
                var definition  = definitions[Random.Range(0, definitions.Count)];

                _contexts.gameState.ReplaceNextChunkPosition(nextChunkPosition + definition.Width);
                _createChunkService.CreateChunk(_idService.GetNext(), new Vector2(nextChunkPosition, 0f), definition);
            }
        }
    }