1
This commit is contained in:
39
Src/Level/LevelComponent.cs
Normal file
39
Src/Level/LevelComponent.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
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);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
11
Src/Level/LevelComponent.cs.meta
Normal file
11
Src/Level/LevelComponent.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4e174908a3e850e4ba7c55460b1179ac
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
16
Src/Level/Net.Project.B.Level.asmdef
Normal file
16
Src/Level/Net.Project.B.Level.asmdef
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"name": "Net.Project.B.Level",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:d8b63aba1907145bea998dd612889d6b"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
7
Src/Level/Net.Project.B.Level.asmdef.meta
Normal file
7
Src/Level/Net.Project.B.Level.asmdef.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 16c1175489fd8a84b846b3dedc7e7836
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user