BITFALL/Assets/BITKit/Unity/Scripts/Entity/Player/UnityPlayerService.cs

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