43 lines
1.1 KiB
C#
43 lines
1.1 KiB
C#
|
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; }
|
||
|
public static void Register(Entity entity)
|
||
|
{
|
||
|
OnPlayerInitialized?.Invoke(entity);
|
||
|
LocalPlayer = entity;
|
||
|
}
|
||
|
public static void UnRegister(Entity entity)
|
||
|
{
|
||
|
OnPlayerDisposed?.Invoke(entity);
|
||
|
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;
|
||
|
}
|
||
|
void IPlayerService.Register(Entity entity)=>Register(entity);
|
||
|
void IPlayerService.UnRegister(Entity entity)=>UnRegister(entity);
|
||
|
}
|
||
|
}
|
||
|
|