315 lines
9.3 KiB
C#
315 lines
9.3 KiB
C#
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using System.Threading;
|
||
using TMPro;
|
||
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
|
||
public class BattlePanel : BasePanel
|
||
{
|
||
//地图境界
|
||
public Text txtTitle;
|
||
//奖励
|
||
public Text txtAward;
|
||
|
||
//降低地图
|
||
public Button btnLowMap;
|
||
//提升地图
|
||
public Button btnUpMap;
|
||
//降低一层
|
||
public Button btnLowLev;
|
||
//提升一层
|
||
public Button btnUpLev;
|
||
|
||
//玩家对象
|
||
public PlayerObject playerObj;
|
||
//怪物对象
|
||
public MonsterObject monsterObj;
|
||
|
||
//伤害数字
|
||
public Transform damageUser;
|
||
public Transform damageMonster;
|
||
|
||
//对象池点1,2
|
||
public Transform target1;
|
||
public Transform target2;
|
||
|
||
|
||
void Awake()
|
||
{
|
||
//显示面板即把时间缩放变为1
|
||
if (Time.timeScale<1)
|
||
{
|
||
Time.timeScale = 1f;
|
||
}
|
||
|
||
//注册伤害数字弹出事件
|
||
EventCenter.Instance.AddEventListener<int>(E_EventType.E_Player_DamageNum, DamageUserNum);
|
||
EventCenter.Instance.AddEventListener<int>(E_EventType.E_Player_CritDamageNum, DamageUserCritNum);
|
||
EventCenter.Instance.AddEventListener<int>(E_EventType.E_Monster_DamageNum, DamageMonsterNum);
|
||
EventCenter.Instance.AddEventListener<int>(E_EventType.E_Monster_CritDamageNum, DamageMonsterCritNum);
|
||
//注册重置玩家和怪物数据
|
||
EventCenter.Instance.AddEventListener(E_EventType.E_Player_Init,InitPlayerPanel);
|
||
EventCenter.Instance.AddEventListener(E_EventType.E_Monster_Init,InitMonsterPanel);
|
||
//注册弹窗信息
|
||
EventCenter.Instance.AddEventListener<string>(E_EventType.E_Pool_Register1, PoolTipTarget1);
|
||
EventCenter.Instance.AddEventListener<string>(E_EventType.E_Pool_Register2, PoolTipTarget2);
|
||
}
|
||
|
||
public override void Init()
|
||
{
|
||
//刚进来需要更新面板
|
||
UpdatePanel();
|
||
|
||
//点击降低地图按钮做什么
|
||
btnLowMap.onClick.AddListener(() =>
|
||
{
|
||
//按钮被点击提示面板
|
||
BtnOnclick2("降低地图按钮被点击了");
|
||
UpOrDownMap(-10, GameDataMgr.Instance.nowMonster);
|
||
});
|
||
//点击提升地图按钮做什么
|
||
btnUpMap.onClick.AddListener(() =>
|
||
{
|
||
BtnOnclick2("提升地图按钮被点击了");
|
||
UpOrDownMap(10, GameDataMgr.Instance.nowMonster);
|
||
});
|
||
//点击降低一层按钮做什么
|
||
btnLowLev.onClick.AddListener(() =>
|
||
{
|
||
BtnOnclick2("降低一层按钮被点击了");
|
||
UpOrDownLev(-1, GameDataMgr.Instance.nowMonster);
|
||
});
|
||
//点击提升一层按钮做什么
|
||
btnUpLev.onClick.AddListener(() =>
|
||
{
|
||
BtnOnclick2("提升一层按钮被点击了");
|
||
UpOrDownLev(1, GameDataMgr.Instance.nowMonster);
|
||
});
|
||
}
|
||
|
||
/// <summary>
|
||
/// 提升或降低一层境界
|
||
/// </summary>
|
||
/// <param name="num">提升或降低多少层数</param>
|
||
/// <param name="nowMonster">当前的怪物数据</param>
|
||
private void UpOrDownLev(int num,MonsterData monster)
|
||
{
|
||
int nowMonsterNum = GameDataMgr.Instance.monsters.IndexOf(monster);
|
||
int index1=nowMonsterNum/10;
|
||
nowMonsterNum += num;
|
||
int index2=nowMonsterNum/10;
|
||
if (nowMonsterNum > GameDataMgr.Instance.monsters.Count-1)
|
||
{
|
||
BtnOnclick1("怪物已达到最高境界");
|
||
return;
|
||
}
|
||
if (nowMonsterNum < 0)
|
||
{
|
||
BtnOnclick1("怪物已是最低境界");
|
||
return;
|
||
}
|
||
|
||
//改变地图成功
|
||
if (index1==index2)
|
||
{
|
||
//飞剑需要放入对象池
|
||
GameMgr.Instance.isFeijianClose = true;
|
||
|
||
GameDataMgr.Instance.nowMonster = GameDataMgr.Instance.monsters[nowMonsterNum];
|
||
//重置面板 包括玩家数据 怪物数据
|
||
UpdatePanel();
|
||
|
||
if (num>0)
|
||
{
|
||
BtnOnclick1("境界提高,怪物已更新");
|
||
}
|
||
else
|
||
{
|
||
BtnOnclick1("境界降低,怪物已更新");
|
||
}
|
||
}
|
||
else
|
||
{
|
||
BtnOnclick1("请提升角色境界");
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 地图提升或降低
|
||
/// </summary>
|
||
/// <param name="num"></param>
|
||
/// <param name="nowMonster"></param>
|
||
private void UpOrDownMap(int num, MonsterData monster)
|
||
{
|
||
int nowMonsterNum = GameDataMgr.Instance.monsters.IndexOf(monster);
|
||
//每次提升或降低地图都是从每十层的第一层开始
|
||
nowMonsterNum =nowMonsterNum/10*10+num;
|
||
|
||
if (nowMonsterNum > GameDataMgr.Instance.monsters.Count-1)
|
||
{
|
||
BtnOnclick1("怪物已达到最高境界");
|
||
return;
|
||
}
|
||
if (nowMonsterNum < 0)
|
||
{
|
||
BtnOnclick1("怪物已是最低境界");
|
||
return;
|
||
}
|
||
//改变地图成功
|
||
if (GameDataMgr.Instance.player.stateId >= nowMonsterNum)
|
||
{
|
||
//飞剑需要放入对象池
|
||
GameMgr.Instance.isFeijianClose = true;
|
||
|
||
GameDataMgr.Instance.nowMonster = GameDataMgr.Instance.monsters[nowMonsterNum];
|
||
//重置面板 包括玩家数据 怪物数据
|
||
UpdatePanel();
|
||
|
||
if (num > 0)
|
||
{
|
||
BtnOnclick1("境界提高,怪物已更新");
|
||
}
|
||
else
|
||
{
|
||
BtnOnclick1("境界降低,怪物已更新");
|
||
}
|
||
}
|
||
else
|
||
{
|
||
BtnOnclick1("请提升角色境界");
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 更新战斗面板上的界面显示
|
||
/// </summary>
|
||
private void UpdatePanel()
|
||
{
|
||
MonsterData monster = GameDataMgr.Instance.nowMonster;
|
||
//固定奖励
|
||
txtAward.text = "固定奖励:" + "灵石+" + GameMgr.Instance.SetNumber(monster.stone) + ",源石+" + monster.yuan;
|
||
//地图境界
|
||
txtTitle.text = monster.state;
|
||
//玩家是否开始攻击-开始
|
||
GameMgr.Instance.isStartAtk = true;
|
||
//飞剑回收仓库
|
||
GameMgr.Instance.isFeijianClose = true;
|
||
|
||
//重置玩家的数据和面板
|
||
InitPlayerPanel();
|
||
//重置怪物的数据和面板
|
||
InitMonsterPanel();
|
||
}
|
||
|
||
//上方提示栏
|
||
private void BtnOnclick1(string str)
|
||
{
|
||
EventCenter.Instance.EventTrigger(E_EventType.E_Pool_Register1, str);
|
||
}
|
||
//下方提示栏
|
||
private void BtnOnclick2(string str)
|
||
{
|
||
EventCenter.Instance.EventTrigger(E_EventType.E_Pool_Register2, str);
|
||
}
|
||
|
||
//初始化玩家的面板
|
||
private void InitPlayerPanel()
|
||
{
|
||
EventCenter.Instance.Claer(E_EventType.E_Player_Wound);
|
||
if (!playerObj.gameObject.activeSelf)
|
||
{
|
||
playerObj.gameObject.SetActive(true);
|
||
}
|
||
playerObj.UpdatePanel();
|
||
}
|
||
//初始化怪物的面板
|
||
private void InitMonsterPanel()
|
||
{
|
||
EventCenter.Instance.Claer(E_EventType.E_Monster_Wound);
|
||
if (!monsterObj.gameObject.activeSelf)
|
||
{
|
||
monsterObj.gameObject.SetActive(true);
|
||
}
|
||
monsterObj.UpdatePanel();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 玩家被伤害数字弹窗
|
||
/// </summary>
|
||
private void DamageUserNum(int damageHp)
|
||
{
|
||
//弹出减血量数字
|
||
GameObject go = PoolMgr.Instance.GetObj("Object/DamageNum");
|
||
go.transform.SetParent(damageUser, false);
|
||
go.transform.localPosition = Vector3.zero;
|
||
go.transform.localScale = Vector3.one;
|
||
go.GetComponent<DamageNum>().UpdateTxtInfo("-" + damageHp);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 玩家被暴击伤害数字弹窗
|
||
/// </summary>
|
||
private void DamageUserCritNum(int damageHp)
|
||
{
|
||
//弹出减血量数字
|
||
GameObject go = PoolMgr.Instance.GetObj("Object/DamageNum");
|
||
go.transform.SetParent(damageUser, false);
|
||
go.transform.localPosition = Vector3.zero;
|
||
go.transform.localScale = new Vector3(1.5f, 1.5f, 1.5f);
|
||
go.GetComponent<DamageNum>().UpdateTxtInfo("-" + damageHp);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 怪物被伤害数字弹窗
|
||
/// </summary>
|
||
private void DamageMonsterNum(int damageHp)
|
||
{
|
||
//弹出减血量数字
|
||
GameObject go = PoolMgr.Instance.GetObj("Object/DamageNum");
|
||
go.transform.SetParent(damageMonster, false);
|
||
go.transform.localPosition = Vector3.zero;
|
||
go.transform.localScale = Vector3.one;
|
||
go.GetComponent<DamageNum>().UpdateTxtInfo("-" + damageHp);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 怪物被暴击伤害数字弹窗
|
||
/// </summary>
|
||
private void DamageMonsterCritNum(int damageHp)
|
||
{
|
||
//弹出减血量数字
|
||
GameObject go = PoolMgr.Instance.GetObj("Object/DamageNum");
|
||
go.transform.SetParent(damageMonster, false);
|
||
go.transform.localPosition = Vector3.zero;
|
||
go.transform.localScale = new Vector3(1.5f, 1.5f, 1.5f);
|
||
go.GetComponent<DamageNum>().UpdateTxtInfo("-" + damageHp);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 公用的弹窗点1事件添加进事件中心
|
||
/// </summary>
|
||
/// <param name="str"></param>
|
||
private void PoolTipTarget1(string str)
|
||
{
|
||
GameObject obj = PoolMgr.Instance.GetObj("Object/TipTool");
|
||
obj.transform.SetParent(target1, false);
|
||
obj.transform.localPosition = Vector3.zero;
|
||
obj.transform.localScale = Vector3.one;
|
||
obj.GetComponent<TipTool>().UpdateTxtInfo(str);
|
||
}
|
||
/// <summary>
|
||
/// 公用的弹窗点1事件添加进事件中心
|
||
/// </summary>
|
||
/// <param name="str"></param>
|
||
private void PoolTipTarget2(string str)
|
||
{
|
||
GameObject obj = PoolMgr.Instance.GetObj("Object/TipTool");
|
||
obj.transform.SetParent(target2, false);
|
||
obj.transform.localPosition = Vector3.zero;
|
||
obj.transform.localScale = Vector3.one;
|
||
obj.GetComponent<TipTool>().UpdateTxtInfo(str);
|
||
}
|
||
|
||
}
|