MissionsUI.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class MissionsUI : MonoBehaviour
  5. {
  6. [Tooltip("The prefab of the Quest UI.")]
  7. public GameObject QuestUITemplate;
  8. Quest queuedquests;
  9. int queuedquestIndex;
  10. public static MissionsUI Instance;
  11. List<QuestUINew> quests;
  12. void Awake()
  13. {
  14. Instance = this;
  15. quests = new List<QuestUINew>();
  16. }
  17. // Use this for initialization
  18. void Start()
  19. {
  20. // ConversationUI.Instance.EndDialog += Instance_EndDialog;
  21. }
  22. private void Instance_EndDialog()
  23. {
  24. //throw new System.NotImplementedException();
  25. if (queuedquests != null)
  26. {
  27. InitMission(queuedquests, queuedquestIndex);
  28. queuedquests = null;
  29. queuedquestIndex = 0;
  30. }
  31. }
  32. // Update is called once per frame
  33. void Update()
  34. {
  35. }
  36. public void AddMission(Quest quest,int index)
  37. {
  38. /*if (!ConversationUI.Instance.InConversation && PhoneUI.Instance.State == PhoneState.Idle)
  39. {
  40. InitMission(quest,index);
  41. }
  42. else
  43. {
  44. queuedquests = quest;
  45. queuedquestIndex = index;
  46. }*/
  47. }
  48. public void LoadMission(Quest quest, int index)
  49. {
  50. InitMission(quest,index);
  51. for (int i = 0; i < index; i++)
  52. {
  53. LoadCheck(i, quest.id);
  54. }
  55. }
  56. void InitMission(Quest quest,int index)
  57. {
  58. GameObject newQuest = Instantiate(QuestUITemplate, transform);
  59. newQuest.GetComponent<QuestUINew>().Init(quest, index);
  60. quests.Add(newQuest.GetComponent<QuestUINew>());
  61. }
  62. public void Check(int Index, string missionName)
  63. {
  64. foreach (QuestUINew quest in quests)
  65. {
  66. if (quest.QuestName == missionName)
  67. {
  68. quest.CheckTask(Index);
  69. }
  70. }
  71. }
  72. public void LoadCheck(int Index, string missionName)
  73. {
  74. foreach (QuestUINew quest in quests)
  75. {
  76. if (quest.QuestName == missionName)
  77. {
  78. quest.CheckTask(Index);
  79. }
  80. }
  81. }
  82. public void ToggleContent()
  83. {
  84. foreach (UIElement element in GetComponentsInChildren<UIElement>(true))
  85. element.ChangeVisibility(!element.Visible);
  86. }
  87. }