///Credit perchik
///Sourced from - http://forum.unity3d.com/threads/receive-onclick-event-and-pass-it-on-to-lower-ui-elements.293642/
using System.Collections.Generic;
namespace UnityEngine.UI.Extensions
{
///
/// Extension to the UI class which creates a dropdown list
///
[RequireComponent(typeof(RectTransform))]
[AddComponentMenu("UI/Extensions/Dropdown List")]
public class DropDownList : MonoBehaviour
{
public Color disabledTextColor;
public DropDownListItem SelectedItem { get; private set; } //outside world gets to get this, not set it
public List Items;
public System.Action OnSelectionChanged; // fires when selection is changed;
public bool OverrideHighlighted = true;
//private bool isInitialized = false;
private bool _isPanelActive = false;
private bool _hasDrawnOnce = false;
private DropDownListButton _mainButton;
private RectTransform _rectTransform;
private RectTransform _overlayRT;
private RectTransform _scrollPanelRT;
private RectTransform _scrollBarRT;
private RectTransform _slidingAreaRT;
// private RectTransform scrollHandleRT;
private RectTransform _itemsPanelRT;
private Canvas _canvas;
private RectTransform _canvasRT;
private ScrollRect _scrollRect;
private List _panelItems;
private GameObject _itemTemplate;
[SerializeField]
private float _scrollBarWidth = 20.0f;
public float ScrollBarWidth
{
get { return _scrollBarWidth; }
set
{
_scrollBarWidth = value;
RedrawPanel();
}
}
// private int scrollOffset; //offset of the selected item
private int _selectedIndex = 0;
[SerializeField]
private int _itemsToDisplay;
public int ItemsToDisplay
{
get { return _itemsToDisplay; }
set
{
_itemsToDisplay = value;
RedrawPanel();
}
}
public void Start()
{
Initialize();
}
private bool Initialize()
{
bool success = true;
try
{
_rectTransform = GetComponent();
_mainButton = new DropDownListButton(_rectTransform.FindChild("MainButton").gameObject);
_overlayRT = _rectTransform.FindChild("Overlay").GetComponent();
_overlayRT.gameObject.SetActive(false);
_scrollPanelRT = _overlayRT.FindChild("ScrollPanel").GetComponent();
_scrollBarRT = _scrollPanelRT.FindChild("Scrollbar").GetComponent();
_slidingAreaRT = _scrollBarRT.FindChild("SlidingArea").GetComponent();
// scrollHandleRT = slidingAreaRT.FindChild("Handle").GetComponent();
_itemsPanelRT = _scrollPanelRT.FindChild("Items").GetComponent();
//itemPanelLayout = itemsPanelRT.gameObject.GetComponent();
_canvas = GetComponentInParent