2023-08-27 02:58:19 +08:00
|
|
|
using System;
|
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
namespace BITKit.Entities.Player
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// Unity玩家服务
|
|
|
|
/// </summary>
|
|
|
|
[Serializable]
|
|
|
|
public class UnityPlayerServiceService : IPlayerService
|
|
|
|
{
|
|
|
|
public static event Action<Entity> OnPlayerInitialized;
|
|
|
|
public static event Action<Entity> OnPlayerDisposed;
|
|
|
|
public static Entity LocalPlayer { get;private set; }
|
2023-10-30 01:25:53 +08:00
|
|
|
public static void Register(Entity unityEntity)
|
2023-08-27 02:58:19 +08:00
|
|
|
{
|
2023-10-30 01:25:53 +08:00
|
|
|
OnPlayerInitialized?.Invoke(unityEntity);
|
|
|
|
LocalPlayer = unityEntity;
|
2023-08-27 02:58:19 +08:00
|
|
|
}
|
2023-10-30 01:25:53 +08:00
|
|
|
public static void UnRegister(Entity unityEntity)
|
2023-08-27 02:58:19 +08:00
|
|
|
{
|
2023-10-30 01:25:53 +08:00
|
|
|
OnPlayerDisposed?.Invoke(unityEntity);
|
2023-08-27 02:58:19 +08:00
|
|
|
LocalPlayer = null;
|
|
|
|
}
|
|
|
|
Entity IPlayerService.LocalPlayer=>LocalPlayer;
|
|
|
|
event Action<Entity> IPlayerService.OnPlayerInitialized
|
|
|
|
{
|
|
|
|
add => OnPlayerInitialized += value;
|
|
|
|
remove => OnPlayerInitialized -= value;
|
|
|
|
}
|
|
|
|
event Action<Entity> IPlayerService.OnPlayerDisposed
|
|
|
|
{
|
|
|
|
add => OnPlayerDisposed += value;
|
|
|
|
remove => OnPlayerDisposed -= value;
|
|
|
|
}
|
2023-10-30 01:25:53 +08:00
|
|
|
void IPlayerService.Register(Entity unityEntity)=>Register(unityEntity);
|
|
|
|
void IPlayerService.UnRegister(Entity unityEntity)=>UnRegister(unityEntity);
|
2023-08-27 02:58:19 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|