namespace UIWidgets
{
using System;
using System.ComponentModel;
using UnityEngine;
using UnityEngine.Serialization;
///
/// Tree view item.
///
[Serializable]
public class TreeViewItem : IObservable, INotifyPropertyChanged
{
///
/// Occurs when a property value changes.
///
public event OnChange OnChange;
///
/// Occurs when a property value changes.
///
public event PropertyChangedEventHandler PropertyChanged;
///
/// The icon.
///
[SerializeField]
Sprite icon;
///
/// Gets or sets the icon.
///
/// The icon.
public Sprite Icon
{
get
{
return icon;
}
set
{
icon = value;
NotifyPropertyChanged("Icon");
}
}
///
/// The name.
///
[SerializeField]
string name;
///
/// Gets or sets the name.
///
/// The name.
public string Name
{
get
{
return name;
}
set
{
name = value;
NotifyPropertyChanged("Name");
}
}
[NonSerialized]
string localizedName;
///
/// The localized name.
///
public string LocalizedName
{
get
{
return localizedName;
}
set
{
localizedName = value;
NotifyPropertyChanged("LocalizedName");
}
}
[SerializeField]
[FormerlySerializedAs("_value")]
int itemValue;
///
/// Gets or sets the value.
///
/// The value.
public int Value
{
get
{
return itemValue;
}
set
{
itemValue = value;
NotifyPropertyChanged("Value");
}
}
[SerializeField]
object tag;
///
/// Gets or sets the tag.
///
/// The tag.
public object Tag
{
get
{
return tag;
}
set
{
tag = value;
NotifyPropertyChanged("Tag");
}
}
///
/// Initializes a new instance of the class.
///
/// Item name.
/// Item icon.
public TreeViewItem(string itemName, Sprite itemIcon = null)
{
name = itemName;
icon = itemIcon;
}
///
/// Raise OnChange event.
///
/// Property name.
protected void NotifyPropertyChanged(string propertyName)
{
var c_handlers = OnChange;
if (c_handlers != null)
{
c_handlers();
}
var handlers = PropertyChanged;
if (handlers != null)
{
handlers(this, new PropertyChangedEventArgs(propertyName));
}
}
///
/// Convert this instance to string.
///
/// String.
public override string ToString()
{
return LocalizedName ?? Name;
}
}
}