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
using UnityEngine;
using UnityEngine.UI;
using EnhancedUI.EnhancedScroller;
 
namespace EnhancedScrollerDemos.CellEvents
{
    /// <summary>
    /// These delegates will publish events when a button is clicked
    /// </summary>
    /// <param name="value"></param>
    public delegate void CellButtonTextClickedDelegate(string value);
    public delegate void CellButtonIntegerClickedDelegate(int value);
 
    public class CellView : EnhancedScrollerCellView
    {
        private Data _data;
 
        public Text someTextText;
 
        /// <summary>
        ///  These delegates will fire whenever one of the events occurs
        /// </summary>
        public CellButtonTextClickedDelegate cellButtonTextClicked;
        public CellButtonIntegerClickedDelegate cellButtonFixedIntegerClicked;
        public CellButtonIntegerClickedDelegate cellButtonDataIntegerClicked;
 
        public void SetData(Data data)
        {
            _data = data;
            someTextText.text = (_data.hour == 0 ? "Midnight" : string.Format("{0} 'o clock", _data.hour.ToString()));
        }
 
        // Handle the click of the fixed text button (this is hooked up in the Unity editor in the button's click event)
        public void CellButtonText_OnClick(string value)
        {
            // fire event if anyone has subscribed to it
            if (cellButtonTextClicked != null) cellButtonTextClicked(value);
        }
 
        // Handle the click of the fixed integer button (this is hooked up in the Unity editor in the button's click event)
        public void CellButtonFixedInteger_OnClick(int value)
        {
            // fire event if anyone has subscribed to it
            if (cellButtonFixedIntegerClicked != null) cellButtonFixedIntegerClicked(value);
        }
 
        // Handle the click of the data integer button (this is hooked up in the Unity editor in the button's click event)
        public void CellButtonDataInteger_OnClick()
        {
            // fire event if anyone has subscribed to it
            if (cellButtonDataIntegerClicked != null) cellButtonDataIntegerClicked(_data.hour);
        }
    }
}