| | 1 | | using UnityEngine; |
| | 2 | |
|
| | 3 | | public interface IPlacesAndEventsSectionComponentView |
| | 4 | | { |
| | 5 | | /// <summary> |
| | 6 | | /// Events sub-section component. |
| | 7 | | /// </summary> |
| | 8 | | IEventsSubSectionComponentView currentEventsSubSectionComponentView { get; } |
| | 9 | | } |
| | 10 | |
|
| | 11 | | public class PlacesAndEventsSectionComponentView : MonoBehaviour, IPlacesAndEventsSectionComponentView |
| | 12 | | { |
| | 13 | | [Header("Top Menu")] |
| | 14 | | [SerializeField] internal SectionSelectorComponentView subSectionSelector; |
| | 15 | |
|
| | 16 | | [Header("Sections")] |
| | 17 | | [SerializeField] internal PlacesSubSectionComponentView placesSubSection; |
| | 18 | | [SerializeField] internal EventsSubSectionComponentView eventsSubSection; |
| | 19 | |
|
| 0 | 20 | | public IEventsSubSectionComponentView currentEventsSubSectionComponentView => eventsSubSection; |
| | 21 | |
|
| | 22 | | private void Start() |
| | 23 | | { |
| 8 | 24 | | if (subSectionSelector.isFullyInitialized) |
| 0 | 25 | | CreateSubSectionSelectorMappings(); |
| | 26 | | else |
| 8 | 27 | | subSectionSelector.OnFullyInitialized += CreateSubSectionSelectorMappings; |
| 8 | 28 | | } |
| | 29 | |
|
| | 30 | | private void OnDestroy() |
| | 31 | | { |
| 20 | 32 | | subSectionSelector.OnFullyInitialized -= CreateSubSectionSelectorMappings; |
| 20 | 33 | | RemoveSectionSelectorMappings(); |
| 20 | 34 | | } |
| | 35 | |
|
| | 36 | | internal void CreateSubSectionSelectorMappings() |
| | 37 | | { |
| 21 | 38 | | subSectionSelector.GetSection(0)?.onSelect.AddListener((isOn) => placesSubSection.gameObject.SetActive(isOn)); |
| 13 | 39 | | subSectionSelector.GetSection(1)?.onSelect.AddListener((isOn) => eventsSubSection.gameObject.SetActive(isOn)); |
| | 40 | |
|
| 12 | 41 | | ShowDefaultSubSection(); |
| 12 | 42 | | } |
| | 43 | |
|
| | 44 | | internal void RemoveSectionSelectorMappings() |
| | 45 | | { |
| 22 | 46 | | subSectionSelector.GetSection(0)?.onSelect.RemoveAllListeners(); |
| 22 | 47 | | subSectionSelector.GetSection(1)?.onSelect.RemoveAllListeners(); |
| 15 | 48 | | } |
| | 49 | |
|
| 26 | 50 | | internal void ShowDefaultSubSection() { placesSubSection.gameObject.SetActive(true); } |
| | 51 | | } |