///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; using System.Linq; namespace UnityEngine.UI.Extensions { [RequireComponent(typeof(RectTransform))] [AddComponentMenu("UI/Extensions/AutoComplete ComboBox")] public class AutoCompleteComboBox : MonoBehaviour { public Color disabledTextColor; public DropDownListItem SelectedItem { get; private set; } //outside world gets to get this, not set it public List AvailableOptions; public System.Action OnSelectionChanged; // fires when selection is changed; //private bool isInitialized = false; private bool _isPanelActive = false; private bool _hasDrawnOnce = false; private InputField _mainInput; private RectTransform _inputRT; private Button _arrow_Button; 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; //items that will get shown in the dropdown private List _prunedPanelItems; //items that used to show in the dropdown private Dictionary panelObjects; private GameObject itemTemplate; public string Text { get; private set; } [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 bool interactible { get { return _mainInput.interactable || _arrow_Button.interactable; } private set { _mainInput.interactable = value; _arrow_Button.interactable = value; if (!value && _isPanelActive) { ToggleDropdownPanel (false); } } } [SerializeField] //I couldn't come up with a better name private bool _technicallyInteractible = true; public bool TechnicallyInteractible { get { return _technicallyInteractible; } set { _technicallyInteractible = value; interactible = _technicallyInteractible && (AvailableOptions.Count > 0 || _remainInteractableIfEmpty); } } [SerializeField] private bool _remainInteractableIfEmpty = true; public bool RemainInteractableIfEmpty { get { return _remainInteractableIfEmpty; } set { _remainInteractableIfEmpty = value; interactible = _technicallyInteractible && (AvailableOptions.Count > 0 || _remainInteractableIfEmpty); } } public void Awake() { Initialize(); } private bool Initialize() { bool success = true; try { _rectTransform = GetComponent(); _inputRT = _rectTransform.FindChild("InputField").GetComponent(); _mainInput = _inputRT.GetComponent(); _arrow_Button = _rectTransform.FindChild ("ArrowBtn").GetComponent