53 lines
1.6 KiB
C#
53 lines
1.6 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
|
||
|
{
|
||
|
public override void OnStart()
|
||
|
{
|
||
|
entity.Id = Guid.NewGuid().GetHashCode();
|
||
|
BITNet.OnConnected+=OnConnected;
|
||
|
BITNet.OnDisconnect += 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)
|
||
|
{
|
||
|
|
||
|
}
|
||
|
}
|
||
|
}
|