// randomize background theme
    // - no repeating themes
    public void RandomizeBackgroundTheme()
    {
        // stop if already transitioning
        if (m_backgroundTransitioning)
        {
            return;
        }

        // loop until backgound does not repeat
        bool changed = false;

        while (!changed)
        {
            // randomize a theme index
            BackgroundTheme newTheme = (BackgroundTheme)Random.Range(0, m_backgrounds.Count);

            // if not current theme, change theme
            if (m_currentTheme != newTheme)
            {
                StartCoroutine(SetBackgroundThemeWithTransition(newTheme));
                m_currentTheme = newTheme;
                changed        = true;
            }
        }
    }
 // set background theme
 private void SetBackgroundTheme(BackgroundTheme theme)
 {
     foreach (BackgroundThemeHolder background in m_backgrounds)
     {
         background.SetStatus(false);
     }
     m_currentTheme = theme;
     m_backgrounds[(int)m_currentTheme].SetStatus(true);
     m_backgrounds[(int)m_currentTheme].InitializePositions();
 }
        private String GetImagePath(BackgroundTheme theme)
        {
            switch (theme)
            {
            case (BackgroundTheme.Morning): return(@"Resources\morning.jpg");

            case (BackgroundTheme.Day): return(@"Resources\day.jpg");

            case (BackgroundTheme.Evening): return(@"Resources\evening.jpg");

            default: return(@"Resources\night.jpg");
            }
        }
 void ChangeStyleType()
 {
     if (!openAirBackground)
     {
         _currentStyleName = OpenAirStyle[Random.Range(0, OpenAirStyle.Count)];
         openAirBackground = true;
     }
     else
     {
         _currentStyleName = CavernStyle[Random.Range(0, CavernStyle.Count)];
         openAirBackground = false;
     }
     _currentTheme = _styleDictionary[_currentStyleName];
 }
示例#5
0
        private static void SetBackgroundColor(GridLabel target, BackgroundTheme theme)
        {
            switch (theme)
            {
            case BackgroundTheme.Black:
                target.Background = Brushes.Black;
                target.Foreground = Brushes.White;
                break;

            case BackgroundTheme.White:
                target.Background = Brushes.White;
                target.Foreground = Brushes.Black;
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(theme), theme, null);
            }
        }
    private IEnumerator SetBackgroundThemeWithTransition(BackgroundTheme theme)
    {
        m_backgroundTransitioning = true;

        // initialize transition
        InitializeTransition();
        m_transition.gameObject.SetActive(true);

        bool changed       = false;
        bool transitioning = true;

        while (transitioning)
        {
            // if dude move pass a threshold, change background
            if (!changed)
            {
                if (DudeController.instance.transform.position.y < m_transition.GetBackgroundY() - 5.0f)
                {
                    SetBackgroundTheme(theme);
                    changed = true;
                }
            }

            // if dude move pass a threashold, break from loop
            else
            {
                if (DudeController.instance.transform.position.y < m_transition.GetBackgroundY() - 12.0f)
                {
                    transitioning = false;
                }
            }

            yield return(null);
        }

        // deactivate transition
        m_transition.gameObject.SetActive(false);

        m_backgroundTransitioning = false;
    }
    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;
    }
        public string AddToast(string title, string content, BackgroundTheme toastBg = BackgroundTheme.info)
        {
            var id    = Guid.NewGuid().ToString("N");
            var model = new ToastModel()
            {
                Title   = title,
                Content = content,
                Time    = DateTime.Now.ToShortTimeString(),
                ToastBg = toastBg
            };

            lock (dict)
                dict.Add(id, model);
            //如果配置了自动关闭
            if (AutoClose)
            {
                Task.Delay(AutoCloseTime).ContinueWith(t =>
                {
                    CloseToast(id);
                });
            }
            InvokeAsync(StateHasChanged);
            return(id);
        }
 public BackgroundManager()
 {
     CurrentTheme = (BackgroundTheme)RandomProvider.Random.Next(0, 4);
     UpdateTheme();
 }