/** * Copyright 2019 The Knights Of Unity, created by Pawel Stolarczyk * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ using System; using DemoGame.Scripts.Menus; using Nakama; using UnityEngine; using UnityEngine.UI; namespace DemoGame.Scripts.Notifications { /// /// Popup menu showed in the top right corner of the screen. /// Shown upon finishing a quest. /// /// /// One of the quests prepared for this demo is "new friend quest". To finish it, /// add a dummy account named "Richard" to friends. /// public class NotificationPopup : Menu { #region Fields /// /// Title of the notification. /// [SerializeField] private Text _titleText = null; /// /// Description of the notification. /// [SerializeField] private Text _descriptionText = null; /// /// Button to hide the notification. /// [SerializeField] private Button _dismissButton = null; #endregion /// /// Serializable class used to retrieve the reward gained from completing a quest. /// [Serializable] private class Reward { public int reward = 0; } #region Mono /// /// Sets up dismiss button handlers and hides the popup. /// private void Awake() { _dismissButton.onClick.AddListener(base.Hide); NotificationManager.Instance.OnNotification += NotificationReceived; } #endregion #region Methods /// /// Handles incomming notification messages. /// private void NotificationReceived(IApiNotification e) { if (e.Code == (int)NotificationCode.Quest_NewFriend) { Debug.Log("New notification: " + e.Code + ", " + e.Content); Reward reward = JsonUtility.FromJson(e.Content); base.Show(); _titleText.text = e.Subject; _descriptionText.text = "Received reward: " + reward.reward; } } /// /// Shows a notification panel /// private void NotifyQuestComplete(IApiNotification e) { Debug.Log("New notification: " + e.Code + ", " + e.Content); Reward reward = JsonUtility.FromJson(e.Content); base.Show(); _titleText.text = e.Subject; _descriptionText.text = "Received reward: " + reward.reward; } #endregion } }