Net.Project.B/Src/Level/LevelComponent.cs

40 lines
1.0 KiB
C#
Raw Normal View History

2025-06-12 16:08:12 +08:00
using System;
using System.Collections;
using System.Collections.Generic;
using Unity.Mathematics;
namespace Net.Project.B.Level
{
public class LevelComponent
{
public int Level { get; private set; }
public int2 Exp { get; set; } = new(0, 1000);
public event Action<int,int> OnExpChanged;
public event Action<int> OnLevelChanged;
public void AddExp(int exp)
{
var current = Exp;
var newExp = Exp + new int2(exp, 0);
// 是否升级x 是当前经验y 是当前等级所需经验)
if (newExp.x >= Exp.y)
{
newExp.x -= Exp.y; // 超出部分保留
newExp.y = (Level/10+1)+Level%10; // 如果你有更高级别的经验需求函数
Exp = newExp;
Level++;
OnLevelChanged?.Invoke(Level);
}
else
{
Exp = newExp;
}
OnExpChanged?.Invoke(current.x, newExp.x);
}
}
}