//--------------------------------------------------------
|
// [Author]: 第二世界
|
// [ Date ]: Saturday, October 14, 2017
|
//--------------------------------------------------------
|
using UnityEngine;
|
using System.Collections;
|
using UnityEngine.UI;
|
|
namespace Snxxz.UI
|
{
|
|
public class PlayerLifeBar : MonoBehaviour
|
{
|
[SerializeField] Image m_Icon;
|
[SerializeField] Button m_ViewPlayer;
|
[SerializeField] Text m_PlayerName;
|
[SerializeField] Text m_PlayerLevel;
|
[SerializeField] Text m_Hp;
|
|
[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 _job, int _jobRank, string _name, int _level, ulong _hp, ulong _maxHp)
|
{
|
playerId = _playerId;
|
|
m_Icon.SetSprite(GeneralDefine.GetJobHeadPortrait(_job, _jobRank));
|
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);
|
}
|
|
public void Show(ulong _hp, ulong _maxHp)
|
{
|
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.gameObject.SetActive(true);
|
}
|
|
public void Hide()
|
{
|
this.gameObject.SetActive(false);
|
}
|
|
void Awake()
|
{
|
reduceHpDelay[0] = 0f;
|
reduceHpDelay[1] = delay;
|
|
addHpDelay[0] = delay;
|
addHpDelay[1] = 0f;
|
}
|
|
private void OnEnable()
|
{
|
multipleSlider.ResetValue(value);
|
m_ViewPlayer.AddListener(ViewPlayer);
|
}
|
|
private void OnDisable()
|
{
|
m_ViewPlayer.RemoveAllListeners();
|
}
|
|
private void ViewPlayer()
|
{
|
PlayerDetails.ShowAreaPlayer(playerId);
|
}
|
}
|
|
}
|