234 lines
6.5 KiB
C#
234 lines
6.5 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using static UnityEngine.GraphicsBuffer;
|
|
|
|
public class UserPanel : BasePanel
|
|
{
|
|
//灵气长度
|
|
public RectTransform imgGasLen;
|
|
private float gasWide = 620f;
|
|
|
|
//装备按钮
|
|
public Button btnEquip;
|
|
//灵剑
|
|
public Button btnJian;
|
|
//炼体
|
|
public Button btnLian;
|
|
//功法
|
|
public Button btnGong;
|
|
//突破
|
|
public Button btnTop;
|
|
|
|
//境界
|
|
public Text txtRealm;
|
|
public Outline outLine;
|
|
|
|
//加灵气点
|
|
public Transform gasTipPos;
|
|
//按钮消息点
|
|
public Transform tipPanelPos;
|
|
|
|
//灵气
|
|
public Text txtGas;
|
|
//血量
|
|
public Text txtHp;
|
|
//攻击力
|
|
public Text txtAtk;
|
|
//防御力
|
|
public Text txtDef;
|
|
//暴击
|
|
public Text txtCrit;
|
|
//仙玉加成
|
|
public Text txtMinuteGas;
|
|
//抗暴率
|
|
public Text txtKangCrit;
|
|
//攻击速度
|
|
public Text txtAtkSpeed;
|
|
//暴击伤害
|
|
public Text txtCritDamage;
|
|
//灵气加成
|
|
public Text txtGasAdd;
|
|
//灵石加成
|
|
public Text txtStone;
|
|
|
|
//玩家数据
|
|
private PlayerData player;
|
|
|
|
void Awake()
|
|
{
|
|
EventCenter.Instance.AddEventListener<int>(E_EventType.E_Pool_GasTip, GasTip);
|
|
|
|
//灵气和弹窗消息关闭立即消失
|
|
GameMgr.Instance.isUserNumAndGas = false;
|
|
}
|
|
|
|
public override void Init()
|
|
{
|
|
player=GameDataMgr.Instance.player;
|
|
//显示面板就更新
|
|
UpdatePanel();
|
|
|
|
//突破按钮点击
|
|
btnTop.onClick.AddListener(() =>
|
|
{
|
|
GasIsEnough();
|
|
});
|
|
btnEquip.onClick.AddListener(() =>
|
|
{
|
|
UIManager.Instance.ShowPanel<EquipPanel>(E_UILayer.System);
|
|
});
|
|
btnJian.onClick.AddListener(() =>
|
|
{
|
|
|
|
});
|
|
btnLian.onClick.AddListener(() =>
|
|
{
|
|
|
|
});
|
|
btnGong.onClick.AddListener(() =>
|
|
{
|
|
|
|
});
|
|
}
|
|
|
|
/// <summary>
|
|
/// 更新面板
|
|
/// </summary>
|
|
public void UpdatePanel()
|
|
{
|
|
//玩家的境界
|
|
txtRealm.text = player.state;
|
|
txtRealm.color = GameMgr.Instance.HexToColor(GameDataMgr.Instance.userUpGradeInfo[player.stateId].color);
|
|
outLine.effectColor = GameMgr.Instance.HexToColorAlaph(GameDataMgr.Instance.userUpGradeInfo[player.stateId].color);
|
|
//灵气
|
|
UpdateGas();
|
|
//血量
|
|
txtHp.text = "血量:" + player.hp;
|
|
//攻击力
|
|
txtAtk.text = "攻击力:" + player.atk;
|
|
//防御力
|
|
txtDef.text ="防御力:"+player.def;
|
|
//暴击
|
|
txtCrit.text = "暴击:" + player.crit.ToString("F1")+"%";
|
|
//每分钟灵气
|
|
txtMinuteGas.text = "每分钟灵气:" + player.minuteGas;
|
|
//抗爆率
|
|
txtKangCrit.text = "抗爆率:" + player.kangCrit.ToString("F1") + "%";
|
|
//攻击速度
|
|
txtAtkSpeed.text = "攻击速度:" + player.atkSpeed.ToString("F1") + "%";
|
|
//暴击伤害
|
|
txtCritDamage.text = "暴击伤害:" + player.critDamage.ToString("F1") + "%";
|
|
//灵气加成
|
|
txtGasAdd.text = "灵气加成:" + player.gasAdd.ToString("F1") + "%";
|
|
//灵石加成
|
|
txtStone.text="灵石加成:"+player.stoneAdd.ToString("F1") + "%";
|
|
}
|
|
|
|
/// <summary>
|
|
/// 判断灵气是否足够升级
|
|
/// </summary>
|
|
private void GasIsEnough()
|
|
{
|
|
if (player.stateId>=GameDataMgr.Instance.userUpGradeInfo.Count)
|
|
{
|
|
UserPanelTip("已达到最高境界");
|
|
return;
|
|
}
|
|
//判断是否够灵气升级
|
|
if (player.gas >= GameDataMgr.Instance.userUpGradeInfo[player.stateId+1].gas)
|
|
{
|
|
UserPanelTip("突破成功");
|
|
//计算玩家数据
|
|
CalcUserData(player.stateId);
|
|
//玩家数据更新后,更新面板数据;
|
|
UpdatePanel();
|
|
//更新Toppanel的数据
|
|
UIManager.Instance.GetPanel<TopPanel>().UpdatePanel();
|
|
}
|
|
else
|
|
{
|
|
UserPanelTip("灵气不足,突破失败");
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 突破后计算战斗力,计算玩家数据的函数
|
|
/// </summary>
|
|
/// <param name="stateId">玩家所在境界Id</param>
|
|
public void CalcUserData(int stateId)
|
|
{
|
|
UserUpgradeData user = GameDataMgr.Instance.userUpGradeInfo[stateId+1];
|
|
//战斗力=血量*10+攻击力*20+防御力*20+每分钟灵气
|
|
int fighting = user.hp * 10 + user.atk * 20 + user.def * 20 + (user.minuteGas-player.minuteGas)*10;
|
|
player.figthing += fighting;
|
|
//玩家灵气减少
|
|
player.gas -= user.gas;
|
|
|
|
//玩家数据计算
|
|
//境界提升
|
|
player.state = user.state;
|
|
player.hp += user.hp;
|
|
player.atk += user.atk;
|
|
player.def += user.def;
|
|
player.minuteGas = user.minuteGas;
|
|
player.stateId += 1;
|
|
|
|
//保存数据到本地
|
|
GameDataMgr.Instance.PlayerDataSave();
|
|
}
|
|
|
|
//加灵气弹窗消息
|
|
private void GasTip(int gas)
|
|
{
|
|
GameObject obj = PoolMgr.Instance.GetObj("Object/AddGasNum");
|
|
obj.transform.SetParent(gasTipPos, false);
|
|
obj.transform.localPosition = Vector3.zero;
|
|
obj.transform.localScale = Vector3.one;
|
|
obj.GetComponent<AddGasNum>().UpdateTxtInfo("灵气+"+gas);
|
|
//同时更新灵气面板
|
|
UpdateGas();
|
|
}
|
|
|
|
//按键点击弹窗消息
|
|
private void UserPanelTip(string str)
|
|
{
|
|
GameObject obj = PoolMgr.Instance.GetObj("Object/UserTipTool");
|
|
obj.transform.SetParent(tipPanelPos, false);
|
|
obj.transform.localPosition = Vector3.zero;
|
|
obj.transform.localScale = Vector3.one;
|
|
obj.GetComponent<UserTipTool>().UpdateTxtInfo(str);
|
|
}
|
|
|
|
//更新灵气条
|
|
public void UpdateGas()
|
|
{
|
|
if ((player.stateId + 1) > (GameDataMgr.Instance.userUpGradeInfo.Count - 1))
|
|
{
|
|
txtGas.text = GameMgr.Instance.SetNumber(player.gas) + "/" + "无";
|
|
imgGasLen.sizeDelta = new Vector2(gasWide, imgGasLen.sizeDelta.y);
|
|
}
|
|
else
|
|
{
|
|
txtGas.text = player.gas + "/" + GameDataMgr.Instance.userUpGradeInfo[player.stateId + 1].gas;
|
|
if (player.gas >= GameDataMgr.Instance.userUpGradeInfo[player.stateId + 1].gas)
|
|
{
|
|
imgGasLen.sizeDelta = new Vector2(gasWide, imgGasLen.sizeDelta.y);
|
|
}
|
|
else
|
|
{
|
|
imgGasLen.sizeDelta = new Vector2(gasWide * player.gas / GameDataMgr.Instance.userUpGradeInfo[player.stateId + 1].gas, imgGasLen.sizeDelta.y);
|
|
}
|
|
}
|
|
}
|
|
|
|
//删除面板时,清楚事件内容
|
|
void OnDestroy()
|
|
{
|
|
EventCenter.Instance.Claer(E_EventType.E_Pool_GasTip);
|
|
//灵气和弹窗消息关闭立即消失
|
|
GameMgr.Instance.isUserNumAndGas = true;
|
|
}
|
|
}
|