private void PresentNextMessage() { _updateTimerTally = 0.0f; _currentStep = NotificationStep.Appearing; _notificationImage.sprite = _sprite; _titleTextMesh.SetText(_title); _subTitleTextMesh.SetText(_message); switch (_style) { default: case NotificationStyle.Blue: _bgImage.color = new Color(52f / 255f, 31f / 255f, 151f / 255f); break; case NotificationStyle.Red: _bgImage.color = new Color(238f / 255f, 82f / 255f, 83f / 255f); break; case NotificationStyle.Yellow: _bgImage.color = new Color(254f / 255f, 202f / 255f, 87f / 255f); break; case NotificationStyle.Cerise: _bgImage.color = new Color(207f / 255f, 3f / 255f, 137f / 255f); break; } _requestedStart = false; }
private void Update() { _updateTimerTally += Time.deltaTime; if (_currentStep == NotificationStep.Hidden) { // We are idle, or just finished displaying a notification if (_requestedStart) { // New notification requested, begin appear animation from zero PresentNextMessage(); } else { // Nothing to show, nothing to do, suicide if (!_runningCoroutine) { gameObject.SetActive(false); } } return; } float bgAlpha = 1.0f; float yOffset = 0.0f; if (_currentStep == NotificationStep.Appearing) { if (_updateTimerTally < ANIMATE_TIME) { // Fading in for FADE_TIME bgAlpha = 1.0f * (_updateTimerTally / ANIMATE_TIME); yOffset = ANIMATE_Y_OFFSET - (ANIMATE_Y_OFFSET * (_updateTimerTally / ANIMATE_TIME)); } else { // FADE_TIME passed; we are now visible, start counting again to disappear per _time bgAlpha = 1.0f; yOffset = 0.0f; _currentStep = NotificationStep.Normal; _updateTimerTally = 0.0f; } } else if (_currentStep == NotificationStep.Disappearing) { if (_updateTimerTally < ANIMATE_TIME) { // Fading out for FADE_TIME bgAlpha = 1.0f - (1.0f * (_updateTimerTally / ANIMATE_TIME)); yOffset = (-ANIMATE_Y_OFFSET * (_updateTimerTally / ANIMATE_TIME)); } else { // FADE_TIME passed; we are now done bgAlpha = 0.0f; yOffset = -ANIMATE_Y_OFFSET; _currentStep = NotificationStep.Hidden; _updateTimerTally = 0.0f; } } else if (_currentStep == NotificationStep.Normal) { // Wait for _time to pass then begin to disappear bgAlpha = 1.0f; if (_updateTimerTally >= _time) { _currentStep = NotificationStep.Disappearing; _updateTimerTally = 0.0f; } } if (bgAlpha != _canvasGroup.alpha) { _canvasGroup.alpha = bgAlpha; } var targetPosY = _basePosY + yOffset; if (_clonedMainScreen.position.y != targetPosY) { _clonedMainScreen.position = new Vector3(_clonedMainScreen.position.x, targetPosY, _clonedMainScreen.position.z); } }