LifeMessagesList.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using UnityEngine;
  2. using System.Collections;
  3. public class LifeMessagesList : ListBase
  4. {
  5. public LifeRequestItem lifeRequestItemPrefab;
  6. public LifeGivenItem lifeGivenItemPrefab;
  7. protected override Transform CreateRandomItemForTestingInEditor(int index)
  8. {
  9. if (Random.value < 0.5f)
  10. {
  11. RequestInfo data = new RequestInfo();
  12. data.senderName = "Avatar "+index;
  13. LifeRequestItem item = (LifeRequestItem)Instantiate(lifeRequestItemPrefab);
  14. item.SetData(data);
  15. return item.transform;
  16. } else
  17. {
  18. RequestInfo data = new RequestInfo();
  19. data.senderName = "Avatar "+index;
  20. LifeGivenItem item = (LifeGivenItem)Instantiate(lifeGivenItemPrefab);
  21. item.SetData(data);
  22. return item.transform;
  23. }
  24. }
  25. protected override bool HasItems()
  26. {
  27. return (FacebookHelper.Instance.lastReceivedRequests != null &&
  28. (FacebookHelper.Instance.lastReceivedRequests.lifeDemandRequests.Count > 0 ||
  29. FacebookHelper.Instance.lastReceivedRequests.lifeRequests.Count > 0));
  30. }
  31. protected override void CreateItems()
  32. {
  33. int row = 0;
  34. //Life Demands
  35. foreach (RequestInfo data in FacebookHelper.Instance.lastReceivedRequests.lifeDemandRequests)
  36. {
  37. LifeRequestItem item = (LifeRequestItem)Instantiate(lifeRequestItemPrefab);
  38. item.SetData(data);
  39. PlaceItem(item.transform, row);
  40. ++row;
  41. }
  42. //Life Gifts
  43. foreach (RequestInfo data in FacebookHelper.Instance.lastReceivedRequests.lifeRequests)
  44. {
  45. LifeGivenItem item = (LifeGivenItem)Instantiate(lifeGivenItemPrefab);
  46. item.SetData(data);
  47. PlaceItem(item.transform, row);
  48. ++row;
  49. }
  50. }
  51. }