wangguan
2020-12-29 452c75675679c44cc39b04bdb7d330d7c5c14d5c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
using UnityEngine;
using System.Collections;
 
namespace EnhancedScrollerDemos.SelectionDemo
{
    /// <summary>
    /// This delegate handles any changes to the selection state of the data
    /// </summary>
    /// <param name="val">The state of the selection</param>
    public delegate void SelectedChangedDelegate(bool val);
 
    /// <summary>
    /// This class represents an inventory record
    /// </summary>
    public class InventoryData
    {
        /// <summary>
        /// The name of the inventory item
        /// </summary>
        public string itemName;
 
        /// <summary>
        /// The cost of the inventory item
        /// </summary>
        public int itemCost;
 
        /// <summary>
        /// The damage the item can do
        /// </summary>
        public int itemDamage;
 
        /// <summary>
        /// The armor the item provides
        /// </summary>
        public int itemDefense;
 
        /// <summary>
        /// The weight of the item
        /// </summary>
        public int itemWeight;
 
        /// <summary>
        /// This description of the inventory item
        /// </summary>
        public string itemDescription;
 
        /// <summary>
        /// The path to the resources folder for the sprite
        /// representing this inventory item
        /// </summary>
        public string spritePath;
 
        /// <summary>
        /// The delegate to call if the data's selection state
        /// has changed. This will update any views that are hooked
        /// to the data so that they show the proper selection state UI.
        /// </summary>
        public SelectedChangedDelegate selectedChanged;
 
        /// <summary>
        /// The selection state
        /// </summary>
        private bool _selected;
        public bool Selected
        {
            get { return _selected; }
            set
            {
                // if the value has changed
                if (_selected != value)
                {
                    // update the state and call the selection handler if it exists
                    _selected = value;
                    if (selectedChanged != null) selectedChanged(_selected);
                }
            }
        }
    }
}