NLDClient-yudde/ProjectNLD/Assets/Code/Scripts/Gameplay/UI/ShowAllCharacter/UILevelUpController.cs

628 lines
20 KiB
C#
Raw Normal View History

2023-10-19 15:00:19 +08:00
using cfg.CharacterCfg;
2023-08-22 19:08:45 +08:00
using Framework;
using Gameplay.Common;
using Gameplay.Net;
2023-10-19 15:00:19 +08:00
using NLDPB;
2023-08-22 19:08:45 +08:00
using System;
2023-11-30 16:18:57 +08:00
using System.Numerics;
using Gameplay;
2023-08-22 19:08:45 +08:00
using TMPro;
2023-11-30 16:18:57 +08:00
using UnityEngine;
using UnityEngine.EventSystems;
2023-08-22 19:08:45 +08:00
using Button = UnityEngine.UI.Button;
using Image = UnityEngine.UI.Image;
2023-11-30 16:18:57 +08:00
using Vector3 = UnityEngine.Vector3;
2024-07-25 20:08:53 +08:00
using Vector2 = UnityEngine.Vector2;
2024-03-28 18:58:39 +08:00
using Cysharp.Threading.Tasks;
using UnityEngine.UI;
2024-04-28 18:47:34 +08:00
using PhxhSDK;
using LC.Newtonsoft.Json.Bson;
using static CriWare.CriAtomExBeatSync;
2023-08-22 19:08:45 +08:00
public class UILevelUpController : UIWindow
{
//UI GameObj
///Auto Gen Start///
public Image Image_BG;
public Button Button_Back;
public Button Button_Home;
public Image Image_PointBG;
public TMP_Text Text_ExpPoint;
public TMP_Text Text_UniversalExp;
public TMP_Text Text_Exp_Value;
public Image Image_LevelUPBar;
public Image Image_Poster;
public TMP_Text Text_Level_Now;
public TMP_Text Text_Level_Max;
public Image Image_Hp;
public TMP_Text Text_Hp;
public TMP_Text Text_Hp_Value;
public TMP_Text Text_Change_Hp;
public Image Image_Morale;
public TMP_Text Text_Cultivate_Morale;
public TMP_Text Text_Morale_Value;
public TMP_Text Text_Change_Morale;
public Image Image_Defense;
public TMP_Text Text_Cultivate_Defense;
public TMP_Text Text_Defense_Value;
public TMP_Text Text_Change_Defanse;
public Image Image_Armor;
public TMP_Text Text_Cultivate_Armor;
public TMP_Text Text_Armor_Value;
public TMP_Text Text_Change_Armor;
public Image Image_Attack;
public TMP_Text Text_Cultivate_Attack;
public TMP_Text Text_Attack_Value;
public TMP_Text Text_Change_Attack;
public Image Image_Speed;
public TMP_Text Text_Cultivate_Speed;
public TMP_Text Text_Speed_Value;
public TMP_Text Text_Change_Speed;
public TMP_Text Text_ExpBefore;
public TMP_Text Text_EXP;
public TMP_Text Text_Plus;
public TMP_Text Text_ExpNeed;
public TMP_Text Text_Level_Value;
public TMP_Text Text_LV;
public TMP_Text Text_LevelUpTo;
public Button Button_MAX;
public Button Button_Plus;
public Button Button_Minus;
public Image Image_LevelBar;
public Image Image_LevelArrow;
2024-07-25 20:08:53 +08:00
float ArrowRadius;
2023-08-22 19:08:45 +08:00
public TMP_Text Text_Level;
public Button Button_Cannot;
public TMP_Text Text_Cannot_Confirm;
public Button Button_Confirm;
public TMP_Text Text_Confirm;
public Button Button_Cancel;
2024-03-28 18:58:39 +08:00
/// Auto Gen End///
2023-08-22 19:08:45 +08:00
2024-03-28 18:58:39 +08:00
/// <summary>
/// 打开角色升级界面
/// </summary>
public static async UniTask<UIWindow> Open(CharacterDataInfo characterDataInfo)
{
2024-09-18 16:03:02 +08:00
CommonUtils.CaptureScreenshot();
2024-03-28 18:58:39 +08:00
2024-05-16 12:40:15 +08:00
return await UIManager.Instance.CreateAndOpenWindow(UINameConst.UILevelUp, characterDataInfo);
2024-03-28 18:58:39 +08:00
}
2024-04-28 18:47:34 +08:00
/// <summary>
/// 台词类
/// </summary>
private class Dialogue : UIGameObjectWrapper
{
/// <summary>
/// 角色名
/// </summary>
private TMP_Text textName;
/// <summary>
/// 角色类型
/// </summary>
private TMP_Text textContent;
public Dialogue(GameObject root) : base(root)
{
textName = GetComponent<TMP_Text>("Text_Name");
textContent = GetComponent<TMP_Text>("Text_Describe");
}
public void SetInfo(string name)
{
textName.text = name;
}
public void SetDialogue(string content)
{
textContent.text = content;
}
}
2024-03-28 18:58:39 +08:00
/// <summary>
/// 高斯模糊遮罩
/// </summary>
private RawImage rawImageGaussianBlurMask;
/// <summary>
/// 升级总消耗经验
/// </summary>
2024-03-28 18:58:39 +08:00
private int expLast;
bool useAllExp = false;//达不到上限,有多少经验用多少经验
2023-08-22 19:08:45 +08:00
CharacterDataInfo mCharacterDataInfo;
private int mCurrentExp;
CharacterLevelExp mCharacterLevelExpCfg;
CharacterBreak mCharacterBreak;
int targetLevel ;
2023-11-30 16:18:57 +08:00
public DragForUI dragForUI;
private AudioInst dialogueAudio;
2024-04-28 18:47:34 +08:00
private Dialogue dialogue;
2024-04-28 17:27:23 +08:00
/// <summary>
/// 是否正在播放台词语音
/// </summary>
public bool IsDialoguePlaying
{
get { return dialogueAudio != null && dialogueAudio.IsPlaying; }
}
2023-08-22 19:08:45 +08:00
// Use this for initialization
2024-01-23 12:25:47 +08:00
public override void OnInit()
2023-08-22 19:08:45 +08:00
{
//bind UI GameObj
UILevelUpBinder.GetComponents(this);
2024-07-25 20:08:53 +08:00
ArrowRadius = -Image_LevelArrow.GetComponent<RectTransform>().anchoredPosition.y;
2024-03-28 18:58:39 +08:00
rawImageGaussianBlurMask = GetComponent<RawImage>("GaussianBlurMask");
rawImageGaussianBlurMask.texture = CommonUtils.GetScreenTexture2D();
2024-03-28 18:58:39 +08:00
2024-04-28 18:47:34 +08:00
dialogue = new(FindObj("Image_ActorLineBG"));
2024-03-28 18:58:39 +08:00
BindButton(Button_Back, OnButton_BackClick);
2023-08-22 19:08:45 +08:00
BindButton(Button_Plus, OnButton_PlusClick);
BindButton(Button_Minus, OnButton_MinusClick);
BindButton(Button_MAX, OnButton_MAXClick);
BindButton(Button_Cancel, OnButton_CancelClick);
BindButton(Button_Confirm, OnButton_ConfirmClick);
2023-11-21 15:18:32 +08:00
BindButton(Button_Home, OnClickHome);
dragForUI = CommonUtils.GetComponent<DragForUI>(this.gameObject,"Drag");
2023-11-30 16:18:57 +08:00
dragForUI.OnDragStarted += ondragStart;
dragForUI.OnDraging += ondrag;
dragForUI.OnDragCompleted += ondragend;
RegisterEvent();
2023-11-30 16:18:57 +08:00
}
UnityEngine.Vector2 startPos;
float interval;//滑动的间隔
float levelCursor;//将等级想象成游标进行滑动
2023-11-30 16:18:57 +08:00
private void ondragend(PointerEventData eventData)
{
}
private void ondrag(PointerEventData eventData)
{
//float offset = eventData.position.y - startPos.y;
float offset = eventData.delta.y;
2023-11-30 16:18:57 +08:00
if (offset < 0)
{
if (targetLevel <= mCharacterDataInfo.Level)//不可小于已达成等级
2023-11-30 16:18:57 +08:00
{
return;
}
levelCursor += interval * offset;
targetLevel = (int)levelCursor;
if (targetLevel <= mCharacterDataInfo.Level)
targetLevel = (int)mCharacterDataInfo.Level;
CalculateExp();
RefreshAfterChangeValue();
2023-11-30 16:18:57 +08:00
RefreshLevelUpBtn();
}
else
{
2023-11-30 16:18:57 +08:00
if (mCharacterBreak.Get((int)mCharacterDataInfo.ID, (int)mCharacterDataInfo.BreakLevel) == null)
{
DebugUtil.LogError("没有配置Id {0} 突破等级 {1}", mCharacterDataInfo.ID, mCharacterDataInfo.BreakLevel);
return;
}
if (targetLevel >= GetExpEnoughMaxLevel(out _))
2023-11-30 16:18:57 +08:00
{
return;
}
levelCursor += interval * offset;
targetLevel = (int)levelCursor;
if (targetLevel > GetExpEnoughMaxLevel(out _))
{
targetLevel = GetExpEnoughMaxLevel(out uint consumeExp);
}
CalculateExp();
RefreshAfterChangeValue();
2023-11-30 16:18:57 +08:00
RefreshLevelUpBtn();
}
}
private void ondragStart(PointerEventData eventData)
{
startPos = eventData.position;
interval = (mCharacterBreak.Get((int)mCharacterDataInfo.ID, (int)mCharacterDataInfo.BreakLevel).LevelLimit - mCharacterDataInfo.Level) / 400f;
levelCursor = targetLevel;
2023-11-21 15:18:32 +08:00
}
2023-11-30 16:18:57 +08:00
2023-11-21 15:18:32 +08:00
private void OnClickHome()
{
UIManager.Instance.CloseAllNormalExcept(UINameConst.UI_MainPanel);
}
2023-08-22 19:08:45 +08:00
private void RegisterEvent()
{
2023-10-19 15:00:19 +08:00
EventManager.Instance.Register(EventManager.EventName.EN_CharacterLevelUp,(Action<UpgradeType>)OnCharacterLevelup);
2023-08-22 19:08:45 +08:00
}
2023-10-19 15:00:19 +08:00
2024-07-31 13:39:07 +08:00
private void OnCharacterLevelup(UpgradeType type)
2023-10-19 15:00:19 +08:00
{
2024-04-28 17:27:23 +08:00
if (type != UpgradeType.UtLevel)
{
return;
}
2024-10-15 19:32:57 +08:00
AudioManager.Instance.PlayAudio(Framework.Constants.Sound.CHARACTER_LEVEL_UP);
2023-10-19 15:00:19 +08:00
mCharacterDataInfo = CharacterDataInfoManager.Instance.GetCharacterInfo(mCharacterDataInfo.ID);
2023-08-22 19:08:45 +08:00
targetLevel = (int)mCharacterDataInfo.Level;
expLast = 0;
2023-08-22 19:08:45 +08:00
RefreshUI();
RefreshAfterChangeValue();
RefreshLevelUpBtn();
2024-04-24 14:31:42 +08:00
2024-04-28 18:47:34 +08:00
dialogueAudio?.Stop();
2024-07-31 13:39:07 +08:00
dialogueAudio = DialogueManager.Instance.PlayDiaogue((int)mCharacterDataInfo.Uid,
2024-04-28 17:27:23 +08:00
cfg.DialogueCfg.E_DialogueType.UpLevel,
2024-04-28 18:47:34 +08:00
(content) => { dialogue.SetDialogue(content); });
2023-08-22 19:08:45 +08:00
}
2023-10-19 15:00:19 +08:00
2023-08-22 19:08:45 +08:00
private void UnregisterEvent()
{
2023-10-19 15:00:19 +08:00
EventManager.Instance.Unregister(EventManager.EventName.EN_CharacterLevelUp,(Action<UpgradeType>)OnCharacterLevelup);
2023-08-22 19:08:45 +08:00
}
private void RefreshLevelUpBtn()
{
Button_Cannot.gameObject.SetActive(expLast <= 0);//targetLevel == mCharacterDataInfo.Level
Button_Confirm.gameObject.SetActive(expLast > 0);//targetLevel != mCharacterDataInfo.Level
Button_Cancel.gameObject.SetActive(expLast > 0);
2023-08-22 19:08:45 +08:00
}
private void OnButton_ConfirmClick()
{
if (expLast <= 0)//targetLevel == mCharacterDataInfo.Level
{
return;
}
//if (targetLevel >= expLast)
//{
// CommonUtils.ShowMessageTips(CommonUtils.GetLocalizeText("cultivate_expDontFull"));
// return;
//}
2024-10-18 18:39:38 +08:00
AudioManager.Instance.PlayAudio(Framework.Constants.Sound.COMMON_CLICK);
2023-10-19 15:00:19 +08:00
if (Actor.Instance.Item.GetItemCount(GLConfig.Inst.data.HeroExpItem)< expLast)
2023-12-21 15:59:18 +08:00
{
CommonUtils.ShowMessageTips(CommonUtils.GetLocalizeText("cultivate_expDontFull"));
2023-10-19 15:00:19 +08:00
return;
}
NetHelper.CharacterUpgrade(mCharacterDataInfo.ID, NLDPB.UpgradeType.UtLevel, (uint)targetLevel, useAllExp);
2023-08-22 19:08:45 +08:00
}
private void OnButton_CancelClick()
{
if (expLast <= 0)
{
return;
}
2024-10-18 18:39:38 +08:00
AudioManager.Instance.PlayAudio(Framework.Constants.Sound.COMMON_CLICK);
targetLevel = (int)mCharacterDataInfo.Level;
if (useAllExp)
useAllExp = false;
CalculateExp();
RefreshAfterChangeValue();
RefreshLevelUpBtn();
2023-08-22 19:08:45 +08:00
}
2023-10-19 15:00:19 +08:00
private void OnButton_MAXClick()
2023-08-22 19:08:45 +08:00
{
2024-10-15 19:32:57 +08:00
AudioManager.Instance.PlayAudio(Framework.Constants.Sound.COMMON_CLAIM);
if (targetLevel > mCharacterDataInfo.Cfg.Hp.Count)
2023-10-19 15:00:19 +08:00
{
DebugUtil.LogError("levelexp表和各种属性没有该突破等级的等级限制等级");
return;
}
2023-08-22 19:08:45 +08:00
if (targetLevel >= mCharacterBreak.Get((int)mCharacterDataInfo.ID, (int)mCharacterDataInfo.BreakLevel).LevelLimit)
{
2023-12-21 15:59:18 +08:00
CommonUtils.ShowMessageTips(CommonUtils.GetLocalizeText("cultivate_LevelUpMAX"));
2023-08-22 19:08:45 +08:00
return;
}
targetLevel = GetExpEnoughMaxLevel(out _);//mCharacterBreak.Get((int)mCharacterDataInfo.ID, (int)mCharacterDataInfo.BreakLevel).LevelLimit;
//expLast = (int)consumeExp;
CalculateExp();
2023-08-22 19:08:45 +08:00
RefreshAfterChangeValue();
RefreshLevelUpBtn();
}
/// <summary>
/// 获取最大经验值填充后的等级(超出等级上限取最大等级)
/// </summary>
/// <param name="consumeExp"></param>
/// <returns></returns>
int GetExpEnoughMaxLevel(out uint consumeExp)
{
var exp = Actor.Instance.Item.GetItemCount(GLConfig.Inst.data.HeroExpItem);
int level = (int)mCharacterDataInfo.Level;
int consume = -(int)mCharacterDataInfo.Exp;
while (level < mCharacterBreak.Get((int)mCharacterDataInfo.ID, (int)mCharacterDataInfo.BreakLevel).LevelLimit)
{
if (mCharacterLevelExpCfg.GetOrDefault((level + 1)) != null)
{
var needExp = mCharacterLevelExpCfg.GetOrDefault((level + 1)).EXP;
if (consume + needExp > exp)
{
consumeExp = exp;//达不到上限,有多少经验用多少经验
return level;
}
else
{
consume += needExp;
}
}
else
{
DebugUtil.LogError("CharacterLevelExpCfg的等级不够了");
}
level++;
}
consumeExp = (uint)consume;
return level;
}
2023-08-22 19:08:45 +08:00
private void OnButton_MinusClick()
{
2024-10-15 19:32:57 +08:00
AudioManager.Instance.PlayAudio(Framework.Constants.Sound.COMMON_CLAIM);
if (expLast <= 0)//targetLevel <= mCharacterDataInfo.Level
2023-08-22 19:08:45 +08:00
{
2024-08-30 16:34:40 +08:00
CommonUtils.ShowMessageTips(CommonUtils.GetLocalizeText("cultivate_LevelUpMIN"));
2023-08-22 19:08:45 +08:00
return;
}
if (!useAllExp)
targetLevel--;
else
useAllExp = false;
CalculateExp();
2023-08-22 19:08:45 +08:00
RefreshAfterChangeValue();
RefreshLevelUpBtn();
}
private void OnButton_PlusClick()
{
2024-10-15 19:32:57 +08:00
AudioManager.Instance.PlayAudio(Framework.Constants.Sound.COMMON_CLAIM);
if (mCharacterBreak.Get((int)mCharacterDataInfo.ID, (int)mCharacterDataInfo.BreakLevel)==null)
2023-08-22 19:08:45 +08:00
{
2023-10-19 15:00:19 +08:00
DebugUtil.LogError("没有配置Id {0} 突破等级 {1}",mCharacterDataInfo.ID, mCharacterDataInfo.BreakLevel);
2023-08-22 19:08:45 +08:00
return;
}
if (targetLevel >= mCharacterBreak.Get((int)mCharacterDataInfo.ID, (int)mCharacterDataInfo.BreakLevel).LevelLimit)
{
2023-12-21 15:59:18 +08:00
CommonUtils.ShowMessageTips(CommonUtils.GetLocalizeText("cultivate_LevelUpMAX"));
2023-10-19 15:00:19 +08:00
return;
}
if (targetLevel + 1 > GetExpEnoughMaxLevel(out uint consumeExp))
{
CommonUtils.ShowMessageTips(CommonUtils.GetLocalizeText("cultivate_expDontFull"));
expLast = (int)consumeExp;
useAllExp = true;
}
else
{
targetLevel++;
CalculateExp();
}
2023-08-22 19:08:45 +08:00
RefreshAfterChangeValue();
RefreshLevelUpBtn();
}
private void OnButton_BackClick()
{
CloseWindow();
}
private void LoadCfg()
{
OnLoadCfg(TableManager.Instance.Tables.CharacterLevelExp);
}
private void OnLoadCfg(CharacterLevelExp characterLevelExp)
{
mCharacterLevelExpCfg = characterLevelExp;
mCharacterBreak = TableManager.Instance.Tables.CharacterBreak;
2023-08-22 19:08:45 +08:00
RefreshUI();
RefreshAfterChangeValue();
}
//invoke when open window
protected override void OnShowWindow(object data = null)
2023-08-22 19:08:45 +08:00
{
2024-06-03 15:57:43 +08:00
base.OnShowWindow(data);
2023-08-22 19:08:45 +08:00
mCharacterDataInfo = data as CharacterDataInfo;
2024-04-28 18:47:34 +08:00
if (mCharacterDataInfo != null)
targetLevel = (int)mCharacterDataInfo.Level;
2023-08-22 19:08:45 +08:00
LoadCfg();
2023-10-19 15:00:19 +08:00
expLast = 0;
useAllExp = false;
2023-10-19 15:00:19 +08:00
2024-04-28 18:47:34 +08:00
dialogue.SetInfo(mCharacterDataInfo.Name);
2023-10-19 15:00:19 +08:00
2024-04-28 18:47:34 +08:00
InputManager.Instance.OnFingersMove += OnFingersHover;
2023-10-19 15:00:19 +08:00
}
private void OnFingersHover(float delta)
{
2023-08-22 19:08:45 +08:00
}
2024-05-08 16:16:50 +08:00
private async void RefreshUI()
2023-08-22 19:08:45 +08:00
{
string imgPath = CommonUtils.GetCharacterPicPath(mCharacterDataInfo.Cfg.RoleID, CommonUtils.ECharacterPicPathType.LevelUp, (int)mCharacterDataInfo.SkinID);
2024-05-08 17:04:37 +08:00
var sprite = await LoadAssetAsync<Sprite>(imgPath);
CommonUtils.RefreshCharacter2DPic(Image_Poster, sprite);
2023-08-22 19:08:45 +08:00
RefresLevelUpBar(mCharacterDataInfo.Level);
RefreshLevelUpBtn();
}
2023-10-19 15:00:19 +08:00
private void RefresLevelUpBar(uint targetRefreshLevel)
2023-08-22 19:08:45 +08:00
{
uint nowLevel = targetRefreshLevel;
2023-08-22 19:08:45 +08:00
int maxLevel = (int)mCharacterBreak.Get((int)mCharacterDataInfo.ID, (int)mCharacterDataInfo.BreakLevel).LevelLimit;
Text_Level_Now.text = nowLevel.ToString();
Text_Level_Max.text ="/" +maxLevel.ToString();
2023-10-19 15:00:19 +08:00
Text_Level_Value.text = targetRefreshLevel.ToString();
2023-08-22 19:08:45 +08:00
float fillAmount;
if (nowLevel >= maxLevel)
{
fillAmount = 1;
}
else
{
fillAmount = mCharacterDataInfo.Exp * 1.0f / (mCharacterLevelExpCfg.Get((int)mCharacterDataInfo.Level + 1).EXP == 0 ? 1 : mCharacterLevelExpCfg.Get((int)mCharacterDataInfo.Level + 1).EXP);
}
//fillAmount= mCharacterDataInfo.Exp/ //nowLevel / (float)maxLevel;
2024-07-25 20:08:53 +08:00
Image_LevelBar.fillAmount = fillAmount;
SetExpBarFillAmount(fillAmount);
2023-08-22 19:08:45 +08:00
Text_Hp_Value.text = mCharacterDataInfo.HP().ToString();
2023-08-22 19:08:45 +08:00
Text_Morale_Value.text = mCharacterDataInfo.Cfg.MaxMorale.ToString();
Text_Defense_Value.text = mCharacterDataInfo.Defence().ToString();
Text_Armor_Value.text= mCharacterDataInfo.Armor().ToString();
Text_Attack_Value.text=mCharacterDataInfo.Attack().ToString();
Text_Speed_Value.text=mCharacterDataInfo.MoveSpeed().ToString();
2023-10-19 15:00:19 +08:00
Text_Exp_Value.text = Actor.Instance.Item.GetItemCount(GLConfig.Inst.data.HeroExpItem).ToString(); ;
2023-08-22 19:08:45 +08:00
}
private void RefreshAfterChangeValue()
{
float changeHp = mCharacterDataInfo.HpLevelUp((int)targetLevel) - mCharacterDataInfo.HpLevelUp((int)mCharacterDataInfo.Level);
2023-08-22 19:08:45 +08:00
float changeMorale = 0;
float changeDefense = mCharacterDataInfo.DefenceLevelUp((int)targetLevel) - mCharacterDataInfo.DefenceLevelUp((int)mCharacterDataInfo.Level);
float changeArmor = mCharacterDataInfo.ArmorLevelUp((int)targetLevel) - mCharacterDataInfo.ArmorLevelUp((int)mCharacterDataInfo.Level);
2023-10-19 15:00:19 +08:00
float changeAttack = mCharacterDataInfo.AttackLevelUp((int)targetLevel) - mCharacterDataInfo.AttackLevelUp((int)mCharacterDataInfo.Level);
float changespeed = 0;
2023-08-22 19:08:45 +08:00
Text_Change_Hp.gameObject.SetActive(changeHp != 0);
Text_Change_Hp.text = "+" + changeHp.ToString();
2023-08-22 19:08:45 +08:00
Text_Change_Morale.gameObject.SetActive(changeMorale != 0);
Text_Change_Morale.text = "+" + changeMorale.ToString();
Text_Change_Defanse.gameObject.SetActive(changeDefense != 0);
Text_Change_Defanse.text = "+" + changeDefense.ToString();
Text_Change_Armor.gameObject.SetActive(changeArmor != 0);
Text_Change_Armor.text = "+" + changeArmor.ToString();
Text_Change_Attack.gameObject.SetActive(changeAttack != 0);
Text_Change_Attack.text = "+" + changeAttack.ToString();
Text_Change_Speed.gameObject.SetActive(changespeed != 0);
Text_Change_Speed.text = "+" + changespeed.ToString();
Text_ExpNeed.gameObject.SetActive(expLast > 0);
Text_ExpNeed.text = expLast.ToString();
Text_Level_Now.text = targetLevel.ToString();
Text_Level_Value.text = targetLevel.ToString();
Text_ExpBefore.text = mCharacterDataInfo.Exp.ToString();
float fillAmount;
if (targetLevel >= mCharacterBreak.Get((int)mCharacterDataInfo.ID, (int)mCharacterDataInfo.BreakLevel).LevelLimit)//= mCharacterLevelExpCfg.GetOrDefault((int)targetLevel).EXP - expLast;
{
//满级进度条
fillAmount = 1;
}
else if (expLast <= 0)
{
//无强化显示持有经验进度条
fillAmount = mCharacterDataInfo.Exp * 1.0f / (mCharacterLevelExpCfg.Get((int)mCharacterDataInfo.Level + 1).EXP == 0 ? 1 : mCharacterLevelExpCfg.Get((int)mCharacterDataInfo.Level + 1).EXP);
}
else
{
if (!useAllExp)
{
fillAmount = 0;
}
else
{
var consumeExp = expLast;
CalculateExp();
useAllExp = true;
var ExpRemainInBar = consumeExp - expLast;
expLast = consumeExp;
fillAmount = ExpRemainInBar / (float)mCharacterLevelExpCfg.GetOrDefault((int)targetLevel + 1).EXP;
}
}
//fillAmount = targetLevel / (float)mCharacterBreak.Get((int)mCharacterDataInfo.ID, (int)mCharacterDataInfo.BreakLevel).LevelLimit;
2024-07-25 20:08:53 +08:00
Image_LevelBar.fillAmount = fillAmount;
SetExpBarFillAmount(fillAmount);
}
/// <summary>
/// 设置经验进度条及小三角位置
/// </summary>
/// <param name="fillAmount"></param>
void SetExpBarFillAmount(float fillAmount)
{
2024-07-25 20:08:53 +08:00
var angle = -360 * fillAmount;
Image_LevelArrow.transform.rotation = UnityEngine.Quaternion.Euler(0, 0, angle);
float posX = Mathf.Sin(angle * Mathf.Deg2Rad) * ArrowRadius;
float posY = -Mathf.Cos(angle * Mathf.Deg2Rad) * ArrowRadius;
Image_LevelArrow.GetComponent<RectTransform>().anchoredPosition = new Vector2(posX, posY);
}
/// <summary>
/// 计算恰好升到目标等级所需经验(刚好升满经验槽的经验量)
/// </summary>
void CalculateExp()
{
useAllExp = false;
expLast = 0;
for (int i = (int)mCharacterDataInfo.Level; i < targetLevel; i++)
{
if (mCharacterLevelExpCfg.GetOrDefault((i + 1)) != null)
{
2023-10-19 15:00:19 +08:00
expLast += mCharacterLevelExpCfg.GetOrDefault((i + 1)).EXP;
}
else
{
DebugUtil.LogError("CharacterLevelExpCfg的等级不够了");
}
}
expLast -= (int)mCharacterDataInfo.Exp;
2023-08-22 19:08:45 +08:00
}
2023-08-22 19:08:45 +08:00
//invoke when reload window
protected override void OnReloadWindow(object data = null)
{
}
2024-04-28 17:27:23 +08:00
protected override void OnUpdate()
{
base.OnUpdate();
2024-04-28 18:47:34 +08:00
dialogue.IsScaleShow = IsDialoguePlaying;
2024-04-28 17:27:23 +08:00
}
//invoke when close window
protected override void OnHideWindow()
2023-08-22 19:08:45 +08:00
{
2023-10-19 15:00:19 +08:00
EventManager.Instance.Send(EventManager.EventName.EN_UIControllCultivateMainInput, true);
2024-04-28 17:27:23 +08:00
AudioManager.Instance.AudioMgrObj.StopAllSounds();
2024-06-03 15:57:43 +08:00
base.OnHideWindow();
2023-08-22 19:08:45 +08:00
}
public override void OnRelease()
{
base.OnRelease();
UnregisterEvent();
}
2023-08-22 19:08:45 +08:00
}