2015-02-03 07:07:31 +08:00
///Credit perchik
///Sourced from - http://forum.unity3d.com/threads/receive-onclick-event-and-pass-it-on-to-lower-ui-elements.293642/
using System ;
2023-01-01 21:29:53 +08:00
using UnityEngine.Events ;
2015-02-03 07:07:31 +08:00
namespace UnityEngine.UI.Extensions
{
2015-02-10 08:03:38 +08:00
[Serializable]
public class DropDownListItem
2015-02-03 07:07:31 +08:00
{
[SerializeField]
private string _caption ;
/// <summary>
/// Caption of the Item
/// </summary>
public string Caption
{
get
{
return _caption ;
}
set
{
_caption = value ;
if ( OnUpdate ! = null )
OnUpdate ( ) ;
}
}
[SerializeField]
private Sprite _image ;
/// <summary>
/// Image component of the Item
/// </summary>
public Sprite Image
{
get
{
return _image ;
}
set
{
_image = value ;
if ( OnUpdate ! = null )
OnUpdate ( ) ;
}
}
[SerializeField]
private bool _isDisabled ;
/// <summary>
/// Is the Item currently enabled?
/// </summary>
public bool IsDisabled
{
get
{
return _isDisabled ;
}
set
{
_isDisabled = value ;
if ( OnUpdate ! = null )
OnUpdate ( ) ;
}
}
2015-02-10 08:03:38 +08:00
[SerializeField]
private string _id ;
///<summary>
2020-07-09 03:38:28 +08:00
///ID 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 ID can be the student's ID number
2015-02-10 08:03:38 +08:00
///</summary>
public string ID
{
get { return _id ; }
set { _id = value ; }
}
2015-02-03 07:07:31 +08:00
2023-01-01 21:29:53 +08:00
public UnityAction OnSelect = null ; //action to be called when this item is selected
2015-02-03 07:07:31 +08:00
2023-01-01 21:29:53 +08:00
internal UnityAction OnUpdate = null ; //action to be called when something changes.
2015-02-03 07:07:31 +08:00
/// <summary>
2015-02-10 08:03:38 +08:00
/// Constructor for Drop Down List panelItems
2015-02-03 07:07:31 +08:00
/// </summary>
/// <param name="caption">Caption for the item </param>
2015-02-10 08:03:38 +08:00
/// <param name="val">ID of the item </param>
2015-02-03 07:07:31 +08:00
/// <param name="image"></param>
/// <param name="disabled">Should the item start disabled</param>
2023-01-01 21:29:53 +08:00
/// <param name="onSelect">UnityAction to be called when this item is selected</param>
public DropDownListItem ( string caption = "" , string inId = "" , Sprite image = null , bool disabled = false , UnityAction onSelect = null )
2015-02-03 07:07:31 +08:00
{
_caption = caption ;
_image = image ;
2015-02-10 08:03:38 +08:00
_id = inId ;
2015-02-03 07:07:31 +08:00
_isDisabled = disabled ;
OnSelect = onSelect ;
}
}
}