57 lines
1.8 KiB
C#
57 lines
1.8 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using BITKit;
|
|
using BITKit.Entities;
|
|
using Net;
|
|
using Net.Component;
|
|
using Net.Client;
|
|
namespace BITFALL.Entites
|
|
{
|
|
public class EntityGDNetPlayer : EntityComponent
|
|
{
|
|
[SerializeField, SerializeReference, SubclassSelector]
|
|
private INetClient netClient;
|
|
[SerializeField, SerializeReference, SubclassSelector]
|
|
private INetProvider netProvider;
|
|
public override void OnStart()
|
|
{
|
|
entity.Id = Guid.NewGuid().GetHashCode();
|
|
netClient.OnConnected+=OnConnected;
|
|
netClient.OnDisconnected += OnDisconnect;
|
|
IEntity.LocalPlayer = entity;
|
|
IEntity.OnSpawnLocalPlayer(entity);
|
|
}
|
|
public override void OnDestroyComponent()
|
|
{
|
|
//DI.Get<ClientManager>().client.stateha(Net.Share.NetworkState.Connected,OnConnected);
|
|
//DI.Get<ClientManager>().client.AddStateHandler(Net.Share.NetworkState.Disconnect,OnDisconnect);
|
|
}
|
|
void OnConnected()
|
|
{
|
|
entity.Set<bool>(nameof(EntityComponent.isLocalPlayer), true);
|
|
foreach (var x in GetComponentsInChildren<IEntityComponent>(true))
|
|
{
|
|
x.OnSpawn();
|
|
}
|
|
entity.Set<bool>(nameof(isSpawned), true);
|
|
}
|
|
void OnDisconnect()
|
|
{
|
|
if (entity.Get<bool>(nameof(isSpawned)))
|
|
{
|
|
entity.Set<bool>(nameof(EntityComponent.isLocalPlayer), true);
|
|
foreach (var x in GetComponentsInChildren<IEntityComponent>(true))
|
|
{
|
|
x.OnDespawn();
|
|
}
|
|
entity.Set<bool>(nameof(isSpawned), false);
|
|
}
|
|
}
|
|
public override void OnFixedUpdate(float deltaTime)
|
|
{
|
|
|
|
}
|
|
}
|
|
} |