void SetNewForeground() { var _lastForegroundGroup = _foregroundGroup.Last(); var _lastForegroundGroupPostionX = _lastForegroundGroup.First().transform.position.x; var _nextForeground = _currentTheme.ForegroundGroup[_currentTheme.NextAvailableForegroundIndex]; _foregroundGroup.Add(_nextForeground); _currentTheme.IncreaseForegroundIndex(); _widthLastForeground = _lastForegroundGroup[0].GetComponent <SpriteRenderer>().sprite.bounds.size.x; foreach (var element in _nextForeground) { element.transform.position = new Vector3(_lastForegroundGroupPostionX + _widthLastForeground, element.transform.position.y, element.transform.position.z); element.SetActive(true); } }
void InitializeBackgrounds() { _currentTheme = _styleDictionary[_currentStyleName]; _backgroundGroup = _currentTheme.BackgroundGroup; _foregroundGroup = _currentTheme.ForegroundGroup; //First background panel is to the left of the player; float firstBackgroundPositionX = -_currentTheme.Width; //group of elements that make one complete background image for (int i = 0; i < _backgroundGroup.Count; i++) { //layers in one background image foreach (var group in _backgroundGroup[i]) { group.SetActive(true); group.transform.position = new Vector3( firstBackgroundPositionX + _currentTheme.Width * i, group.transform.position.y, group.transform.position.z); } _currentTheme.IncreaseBackgroundIndex(); } for (int i = 0; i < _foregroundGroup.Count; i++) { //layers in one foreground image foreach (var group in _foregroundGroup[i]) { group.SetActive(true); group.transform.position = new Vector3( firstBackgroundPositionX + _currentTheme.Width * i, group.transform.position.y, group.transform.position.z); } _currentTheme.IncreaseForegroundIndex(); } _widthLastBackground = _widthLastForeground = _currentTheme.Width; }