Files
BITFALL/Assets/Artists/Scripts/Entity/Player/EntityGDNetPlayer.cs

53 lines
1.6 KiB
C#
Raw Normal View History

2023-06-08 14:09:50 +08:00
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)
{
}
}
}