/// <summary> /// Widget constructor /// </summary> protected virtual void Construct() { // set some default value m_selectedItem = default(T); m_clickAnywhereToOpen = false; // get allocators and UI elements m_allocator = this.GetWidgetAllocator(); m_listAllocator = this.GetListWidgetAllocator(); m_listArea = this.GetListArea(); m_selectedItemArea = this.GetSelectedItemArea(); m_pushButton = this.GetPushButton(); // create the list and subscribe to the item selection event m_list = m_listAllocator.Construct(); m_list.OnSelectItem.AddListener(this.OnItemSelected); // reparent the list to the list area transform provided by the inheriting class RectTransform listTransform = (RectTransform)m_list.transform; listTransform.SetParent(m_listArea, false); listTransform.Stretch(); // list should be disabled by default m_listArea.gameObject.SetActive(false); // subscribe to the PushButton's click event this.EnablePushButtonListener(true); }
protected virtual void Construct() { m_items = new List <T>(); m_widgets = new List <WidgetType>(); m_comparer = null; m_allocator = this.GetWidgetAllocator(); m_scroll = this.GetScrollRect(); m_scrollTransform = m_scroll.transform as RectTransform; m_layout = this.GetLayout(); // get the ScrollRect's content area m_contentArea = m_scroll.content; if (m_contentArea == null) { GameObject contentAreaObject = new GameObject("Content"); m_contentArea = contentAreaObject.AddComponent <RectTransform>(); m_contentArea.SetParent(m_scroll.transform, false); m_scroll.content = m_contentArea; } }