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
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using EnhancedUI.EnhancedScroller;
 
namespace EnhancedScrollerDemos.MultipleCellTypesDemo
{
    /// <summary>
    /// This is the view for the rows
    /// </summary>
    public class CellViewRow : CellView
    {
        /// <summary>
        /// An internal reference to the row data. We could have just
        /// used the base CellView's class member _data, but that would
        /// require us to cast it each time a row data field is needed.
        /// By referencing the row data, we can save some time accessing
        /// the fields.
        /// </summary>
        private RowData _rowData;
 
        /// <summary>
        /// Links to the UI fields
        /// </summary>
        public Text userNameText;
        public Image userAvatarImage;
        public Text userHighScoreText;
 
        /// <summary>
        /// Override of the base class's SetData function. This links the data
        /// and updates the UI
        /// </summary>
        /// <param name="data"></param>
        public override void SetData(Data data)
        {
            // call the base SetData to link to the underlying _data
            base.SetData(data);
 
            // cast the data as rowData and store the reference
            _rowData = data as RowData;
 
            // update the UI with the data fields
            userNameText.text = _rowData.userName;
            userAvatarImage.sprite = Resources.Load<Sprite>(_rowData.userAvatarSpritePath);
            userHighScoreText.text = string.Format("{0:n0}", _rowData.userHighScore);
        }
    }
}