AnnouncementManager.cs 860 B

1234567891011121314151617181920212223242526272829303132
  1. using UnityEngine;
  2. using System.Collections;
  3. public class AnnouncementManager : MonoBehaviour
  4. {
  5. public Transform announcementsAnchor;
  6. public PoolObject announcementPrefab;
  7. Pool _announcementsPool;
  8. void Awake()
  9. {
  10. _announcementsPool = Pool.Create(announcementPrefab, 5);
  11. NotificationCenter.AddListener(OnAnnouncement, NotificationType.Announcement);
  12. }
  13. void OnDestroy()
  14. {
  15. NotificationCenter.RemoveListener(OnAnnouncement, NotificationType.Announcement);
  16. }
  17. void OnAnnouncement(Notification note)
  18. {
  19. string text = (string)note.data;
  20. TextAnnouncement announcement = _announcementsPool.Spawn().GetComponent<TextAnnouncement>();
  21. Transform hitPointsBonusTransform = announcement.transform;
  22. hitPointsBonusTransform.parent = announcementsAnchor;
  23. announcement.SetText(text);
  24. hitPointsBonusTransform.localPosition = Vector3.zero;
  25. }
  26. }