Advertisement
ilih

Untitled

Mar 17th, 2019
160
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // TreeViewItem class
  2. public event PropertyChangedEventHandler PropertyChanged = (x, y) => { };
  3.  
  4. [SerializeField]
  5. [UnityEngine.Serialization.FormerlySerializedAs("ComboboxItems")] // without it data will be lost on renaming
  6. List<string> comboboxItems;
  7.  
  8. public List<string> ComboboxItems
  9. {
  10. get
  11. {
  12. return comboboxItems
  13. }
  14.  
  15. set
  16. {
  17. comboboxItems = value;
  18. Changed("ComboboxItems");
  19. }
  20. }
  21.  
  22. protected void Changed(string propertyName)
  23. {
  24. PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
  25. }
  26.  
  27. TreeViewItem item;
  28.  
  29. // TreeViewItemComponent
  30. public TreeViewItem Item
  31. {
  32. get
  33. {
  34. return item;
  35. }
  36.  
  37. set
  38. {
  39. if (item != null)
  40. {
  41. item.PropertyChanged -= UpdateView;
  42. }
  43.  
  44. item = value;
  45.  
  46. if (item != null)
  47. {
  48. item.PropertyChanged += UpdateView;
  49. }
  50.  
  51. UpdateView();
  52. }
  53. }
  54.  
  55. public override void SetData(TreeNode<TreeViewItem> node, int depth)
  56. {
  57. Node = node;
  58. base.SetData(Node, depth);
  59.  
  60. Item = (Node == null) ? null : Node.Item;
  61. }
  62.  
  63. protected void UpdateView(object sender = null, PropertyChangedEventArgs ev = null)
  64. {
  65. // set combobox items, selected index and other data
  66. }
Advertisement
RAW Paste Data Copied
Advertisement