///Credit perchik
///Sourced from - http://forum.unity3d.com/threads/receive-onclick-event-and-pass-it-on-to-lower-ui-elements.293642/
using System;
using UnityEngine;
using UnityEngine.UI;
public class ComboBoxItem
{
[SerializeField]
private string _caption;
///
/// Caption of the Item
///
public string Caption
{
get
{
return _caption;
}
set
{
_caption = value;
if (OnUpdate != null)
OnUpdate();
}
}
[SerializeField]
private Sprite _image;
///
/// Image component of the Item
///
public Sprite Image
{
get
{
return _image;
}
set
{
_image = value;
if (OnUpdate != null)
OnUpdate();
}
}
[SerializeField]
private bool _isDisabled;
///
/// Is the Item currently enabled?
///
public bool IsDisabled
{
get
{
return _isDisabled;
}
set
{
_isDisabled = value;
if (OnUpdate != null)
OnUpdate();
}
}
public Action OnSelect; //action to be called when this item is selected
internal Action OnUpdate; //action to be called when something changes.
/// Value exists so that an item can have a caption and a value, like in traditional windows forms. Ie. an item may be a student's name, and the value could be the student's ID number
private string _value;
///
/// Constructor for ComboBoxOptions
///
/// Caption for the item
/// Value of the item
///
/// Should the item start disabled
/// Action to be called when this item is selected
public ComboBoxItem(string caption="",string val="", Sprite image=null, bool disabled=false, Action onSelect=null)
{
_caption = caption;
_image = image;
_value = val;
_isDisabled = disabled;
OnSelect = onSelect;
}
}