Esempio n. 1
0
        private void OnPlayerCharacterPositionRowChanged(float row)
        {
            // Create new segment after offset when line changed.
            if (_waitingForNewSegment && row > _lastLineChangedRow + _gameConfig.RoadSettings.LineChangeOffset)
            {
                CreateNewSegment();
                _waitingForNewSegment = false;
            }

            // Increase active segment length.
            if (_activeSegment != null)
            {
                // Build active road segment.
                _activeSegment.IncreaseLength(row + _gameConfig.RoadSettings.Offset);
            }

            // Segment out of playable space check.
            if (RoadSegments.Count > 0)
            {
                RoadSegment segment = RoadSegments.Peek();

                if (segment.Position.Row < _gameConfig.GridSettings.StartPosition + _gameConfig.CellSettings.CellSize * (_grid.RowsOffset - 1))
                {
                    RemoveOldestSegment();
                }
            }
        }
Esempio n. 2
0
        private void Awake()
        {
            // Get GameConfigData reference via container.
            _gameConfig = Globals.Instance.GetData <GameConfigData>();

            // Get RelativeCoordinates reference via container.
            _relativeCoordinates = Globals.Instance.GetDependency <RelativeCoordinates>();

            // Required component.
            _roadSegment = GetComponent <RoadSegment>();

            // Get Transform reference.
            _transform = transform;

            _renderer = GetComponentInChildren <MeshRenderer>();

            // Clone material.
            Material originMaterial = _renderer.sharedMaterial;

            _material = Instantiate(originMaterial);
            _renderer.sharedMaterial = _material;

            _material.SetFloat("_PositionZ", _transform.position.z);
            _material.SetFloat("_Progress", 0);
        }
Esempio n. 3
0
 private void RemoveOldestSegment()
 {
     if (RoadSegments.Count > 0)
     {
         RoadSegment segment = RoadSegments.Dequeue();
         _pool.Despawn(segment);
     }
 }
Esempio n. 4
0
        private void CreateNewSegment(bool relativeToLast = false)
        {
            // Spawn new segment.
            GridCoordinates pos = new GridCoordinates(_playerCharacter.Position.Line, _playerCharacter.Position.Row + _gameConfig.RoadSettings.Offset);

            if (relativeToLast && _activeSegment != null)
            {
                pos.Row = _activeSegment.Position.Row + _gameConfig.CellSettings.CellSize;
            }

            _activeSegment = _pool.Spawn(_transform);
            _activeSegment.Setup(pos);
            RoadSegments.Enqueue(_activeSegment);

            // Subscribe for active segment.
            _activeSegment.BuildingComplited += OnActiveSegmentBuildingComplited;
            _isSubscribedForActiveSegment     = true;
        }
Esempio n. 5
0
        public void Despawn(RoadSegment segment)
        {
            segment.transform.SetParent(_poolParent);

            _segments.Push(segment);
        }