//--------------------------------------------------------
|
// [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);
|
}
|
}
|
|
}
|