Files
AIC-Project/Client/Assets/Script/xmain/Module/Player/PlayerProfileStore.cs
T
2026-07-31 17:39:52 +08:00

44 lines
1.2 KiB
C#

using System;
namespace XGame
{
public static class PlayerProfileStore
{
private static PlayerProfileData current = PlayerProfileData.CreateDefault();
public static event Action<PlayerProfileData> Changed;
public static PlayerProfileData Current => current.Clone();
public static void Replace(PlayerProfileData profile)
{
current = profile == null ? PlayerProfileData.CreateDefault() : profile.Clone();
current.Normalize();
Changed?.Invoke(Current);
}
public static void Update(Action<PlayerProfileData> updater)
{
PlayerProfileData next = Current;
updater?.Invoke(next);
Replace(next);
}
public static void ResetToDefault()
{
Replace(PlayerProfileData.CreateDefault());
}
public static void SetSessionIdentity(string nickname, string uid, int avatarId = 0, PlayerRoleType roleType = PlayerRoleType.Adventurer)
{
Update(profile =>
{
profile.Nickname = nickname;
profile.Uid = uid;
profile.AvatarId = avatarId;
profile.RoleType = roleType;
});
}
}
}