少年修仙传客户端代码仓库
hch
2 天以前 600733c8f592cb9e65f2b7a3e110ac1d686e6bfe
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
//--------------------------------------------------------
//    [Author]:           第二世界
//    [  Date ]:           Saturday, October 14, 2017
//--------------------------------------------------------
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
 
namespace vnxbqy.UI
{
 
    public class PlayerLifeBar : MonoBehaviour
    {
        [SerializeField] AvatarCell avatarCell;
        [SerializeField] Text m_PlayerName;
        [SerializeField] Text m_PlayerLevel;
        [SerializeField] Text m_Hp;
        [SerializeField] Text m_ShieldText;
        [SerializeField] Image m_Shield;//护盾显示
 
        [SerializeField] MultipleSmoothSlider m_MultipleSlider;
        public MultipleSmoothSlider multipleSlider
        {
            get { return m_MultipleSlider; }
        }
 
        [SerializeField]
        [Range(0, 10)]
        float m_Delay;
        public float delay
        {
            get { return m_Delay; }
        }
 
        float m_Value;
        public float value
        {
            get
            {
                return m_Value;
            }
            set
            {
                m_Value = Mathf.Clamp01(value);
                if (multipleSlider != null)
                {
                    multipleSlider.value = m_Value;
                }
            }
        }
 
        int playerIdBuf = 0;
        float[] reduceHpDelay = new float[2];
        float[] addHpDelay = new float[2];
 
        int playerId = 0;
 
        public void SetBaseInfo(int _playerId,int face,int facePic, int _job, int _jobRank, string _name, 
            int _level, ulong _hp, ulong _maxHp, int shield, int maxShield)
        {
            playerId = _playerId;
            avatarCell.InitUI(AvatarHelper.GetAvatarModel(_playerId, face, facePic, _job));
            m_PlayerName.text = _name;
            m_PlayerLevel.text = _level.ToString();
 
            var targetValue = (float)_hp / _maxHp;
            m_Hp.text = StringUtility.Contact(UIHelper.ReplaceLargeNum(_hp), "/", UIHelper.ReplaceLargeNum(_maxHp));
            multipleSlider.ResetValue(targetValue);
            ShowShield(shield, maxShield);
        }
 
        public void Show(ulong _hp, ulong _maxHp, int shield, int maxShield)
        {
            var targetValue = _hp / (float)_maxHp;
            if (targetValue < this.value)
            {
                multipleSlider.UpdateDelayTimes(reduceHpDelay);
            }
            else
            {
                multipleSlider.UpdateDelayTimes(addHpDelay);
            }
 
            value = targetValue;
            m_Hp.text = StringUtility.Contact(UIHelper.ReplaceLargeNum(_hp), "/", UIHelper.ReplaceLargeNum(_maxHp));
            this.SetActive(true);
            ShowShield(shield, maxShield);
        }
 
        void ShowShield(int shield, int maxShield)
        {
            var fillAmount = maxShield <= 0 ? 1f : (float)shield / maxShield;
            m_Shield.fillAmount = fillAmount;
            m_ShieldText.text = StringUtility.Contact(UIHelper.ReplaceLargeNumEx(shield), "/", UIHelper.ReplaceLargeNumEx(maxShield));
        }
 
        public void Hide()
        {
            this.SetActive(false);
        }
 
        void Awake()
        {
            reduceHpDelay[0] = 0f;
            reduceHpDelay[1] = delay;
 
            addHpDelay[0] = delay;
            addHpDelay[1] = 0f;
        }
 
        private void OnEnable()
        {
            multipleSlider.ResetValue(value);
            avatarCell.button.AddListener(ViewPlayer);
        }
 
        private void OnDisable()
        {
            avatarCell.button.RemoveAllListeners();
        }
 
        private void ViewPlayer()
        {
            PlayerDetails.ShowAreaPlayer(playerId);
        }
    }
 
}