/// <inheritdoc /> public void Add(IObjective objective) { if (objective == null) { throw new ArgumentNullException(nameof(objective), $"objective is required by {this}"); } Objectives.Add(objective); ObjectiveAdded?.Invoke(this, new ObjectiveArgs(objective)); }
void Start() { ObjectiveAdded evt = Events.ObjectiveAddedEvent; evt.Objective = this; EventManager.Broadcast(evt); if (m_Trigger) { m_Trigger.OnProgress += Progress; m_Trigger.OnActivate += Activate; } else { Activate(); } }
void OnObjectiveAdded(ObjectiveAdded evt) { if (!evt.Objective.m_Hidden) { // Instantiate the UI element for the new objective. GameObject go = Instantiate(evt.Objective.m_Lose ? m_LoseObjectivePrefab : m_WinObjectivePrefab, m_ObjectivePanel.transform); // Initialise the objective element. Objective objective = go.GetComponent <Objective>(); objective.Initialize(evt.Objective.m_Title, evt.Objective.m_Description, evt.Objective.GetProgress()); // Force layout rebuild to get height of objective UI. LayoutRebuilder.ForceRebuildLayoutImmediate(objective.GetComponent <RectTransform>()); // Position the objective. var rectTransform = go.GetComponent <RectTransform>(); rectTransform.anchoredPosition = new Vector2(0, m_NextY - s_TopMargin); m_NextY -= rectTransform.sizeDelta.y + s_Spacing; evt.Objective.OnProgress += objective.OnProgress; } }