using Unity.FPS.Game; using Unity.FPS.Gameplay; using UnityEngine; namespace Unity.FPS.UI { public class NotificationHUDManager : MonoBehaviour { [Tooltip("UI panel containing the layoutGroup for displaying notifications")] public RectTransform NotificationPanel; [Tooltip("Prefab for the notifications")] public GameObject NotificationPrefab; void Awake() { PlayerWeaponsManager playerWeaponsManager = FindObjectOfType(); DebugUtility.HandleErrorIfNullFindObject(playerWeaponsManager, this); playerWeaponsManager.OnAddedWeapon += OnPickupWeapon; Jetpack jetpack = FindObjectOfType(); DebugUtility.HandleErrorIfNullFindObject(jetpack, this); jetpack.OnUnlockJetpack += OnUnlockJetpack; EventManager.AddListener(OnObjectiveUpdateEvent); } void OnObjectiveUpdateEvent(ObjectiveUpdateEvent evt) { if (!string.IsNullOrEmpty(evt.NotificationText)) CreateNotification(evt.NotificationText); } void OnPickupWeapon(WeaponController weaponController, int index) { if (index != 0) CreateNotification("Picked up weapon : " + weaponController.WeaponName); } void OnUnlockJetpack(bool unlock) { CreateNotification("Jetpack unlocked"); } public void CreateNotification(string text) { GameObject notificationInstance = Instantiate(NotificationPrefab, NotificationPanel); notificationInstance.transform.SetSiblingIndex(0); NotificationToast toast = notificationInstance.GetComponent(); if (toast) { toast.Initialize(text); } } void OnDestroy() { EventManager.RemoveListener(OnObjectiveUpdateEvent); } } }