iFactory.Cutting.Unity/Assets/BITKit/Unity/Scripts/Entity/Net/EntityNetConfig.cs

33 lines
705 B
C#
Raw Normal View History

2024-03-04 18:45:21 +08:00
using System;
2024-01-23 02:56:26 +08:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace BITKit.Entities
{
public sealed class EntityNetConfig : EntityBehavior
{
[SerializeField] private bool serverOnly;
[SerializeReference,SubclassSelector] private INetClient netClient;
[SerializeReference,SubclassSelector] private INetServer netServer;
2024-03-04 18:45:21 +08:00
[SerializeReference,SubclassSelector] private ITicker ticker;
public override void OnStart()
{
base.OnStart();
ticker?.Add(OnTick);
}
private void OnDestroy()
{
ticker?.Remove(OnTick);
}
private void OnTick(float deltaTime)
2024-01-23 02:56:26 +08:00
{
if (netClient.IsConnected && serverOnly)
{
Destroy(gameObject);
}
}
}
}