Add player profile system
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
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;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user